Host Matrices
Host Matrix (CRS)
-
template<typename
NumType>
classHostMatrix: public BaseMatrix<NumType> Implementation of a Matrix class on the host system.
- Template Parameters
NumType: Number type (double and float currently supported). This class uses the Compressed Row Storage (CRS) format.
Public Functions
-
HostMatrix() Default constructor.
-
virtual
~HostMatrix() Destructor.
-
virtual void
allocate(int m, int n, int nnz) Allocate a matrix of size
mxnwithnnznon-zero entries.- Parameters
m: The number of rows.n: The number of columns.nnz: The number of non-zero entries.
-
virtual void
clear() Clear matrix.
-
virtual void
copy_from(const NumType *val, const int *row_ptr, const int *col_idx) Copy data to the matrix.
- Note
- allocate should be called first.
- Parameters
val: The pointer to the values to copy.row_ptr: The pointer to the indices of val starting a new row.col_idx: The pointer to the column indices of the elements in val.
-
virtual void
copy_from(const BaseMatrix<NumType> &B) A=B, whereAis the matrix itself.- Parameters
B: The matrix to copy.
-
virtual void
copy_to(BaseMatrix<NumType> &B) const B=A, whereAis the matrix itself.- Parameters
B: The matrix to copy to.
-
virtual NumType
norm() const - Return
- The Frobenius norm of the matrix.
-
virtual void
scale(NumType alpha) A=alpha*A, whereAis the matrix itself.- Parameters
alpha: The value by which to scale the entries in the matrix.
-
virtual void
multiply(const BaseVector<NumType> &v_in, BaseVector<NumType> *w_out) const w_out=A*v_in, whereAis the matrix itself.- Parameters
v_in: The vector right-multiplying the vector.w_out: The outputted vector.
-
virtual void
lower_solve(const BaseVector<NumType> &b, BaseVector<NumType> *x) const Solvers for
xin (L+D) *x=b, whereLandDare respectively the lower triangular and diagonal parts of the matrix itself. \param[in] b The vector in the above equation \param[out] x The vector in the above equation
-
virtual void
upper_solve(const BaseVector<NumType> &b, BaseVector<NumType> *x) const Solvers for
xin (U+D) *x=b, whereUandDare respectively the upper triangular and diagonal parts of the matrix itself. \param[in] b The vector in the above equation \param[out] x The vector in the above equation
-
virtual void
get_diagonals(BaseVector<NumType> *diag) const Outputs the diagonal entries of the matrix.
- Parameters
w_out: The outputted vector storing the diagonal entries.
-
virtual void
compute_inverse_diagonals(BaseVector<NumType> *inv_diag) const Compute the inverse of the diagonal entries of the matrix.
- Parameters
w_out: The outputted vector storing the inverse of the diagonal entries.
-
bool
read_matrix_market(const std::string filename) Read a matrix market.
- Return
- True if successfully read, and False otherwise.
- Parameters
filename: The matrix market file.
Host Matrix (COO)
-
template<typename
NumType>
classHostMatrixCOO: public BaseMatrix<NumType> Implementation of a Matrix class on the host system.
- Template Parameters
NumType: Number type (double and float currently supported). This class uses the Coordinate list (COO) format.
Public Functions
-
HostMatrixCOO() Default constructor.
-
~HostMatrixCOO() Destructor.
-
void
allocate(int m, int n, int nnz) Allocate a matrix of size
mxnwithnnznon-zero entries.- Parameters
m: The number of rows.n: The number of columns.nnz: The number of non-zero entries.
-
void
clear() Clear matrix.
-
void
copy_from(const BaseMatrix<NumType> &B) A=B, whereAis the matrix itself.- Parameters
B: The matrix to copy.
-
void
copy_to(BaseMatrix<NumType> &B) const B=A, whereAis the matrix itself.- Parameters
B: The matrix to copy to.
-
NumType
norm() const - Return
- The Frobenius norm of the matrix.
-
void
scale(NumType alpha) A=alpha*A, whereAis the matrix itself.- Parameters
alpha: The value by which to scale the entries in the matrix.
-
void
multiply(const BaseVector<NumType> &v_in, BaseVector<NumType> *w_out) const w_out=A*v_in, whereAis the matrix itself.- Parameters
v_in: The vector right-multiplying the vector.w_out: The outputted vector.
-
void
lower_solve(const BaseVector<NumType> &b, BaseVector<NumType> *x) const Solvers for
xin (L+D) *x=b, whereLandDare respectively the lower triangular and diagonal parts of the matrix itself. \param[in] b The vector in the above equation \param[out] x The vector in the above equation
-
void
upper_solve(const BaseVector<NumType> &b, BaseVector<NumType> *x) const Solvers for
xin (U+D) *x=b, whereUandDare respectively the upper triangular and diagonal parts of the matrix itself. \param[in] b The vector in the above equation \param[out] x The vector in the above equation
-
void
get_diagonals(BaseVector<NumType> *diag) const Outputs the diagonal entries of the matrix.
- Parameters
w_out: The outputted vector storing the diagonal entries.
-
void
compute_inverse_diagonals(BaseVector<NumType> *inv_diag) const Compute the inverse of the diagonal entries of the matrix.
- Parameters
w_out: The outputted vector storing the inverse of the diagonal entries.
-
bool
read_matrix_market(const std::string filename) Read a matrix market.
- Return
- True if successfully read, and False otherwise.
- Parameters
filename: The matrix market file.
-
void
convert_to_CSR(HostMatrix<NumType> &mat_csr) const Convert the COO matrix to a CSR matrix.
- Parameters
mat_CSR: The CSR matrix.