imate
C++/CUDA Reference
Loading...
Searching...
No Matches
cCSRMatrix< DataType > Class Template Reference

Container for CSR matrices. More...

#include <c_csr_matrix.h>

Inheritance diagram for cCSRMatrix< DataType >:
Collaboration diagram for cCSRMatrix< DataType >:

Public Member Functions

 cCSRMatrix ()
 Default constructor.
 
 cCSRMatrix (const DataType *A_data_, const LongIndexType *A_indices_, const LongIndexType *A_index_pointer_, const LongIndexType num_rows_, const LongIndexType num_columns_, const FlagType A_is_symmetric)
 Constructor.
 
virtual ~cCSRMatrix ()
 Destructor.
 
virtual FlagType is_identity_matrix () const
 Checks whether the matrix is identity.
 
LongIndexType get_nnz () const
 Returns the number of non-zero elements of the sparse matrix.
 
virtual void dot (const DataType *vector, DataType *product)
 Matrix vector product.
 
virtual void dot_plus (const DataType *vector, const DataType alpha, DataType *product)
 Matrix vector product written in place.
 
virtual void transpose_dot (const DataType *vector, DataType *product)
 Transposed-matrix vector product.
 
virtual void transpose_dot_plus (const DataType *vector, const DataType alpha, DataType *product)
 Transposed-matrix vector product written in place.
 
- Public Member Functions inherited from cMatrix< DataType >
 cMatrix ()
 Default constructor.
 
 cMatrix (const FlagType A_is_symmetric_)
 Constructor.
 
virtual ~cMatrix ()
 Destructor.
 
DataType get_eigenvalue (const DataType *known_parameters, const DataType known_eigenvalue, const DataType *inquiry_parameters) const
 This virtual function is implemented from its pure virtual function of the base class. In this class, this functio has no use and was only implemented so that this class be able to be instantiated (due to the pure virtual function).
 
virtual void set_symmetry (const FlagType symmetric)
 Specify whether the matrix is symmetic or non-symmetric.
 
- Public Member Functions inherited from cLinearOperator< DataType >
 cLinearOperator ()
 Default constructor.
 
virtual ~cLinearOperator ()
 Destructor.
 
void set_parameters (DataType *parameters_)
 Sets the scalar parameter this->parameters. Parameter is initialized to NULL. However, before calling dot or transpose_dot functions, the parameters must be set.
 
- Public Member Functions inherited from cLinearOperatorBase
 cLinearOperatorBase ()
 Default constructor.
 
 cLinearOperatorBase (const LongIndexType num_rows_, const LongIndexType num_columns_)
 Constructor with setting num_rows and num_columns.
 
virtual ~cLinearOperatorBase ()
 Destructor.
 
LongIndexType get_num_rows () const
 Returns the number of rows of the matrix.
 
LongIndexType get_num_columns () const
 Returns the number of columns of the matrix.
 
IndexType get_num_parameters () const
 Returns the number of parameters of the linear operator.
 
FlagType is_eigenvalue_relation_known () const
 Returns a flag that determines whether a relation between the parameters of the operator and its eigenvalue(s) is known.
 

Protected Attributes

const DataType * A_data
 
const LongIndexTypeA_indices
 
const LongIndexTypeA_index_pointer
 
- Protected Attributes inherited from cMatrix< DataType >
FlagType A_is_symmetric
 
- Protected Attributes inherited from cLinearOperator< DataType >
DataType * parameters
 
- Protected Attributes inherited from cLinearOperatorBase
const LongIndexType num_rows
 
const LongIndexType num_columns
 
FlagType eigenvalue_relation_known
 
IndexType num_parameters
 

Detailed Description

template<typename DataType>
class cCSRMatrix< DataType >

Container for CSR matrices.

The cCSRMatrix holds a two-dimensional compressed sparse row matrix, and can perofrom matrix-vector product and transposed matrix-vector product.

See also
cMatrix, cDenseMatrix, cCSCMatrix, cCSRAffineMatrixFunction, cuCSRMatrix

Definition at line 43 of file c_csr_matrix.h.

Constructor & Destructor Documentation

◆ cCSRMatrix() [1/2]

template<typename DataType >
cCSRMatrix< DataType >::cCSRMatrix ( )

Default constructor.

Definition at line 34 of file c_csr_matrix.cpp.

34 :
35 A_data(NULL),
36 A_indices(NULL),
37 A_index_pointer(NULL)
38{
39}
const LongIndexType * A_index_pointer
const DataType * A_data
const LongIndexType * A_indices

◆ cCSRMatrix() [2/2]

template<typename DataType >
cCSRMatrix< DataType >::cCSRMatrix ( const DataType *  A_data_,
const LongIndexType A_indices_,
const LongIndexType A_index_pointer_,
const LongIndexType  num_rows_,
const LongIndexType  num_columns_,
const FlagType  A_is_symmetric_ 
)

Constructor.

Parameters
[in]A_data_1D array of the data content of sparse matrix. The size of the array is the nnz of the matrix.
[in]A_indices_1D array indicating the column of each element in A_data_ . The size of this array is the nnz of the matrix.
[in]A_index_pointer_1D array pointing to the start of new rows in A_indices_ . The size of this array is num_rows+1 . The first element of this array is 0 and the last element of this array is the nnz of the matrix.
[in]num_rows_Number of rows of A
[in]num_columns_Number of columns of A
[in]A_is_symmetric_Boolean. If A is symmetric, set this value to 1, otherwise 0.

Definition at line 68 of file c_csr_matrix.cpp.

74 :
75
76 // Base class constructors
77 cLinearOperatorBase(num_rows_, num_columns_),
78 cMatrix<DataType>(A_is_symmetric_),
79
80 // Initializer list
81 A_data(A_data_),
82 A_indices(A_indices_),
83 A_index_pointer(A_index_pointer_)
84{
85}
cLinearOperatorBase()
Default constructor.
Base class for constant matrices.
Definition c_matrix.h:45

◆ ~cCSRMatrix()

template<typename DataType >
cCSRMatrix< DataType >::~cCSRMatrix ( )
virtual

Destructor.

Definition at line 96 of file c_csr_matrix.cpp.

97{
98}

Member Function Documentation

◆ dot()

template<typename DataType >
void cCSRMatrix< DataType >::dot ( const DataType *  vector,
DataType *  product 
)
virtual

Matrix vector product.

Performs the matrix vector product \( \boldsymbol{y} = \mathbf{A} \boldsymbol{x} \).

Parameters
[in]vectorA one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \).
[out]productA one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \). This vector will be overwritten.
See also
cCSRMatrix::dot_plus, cCSRMatrix::transposed_dot cCSRMatrix::transposed_dot_plus

Implements cLinearOperator< DataType >.

Definition at line 211 of file c_csr_matrix.cpp.

214{
216 this->A_data,
217 this->A_indices,
218 this->A_index_pointer,
219 vector,
220 this->num_rows,
221 product);
222}
const LongIndexType num_rows
static void csr_matvec(const DataType *RESTRICT A_data, const LongIndexType *RESTRICT A_column_indices, const LongIndexType *RESTRICT A_index_pointer, const DataType *RESTRICT b, const LongIndexType num_rows, DataType *RESTRICT c)
Computes where is compressed sparse row (CSR) matrix and is a dense vector. The output is a dense...

References cMatrixOperations< DataType >::csr_matvec().

Here is the call graph for this function:

◆ dot_plus()

template<typename DataType >
void cCSRMatrix< DataType >::dot_plus ( const DataType *  vector,
const DataType  alpha,
DataType *  product 
)
virtual

Matrix vector product written in place.

Performs the matrix vector product \( \boldsymbol{y} = \boldsymbol{y} + \alpha \mathbf{A} \boldsymbol{x} \).

Parameters
[in]vectorA one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \).
[in]alphaA scalar.
[out]productA one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \).
See also
cCSRMatrix::dot, cCSRMatrix::transposed_dot cCSRMatrix::transposed_dot_plus

Implements cMatrix< DataType >.

Definition at line 248 of file c_csr_matrix.cpp.

252{
254 this->A_data,
255 this->A_indices,
256 this->A_index_pointer,
257 vector,
258 alpha,
259 this->num_rows,
260 product);
261}
static void csr_matvec_plus(const DataType *RESTRICT A_data, const LongIndexType *RESTRICT A_column_indices, const LongIndexType *RESTRICT A_index_pointer, const DataType *RESTRICT b, const DataType alpha, const LongIndexType num_rows, DataType *RESTRICT c)
Computes where is compressed sparse row (CSR) matrix and is a dense vector. The output is a dense...

References cMatrixOperations< DataType >::csr_matvec_plus().

Here is the call graph for this function:

◆ get_nnz()

template<typename DataType >
LongIndexType cCSRMatrix< DataType >::get_nnz ( ) const

Returns the number of non-zero elements of the sparse matrix.

The nnz of a CSR matrix can be obtained from the last element of A_index_pointer. The size of array A_index_pointer is one plus the number of rows of the matrix.

Returns
The nnz of the matrix.

Definition at line 183 of file c_csr_matrix.cpp.

184{
185 return this->A_index_pointer[this->num_rows];
186}

◆ is_identity_matrix()

template<typename DataType >
FlagType cCSRMatrix< DataType >::is_identity_matrix ( ) const
virtual

Checks whether the matrix is identity.

The identity check is primarily performed in the cAffineMatrixFunction class.

Returns
Returns 1 if the input matrix is identity, and 0 otherwise.
See also
cAffineMatrixFunction

Implements cMatrix< DataType >.

Definition at line 115 of file c_csr_matrix.cpp.

116{
117 FlagType matrix_is_identity = 1;
118 LongIndexType index_pointer;
119 LongIndexType column;
120 DataType matrix_element;
121 const DataType diagonal = 1.0;
122 const DataType off_diagonal = 0.0;
123
124 // Check matrix element-wise
125 #if defined(USE_OPENMP) && (USE_OPENMP == 1)
126 #pragma omp parallel for \
127 schedule(static) \
128 if (!omp_in_parallel()) \
129 default(none) \
130 shared(matrix_is_identity, diagonal, off_diagonal) \
131 private(index_pointer, column, matrix_element)
132 #endif
133 for (LongIndexType row=0; row < this->num_rows; ++row)
134 {
135 if (matrix_is_identity)
136 {
137 for (index_pointer=this->A_index_pointer[row];
138 index_pointer < this->A_index_pointer[row+1];
139 ++index_pointer)
140 {
141 column = this->A_indices[index_pointer];
142
143 if (!((this->A_is_symmetric) && (column >= row)))
144 {
145 matrix_element = this->A_data[index_pointer];
146
147 if (((row == column) && \
148 (!c_arithmetics::is_equal(matrix_element,
149 diagonal))) || \
150 ((row != column) && \
151 (!c_arithmetics::is_equal(matrix_element,
152 off_diagonal))))
153 {
154 #if defined(USE_OPENMP) && (USE_OPENMP == 1)
155 #pragma omp atomic write
156 #endif
157 matrix_is_identity = 0;
158
159 break;
160 }
161 }
162 }
163 }
164 }
165
166 return matrix_is_identity;
167}
FlagType A_is_symmetric
Definition c_matrix.h:77
bool is_equal(DataType x, DataType y)
Check if two floating point numbers are equal within a tolerance.
Definition _c_is_equal.h:49
int LongIndexType
Definition types.h:60
int FlagType
Definition types.h:68

References c_arithmetics::is_equal().

Here is the call graph for this function:

◆ transpose_dot()

template<typename DataType >
void cCSRMatrix< DataType >::transpose_dot ( const DataType *  vector,
DataType *  product 
)
virtual

Transposed-matrix vector product.

Performs the matrix vector product \( \boldsymbol{y} = \mathbf{A}^{\intercal} \boldsymbol{x} \).

Parameters
[in]vectorA one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \).
[out]productA one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \). This vector will be overwritten.
See also
cCSRMatrix::dot_plus, cCSRMatrix::dot cCSRMatrix::transposed_dot_plus

Implements cLinearOperator< DataType >.

Definition at line 286 of file c_csr_matrix.cpp.

289{
291 this->A_data,
292 this->A_indices,
293 this->A_index_pointer,
294 this->A_is_symmetric,
295 vector,
296 this->num_rows,
297 this->num_columns,
298 product);
299}
const LongIndexType num_columns
static void csr_transposed_matvec(const DataType *RESTRICT A_data, const LongIndexType *RESTRICT A_column_indices, const LongIndexType *RESTRICT A_index_pointer, const FlagType A_is_symmetric, const DataType *RESTRICT b, const LongIndexType num_rows, const LongIndexType num_columns, DataType *RESTRICT c)
Computes where is compressed sparse row (CSR) matrix and is a dense vector. The output is a dense...

References cMatrixOperations< DataType >::csr_transposed_matvec().

Here is the call graph for this function:

◆ transpose_dot_plus()

template<typename DataType >
void cCSRMatrix< DataType >::transpose_dot_plus ( const DataType *  vector,
const DataType  alpha,
DataType *  product 
)
virtual

Transposed-matrix vector product written in place.

Performs the matrix vector product \( \boldsymbol{y} = \boldsymbol{y} + \alpha \mathbf{A}^{\intercal} \boldsymbol{x} \).

Parameters
[in]vectorA one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \).
[in]alphaA scalar.
[out]productA one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \).
See also
cCSRMatrix::dot_plus, cCSRMatrix::transposed_dot cCSRMatrix::dot

Implements cMatrix< DataType >.

Definition at line 326 of file c_csr_matrix.cpp.

330{
332 this->A_data,
333 this->A_indices,
334 this->A_index_pointer,
335 this->A_is_symmetric,
336 vector,
337 alpha,
338 this->num_rows,
339 product);
340}
static void csr_transposed_matvec_plus(const DataType *RESTRICT A_data, const LongIndexType *RESTRICT A_column_indices, const LongIndexType *RESTRICT A_index_pointer, const FlagType A_is_symmetric, const DataType *RESTRICT b, const DataType alpha, const LongIndexType num_rows, DataType *RESTRICT c)
Computes where is compressed sparse row (CSR) matrix and is a dense vector. The output is a dense...

References cMatrixOperations< DataType >::csr_transposed_matvec_plus().

Here is the call graph for this function:

Member Data Documentation

◆ A_data

template<typename DataType >
const DataType* cCSRMatrix< DataType >::A_data
protected

Definition at line 85 of file c_csr_matrix.h.

◆ A_index_pointer

template<typename DataType >
const LongIndexType* cCSRMatrix< DataType >::A_index_pointer
protected

Definition at line 87 of file c_csr_matrix.h.

◆ A_indices

template<typename DataType >
const LongIndexType* cCSRMatrix< DataType >::A_indices
protected

Definition at line 86 of file c_csr_matrix.h.


The documentation for this class was generated from the following files: