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

Container for CSC matrices. More...

#include <c_csc_matrix.h>

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

Public Member Functions

 cCSCMatrix ()
 Default constructor.
 
 cCSCMatrix (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 ~cCSCMatrix ()
 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 cCSCMatrix< DataType >

Container for CSC matrices.

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

See also
cMatrix, cDenseMatrix, cCSRMatrix, cCSCAffineMatrixFunction, cuCSCMatrix

Definition at line 43 of file c_csc_matrix.h.

Constructor & Destructor Documentation

◆ cCSCMatrix() [1/2]

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

Default constructor.

Definition at line 34 of file c_csc_matrix.cpp.

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

◆ cCSCMatrix() [2/2]

template<typename DataType >
cCSCMatrix< DataType >::cCSCMatrix ( 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 row 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_csc_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

◆ ~cCSCMatrix()

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

Destructor.

Definition at line 96 of file c_csc_matrix.cpp.

97{
98}

Member Function Documentation

◆ dot()

template<typename DataType >
void cCSCMatrix< 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
cCSCMatrix::dot_plus, cCSCMatrix::transposed_dot cCSCMatrix::transposed_dot_plus

Implements cLinearOperator< DataType >.

Definition at line 211 of file c_csc_matrix.cpp.

214{
216 this->A_data,
217 this->A_indices,
218 this->A_index_pointer,
219 this->A_is_symmetric,
220 vector,
221 this->num_rows,
222 this->num_columns,
223 product);
224}
const LongIndexType num_rows
const LongIndexType num_columns
static void csc_matvec(const DataType *RESTRICT A_data, const LongIndexType *RESTRICT A_row_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 column (CSC) matrix and is a dense vector. The output is a de...
FlagType A_is_symmetric
Definition c_matrix.h:77

References cMatrixOperations< DataType >::csc_matvec().

Here is the call graph for this function:

◆ dot_plus()

template<typename DataType >
void cCSCMatrix< 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
cCSCMatrix::dot, cCSCMatrix::transposed_dot cCSCMatrix::transposed_dot_plus

Implements cMatrix< DataType >.

Definition at line 250 of file c_csc_matrix.cpp.

254{
256 this->A_data,
257 this->A_indices,
258 this->A_index_pointer,
259 this->A_is_symmetric,
260 vector,
261 alpha,
262 this->num_columns,
263 product);
264}
static void csc_matvec_plus(const DataType *RESTRICT A_data, const LongIndexType *RESTRICT A_row_indices, const LongIndexType *RESTRICT A_index_pointer, const FlagType A_is_symmetric, const DataType *RESTRICT b, const DataType alpha, const LongIndexType num_columns, DataType *RESTRICT c)
Computes where is compressed sparse column (CSC) matrix and is a dense vector. The output is a de...

References cMatrixOperations< DataType >::csc_matvec_plus().

Here is the call graph for this function:

◆ get_nnz()

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

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

The nnz of a CSC 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 columns of the matrix.

Returns
The nnz of the matrix.

Definition at line 183 of file c_csc_matrix.cpp.

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

◆ is_identity_matrix()

template<typename DataType >
FlagType cCSCMatrix< 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_csc_matrix.cpp.

116{
117 FlagType matrix_is_identity = 1;
118 LongIndexType index_pointer;
119 LongIndexType row;
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, row, matrix_element)
132 #endif
133 for (LongIndexType column=0; column < this->num_columns; ++column)
134 {
135 if (matrix_is_identity)
136 {
137 for (index_pointer=this->A_index_pointer[column];
138 index_pointer < this->A_index_pointer[column+1];
139 ++index_pointer)
140 {
141 row = 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}
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 cCSCMatrix< 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
cCSCMatrix::dot_plus, cCSCMatrix::dot cCSCMatrix::transposed_dot_plus

Implements cLinearOperator< DataType >.

Definition at line 289 of file c_csc_matrix.cpp.

292{
294 this->A_data,
295 this->A_indices,
296 this->A_index_pointer,
297 vector,
298 this->num_columns,
299 product);
300}
static void csc_transposed_matvec(const DataType *RESTRICT A_data, const LongIndexType *RESTRICT A_row_indices, const LongIndexType *RESTRICT A_index_pointer, const DataType *RESTRICT b, const LongIndexType num_columns, DataType *RESTRICT c)
Computes where is compressed sparse column (CSC) matrix and is a dense vector. The output is a de...

References cMatrixOperations< DataType >::csc_transposed_matvec().

Here is the call graph for this function:

◆ transpose_dot_plus()

template<typename DataType >
void cCSCMatrix< 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
cCSCMatrix::dot_plus, cCSCMatrix::transposed_dot cCSCMatrix::dot

Implements cMatrix< DataType >.

Definition at line 327 of file c_csc_matrix.cpp.

331{
333 this->A_data,
334 this->A_indices,
335 this->A_index_pointer,
336 vector,
337 alpha,
338 this->num_columns,
339 product);
340}
static void csc_transposed_matvec_plus(const DataType *RESTRICT A_data, const LongIndexType *RESTRICT A_row_indices, const LongIndexType *RESTRICT A_index_pointer, const DataType *RESTRICT b, const DataType alpha, const LongIndexType num_columns, DataType *RESTRICT c)
Computes where is compressed sparse column (CSC) matrix and is a dense vector. The output is a de...

References cMatrixOperations< DataType >::csc_transposed_matvec_plus().

Here is the call graph for this function:

Member Data Documentation

◆ A_data

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

Definition at line 85 of file c_csc_matrix.h.

◆ A_index_pointer

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

Definition at line 87 of file c_csc_matrix.h.

◆ A_indices

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

Definition at line 86 of file c_csc_matrix.h.


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