16 #define MM_BANNER "%%MatrixMarket"
17 #define MM_MAT "matrix"
18 #define MM_VEC "vector"
19 #define MM_FMT "coordinate"
20 #define MM_TYPE_REAL "real"
21 #define MM_TYPE_GENERAL "general"
22 #define MM_TYPE_SYMM "symmetric"
25 template <
typename Float>
class vector;
26 template <
typename TYPE,
typename Float>
class view1D;
28 template <
typename Float>
class Dense;
29 template <
typename Float>
class CRS;
43 template <
typename Float>
class COO {
82 std::vector<Float>
val;
97 COO(
const size_t M,
const size_t N)
116 COO(
const size_t M,
const size_t N,
const size_t NNZ,
const int *
row,
117 const int *
col,
const Float *value);
134 COO(
const size_t M,
const size_t N,
const size_t NNZ,
135 const std::vector<int> &
row,
const std::vector<int> &
col,
136 const std::vector<Float> &value) {
137 this =
COO(M, N, NNZ,
row.data(),
col.data(), value.data());
157 COO(
const size_t M,
const size_t N,
const size_t NNZ,
158 const std::vector<int> &
row,
const std::vector<int> &
col,
181 COO(
const size_t M,
const size_t N,
const size_t NNZ,
const int *
row,
182 const int *
col,
const Float *value,
const size_t origin);
201 COO(
const size_t M,
const size_t N,
const size_t NNZ,
202 const std::vector<int> &
row,
const std::vector<int> &
col,
203 const std::vector<Float> &value,
const size_t origin) {
204 this =
COO(M, N, NNZ,
row.data(),
col.data(), value.data(), origin);
312 throw std::runtime_error(
"error, GPU util of COO format is not impl. ");
321 throw std::runtime_error(
"error, GPU util of COO format is not impl. ");
410 [[nodiscard]] Float
at(
const size_t i,
const size_t j)
const;
419 [[nodiscard]] Float
at(
const size_t i,
const size_t j) {
420 return static_cast<const COO *
>(
this)->
at(i, j);
435 void set_ptr(
const size_t rN,
const size_t cN,
const std::vector<int> &r,
436 const std::vector<int> &c,
const std::vector<Float> &v);
570 return 3 *
get_nnz() *
sizeof(Float) / 1.0e+9;
580 [[nodiscard]] std::string
type()
const {
return "COO"; }
645 bool compare_cpu_and_device =
false)
const;
684 void insert(
const size_t m,
const size_t n,
const Float
val);
Coodinate (COO) format Matrix (need to sort)
void diag(view1D< vector< Float >, Float > &vec) const
bool operator!=(const COO< Float > &mat) const
Comparing matrices (A != mat)
void print_all(bool force_cpu=false) const
print all elements to standard I/O
void recv() const
recv data from GPU
size_t nnz
# of non-zero element
Float at(const size_t i, const size_t j) const
Get matrix element (A(i,j))
void convert(const matrix::LinearOperator< Float > &linearoperator)
COO(const size_t M, const size_t N, const size_t NNZ, const int *row, const int *col, const Float *value)
Create COO matrix from array.
bool equal(const COO< Float > &mat, bool compare_cpu_and_device=false) const
Comparing matrices (A == mat)
void operator=(const COO< Float > &mat)
matrix copy
void transpose(const COO &B)
create transposed matrix from COO matrix (B = A^T)
void fill(Float value)
fill matrix elements with a scalar value
COO(const std::string filename)
Create COO matrix from MatrixMarket format file (only real general) (MatrixMarket format: https://mat...
void col(const size_t c, view1D< vector< Float >, Float > &vec) const
void transpose()
get transposed matrix (A^T)
COO(const matrix::CRS< Float > &crs)
Create COO matrix from CRS matrix.
COO(const matrix::COO< Float > &coo)
Create COO matrix from COO matrix.
std::vector< int > row_index
Coodinate format row index, which stores row numbers of the non-zero elements (size nnz)
void diag(vector< Float > &vec) const
get diag. vector
void print_all(const std::string filename) const
print all elements to file
COO(const matrix::Dense< Float > &dense)
Create COO matrix from Dense matrix (drop zero)
bool operator==(const COO< Float > &mat) const
Comparing matrices (A == mat)
void set_col(const size_t N)
Set col number.
void col(const size_t c, vector< Float > &vec) const
get column vector
void sort(bool merge)
sort COO matrix elements (and merge elements)
COO(const matrix::COO< Float > &coo, Float value)
Initialize COO matrix of the same size as input matrix.
COO(const size_t M, const size_t N, const size_t NNZ, const std::vector< int > &row, const std::vector< int > &col, const vector< Float > &value)
Create COO matrix from monolish::vector.
std::vector< int > & get_col_ind()
get column index
void col(const size_t c, view1D< matrix::Dense< Float >, Float > &vec) const
COO(const size_t M, const size_t N)
Initialize M x N COO matrix.
void _q_sort(int lo, int hi)
void set_ptr(const size_t rN, const size_t cN, const std::vector< int > &r, const std::vector< int > &c, const std::vector< Float > &v)
Set COO array from std::vector.
const std::vector< int > & get_col_ind() const
get column index
COO(const size_t M, const size_t N, const size_t NNZ, const std::vector< int > &row, const std::vector< int > &col, const std::vector< Float > &value)
Create COO matrix from std::vector.
void set_nnz(const size_t NNZ)
Set # of non-zero elements.
std::string type() const
get format name "COO"
void insert(const size_t m, const size_t n, const Float val)
insert element to (m, n)
std::vector< int > & get_row_ptr()
get row index
Float at(const size_t i, const size_t j)
Get matrix element (A(i,j))
void device_free() const
free data on GPU
const std::vector< Float > & get_val_ptr() const
get value
void input_mm(const std::string filename)
Create COO matrix from MatrixMarket format file (only real general) (MatrixMarket format: https://mat...
COO(const matrix::LinearOperator< Float > &linearoperator)
const std::vector< int > & get_row_ptr() const
get row index
bool gpu_status
true: sended, false: not send
bool get_device_mem_stat() const
false; // true: sended, false: not send
void row(const size_t r, view1D< vector< Float >, Float > &vec) const
size_t get_nnz() const
get # of non-zeros
std::vector< Float > val
Coodinate format value array, which stores values of the non-zero elements (size nnz)
void send() const
send data to GPU
void convert(const matrix::Dense< Float > &dense)
Create COO matrix from Dense matrix (drop zero)
COO(const size_t M, const size_t N, const size_t NNZ, const std::vector< int > &row, const std::vector< int > &col, const std::vector< Float > &value, const size_t origin)
Create COO matrix from n-origin array.
size_t get_col() const
get # of col
std::vector< Float > & get_val_ptr()
get value
void diag(view1D< matrix::Dense< Float >, Float > &vec) const
std::vector< int > col_index
Coodinate format column index, which stores column numbers of the non-zero elements (size nnz)
size_t get_row() const
get # of row
void row(const size_t r, view1D< matrix::Dense< Float >, Float > &vec) const
void row(const size_t r, vector< Float > &vec) const
get row vector
void output_mm(const std::string filename) const
output matrix elements in MatrixMarket format (MatrixMarket format: https://math.nist....
COO(const size_t M, const size_t N, const size_t NNZ, const int *row, const int *col, const Float *value, const size_t origin)
Create COO matrix from n-origin array.
double get_data_size() const
Memory data space required by the matrix.
void convert(const matrix::CRS< Float > &crs)
Create COO matrix from CRS matrix.
void set_row(const size_t M)
Set row number.
Compressed Row Storage (CRS) format Matrix.
Linear Operator imitating Matrix.
const Float * data() const
returns a direct pointer to the vector
bool get_device_mem_stat() const
true: sended, false: not send