17 template <
typename Float>
class vector;
18 template <
typename TYPE,
typename Float>
class view1D;
20 template <
typename Float>
class Dense;
21 template <
typename Float>
class COO;
34 template <
typename Float>
class CRS {
66 std::vector<Float>
val;
92 CRS(
const size_t M,
const size_t N,
const size_t NNZ);
109 CRS(
const size_t M,
const size_t N,
const size_t NNZ,
const int *rowptr,
110 const int *colind,
const Float *value);
129 CRS(
const size_t M,
const size_t N,
const size_t NNZ,
const int *rowptr,
130 const int *colind,
const Float *value,
const size_t origin);
146 CRS(
const size_t M,
const size_t N,
const std::vector<int> &rowptr,
147 const std::vector<int> &colind,
const std::vector<Float> &value);
163 CRS(
const size_t M,
const size_t N,
const std::vector<int> &rowptr,
237 void set_ptr(
const size_t M,
const size_t N,
const std::vector<int> &rowptr,
238 const std::vector<int> &colind,
const std::vector<Float> &value);
284 [[nodiscard]] std::string
type()
const {
return "CRS"; }
549 return (
get_nnz() *
sizeof(Float) + (
get_row() + 1) *
sizeof(
int) +
587 bool compare_cpu_and_device =
false)
const;
Coodinate (COO) format Matrix (need to sort)
Compressed Row Storage (CRS) format Matrix.
bool gpu_status
true: sended, false: not send
bool equal(const CRS< Float > &mat, bool compare_cpu_and_device=false) const
Comparing matrices (A == mat)
CRS(const CRS< Float > &mat)
Create CRS matrix from CRS matrix.
void diag_mul(const Float alpha)
Scalar and diag. vector of CRS format matrix mul.
size_t get_col() const
get # of col
CRS(const size_t M, const size_t N, const size_t NNZ)
declare CRS matrix
void diag(vector< Float > &vec) const
get diag. vector
void diag_mul(const view1D< matrix::Dense< Float >, Float > &vec)
CRS(const size_t M, const size_t N, const size_t NNZ, const int *rowptr, const int *colind, const Float *value, const size_t origin)
Create CRS matrix from array, also compute the hash.
CRS(COO< Float > &coo)
Create CRS matrix from COO matrix, also compute the hash.
void diag_mul(const vector< Float > &vec)
Vector and diag. vector of CRS format matrix mul.
double get_data_size() const
void diag_sub(const Float alpha)
Scalar and diag. vector of CRS format matrix sub.
void compute_hash()
compute index array hash (to compare structure)
void diag_sub(const view1D< vector< Float >, Float > &vec)
CRS(const size_t M, const size_t N, const size_t NNZ, const int *rowptr, const int *colind, const Float *value)
Create CRS matrix from array, also compute the hash.
void row(const size_t r, view1D< matrix::Dense< Float >, Float > &vec) const
bool operator!=(const CRS< Float > &mat) const
Comparing matrices (A != mat)
void diag_add(const view1D< vector< Float >, Float > &vec)
void fill(Float value)
fill matrix elements with a scalar value
size_t get_hash() const
get index array hash (to compare structure)
void diag_add(const view1D< matrix::Dense< Float >, Float > &vec)
bool operator==(const CRS< Float > &mat) const
Comparing matrices (A == mat)
void send() const
send data to GPU
void convert(CRS< Float > &crs)
Convert CRS matrix from COO matrix.
void print_all(bool force_cpu=false) const
print all elements to standard I/O
void col(const size_t c, vector< Float > &vec) const
get column vector
void diag_sub(const vector< Float > &vec)
Vector and diag. vector of CRS format matrix sub.
void operator=(const CRS< Float > &mat)
matrix copy
void transpose(const CRS &B)
create transposed matrix from CRS format matrix (B = A^T)
CRS(const CRS< Float > &mat, Float value)
Create CRS matrix of the same size as input matrix.
std::vector< Float > val
CRS format value, which stores values of the non-zero elements (size nnz)
size_t get_nnz() const
get # of non-zeros
size_t structure_hash
hash, created from row_ptr and col_ind
void col(const size_t c, view1D< vector< Float >, Float > &vec) const
void diag(view1D< vector< Float >, Float > &vec) const
void diag(view1D< matrix::Dense< Float >, Float > &vec) const
size_t get_row() const
get # of row
std::vector< int > col_ind
CRS format column index, which stores column numbers of the non-zero elements (size nnz)
~CRS()
destructor of CRS matrix, free GPU memory
std::string type() const
get format name "CRS"
void nonfree_recv()
recv. data to GPU (w/o free)
void convert(COO< Float > &coo)
Convert CRS matrix from COO matrix, also compute the hash.
void diag_add(const Float alpha)
Scalar and diag. vector of CRS format matrix add.
void transpose()
get transposed matrix (A^T)
void device_free() const
free data on GPU
void row(const size_t r, view1D< vector< Float >, Float > &vec) const
void diag_add(const vector< Float > &vec)
Vector and diag. vector of CRS format matrix add.
void diag_div(const view1D< matrix::Dense< Float >, Float > &vec)
void diag_div(const Float alpha)
Scalar and diag. vector of CRS format matrix div.
void diag_mul(const view1D< vector< Float >, Float > &vec)
void recv()
recv. data to GPU, and free data on GPU
size_t nnz
# of non-zero element
void row(const size_t r, vector< Float > &vec) const
get row vector
void diag_div(const vector< Float > &vec)
Vector and diag. vector of CRS format matrix div.
void set_ptr(const size_t M, const size_t N, const std::vector< int > &rowptr, const std::vector< int > &colind, const std::vector< Float > &value)
Set CRS array from std::vector.
void col(const size_t c, view1D< matrix::Dense< Float >, Float > &vec) const
std::vector< int > row_ptr
CRS format row pointer, which stores the starting points of the rows of the arrays value and col_ind ...
CRS(const size_t M, const size_t N, const std::vector< int > &rowptr, const std::vector< int > &colind, const std::vector< Float > &value)
Create CRS matrix from std::vector, also compute the hash.
bool get_device_mem_stat() const
true: sended, false: not send
void diag_sub(const view1D< matrix::Dense< Float >, Float > &vec)
CRS(const size_t M, const size_t N, const std::vector< int > &rowptr, const std::vector< int > &colind, const vector< Float > &value)
Create CRS matrix from std::vector, also compute the hash.
void diag_div(const view1D< vector< Float >, Float > &vec)