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

Container for dense matrices. More...

#include <c_dense_matrix.h>

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

Public Member Functions

 cDenseMatrix ()
 Default constructor.
 
 cDenseMatrix (const DataType *A_, const LongIndexType num_rows_, const LongIndexType num_columns_, const FlagType A_is_row_major_, const FlagType A_is_symmetric_)
 Constructor.
 
virtual ~cDenseMatrix ()
 Destructor.
 
virtual FlagType is_identity_matrix () const
 Checks whether the matrix is identity.
 
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
 
const FlagType A_is_row_major
 
- 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 cDenseMatrix< DataType >

Container for dense matrices.

The cDenseMatrix holds a two-dimensional dense matrix, and can perofrom matrix-vector product and transposed matrix-vector product.

See also
cMatrix, cCSRMatrix, cCSCMatrix, cDenseAffineMatrixFunction, cuDenseMatrix

Definition at line 43 of file c_dense_matrix.h.

Constructor & Destructor Documentation

◆ cDenseMatrix() [1/2]

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

Default constructor.

Definition at line 34 of file c_dense_matrix.cpp.

34 :
35
36 // Initializer list
37 A(NULL),
39{
40}
const FlagType A_is_row_major
const DataType * A

◆ cDenseMatrix() [2/2]

template<typename DataType >
cDenseMatrix< DataType >::cDenseMatrix ( const DataType *  A_,
const LongIndexType  num_rows_,
const LongIndexType  num_columns_,
const FlagType  A_is_row_major_,
const FlagType  A_is_symmetric_ 
)

Constructor.

Parameters
[in]A_1D array that represents a 2D dense array with either C (row) major ordering or Fortran (column) major ordering. The major ordering should de defined by A_is_row_major flag.
[in]num_rows_Number of rows of A
[in]num_columns_Number of columns of A
[in]A_is_row_major_Boolean, can be 0 or 1 as follows:
  • If A is row major (C ordering where the last index is contiguous) this value should be 1.
  • If A is column major (Fortran ordering where the first index is contiguous), this value should be set to 0.
[in]A_is_symmetric_Boolean. If A is symmetric, set this value to 1, otherwise 0.

Definition at line 68 of file c_dense_matrix.cpp.

73 :
74
75 // Base class constructors
76 cLinearOperatorBase(num_rows_, num_columns_),
77 cMatrix<DataType>(A_is_symmetric_),
78
79 // Initializer list
80 A(A_),
81 A_is_row_major(A_is_row_major_)
82{
83}
cLinearOperatorBase()
Default constructor.
Base class for constant matrices.
Definition c_matrix.h:45

◆ ~cDenseMatrix()

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

Destructor.

Definition at line 94 of file c_dense_matrix.cpp.

95{
96}

Member Function Documentation

◆ dot()

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

Implements cLinearOperator< DataType >.

Definition at line 252 of file c_dense_matrix.cpp.

255{
257 this->A,
258 vector,
259 this->num_rows,
260 this->num_columns,
261 this->A_is_row_major,
262 this->A_is_symmetric,
263 product);
264}
const LongIndexType num_rows
const LongIndexType num_columns
static void dense_matvec(const DataType *RESTRICT A, const DataType *RESTRICT b, const LongIndexType num_rows, const LongIndexType num_columns, const FlagType A_is_row_major, const FlagType A_is_symmetric, DataType *RESTRICT c)
Computes the matrix vector multiplication where is a dense matrix.
FlagType A_is_symmetric
Definition c_matrix.h:77

References cMatrixOperations< DataType >::dense_matvec().

Here is the call graph for this function:

◆ dot_plus()

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

Implements cMatrix< DataType >.

Definition at line 290 of file c_dense_matrix.cpp.

294{
296 this->A,
297 vector,
298 alpha,
299 this->num_rows,
300 this->num_columns,
301 this->A_is_row_major,
302 this->A_is_symmetric,
303 product);
304}
static void dense_matvec_plus(const DataType *RESTRICT A, const DataType *RESTRICT b, const DataType alpha, const LongIndexType num_rows, const LongIndexType num_columns, const FlagType A_is_row_major, const FlagType A_is_symmetric, DataType *RESTRICT c)
Computes the operation where is a dense matrix.

References cMatrixOperations< DataType >::dense_matvec_plus().

Here is the call graph for this function:

◆ is_identity_matrix()

template<typename DataType >
FlagType cDenseMatrix< 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 113 of file c_dense_matrix.cpp.

114{
115 FlagType matrix_is_identity = 1;
116 DataType matrix_element;
117 const DataType diagonal = 1.0;
118 const DataType off_diagonal = 0.0;
119
120 // Check matrix element-wise
121 if (this->A_is_row_major)
122 {
123 // Row-major matrix
124 LongIndexType column;
125 LongIndexType num_checking_columns;
126
127 #if defined(USE_OPENMP) && (USE_OPENMP == 1)
128 #pragma omp parallel for \
129 schedule(static) \
130 if (!omp_in_parallel()) \
131 default(none) \
132 shared(matrix_is_identity, diagonal, off_diagonal) \
133 private(column, num_checking_columns, matrix_element)
134 #endif
135 for (LongIndexType row=0; row < this->num_rows; ++row)
136 {
137 if (matrix_is_identity)
138 {
139 if (this->A_is_symmetric)
140 {
141 // Check only half of the columns up to diagonal element
142 num_checking_columns = row + 1;
143 }
144 else
145 {
146 num_checking_columns = this->num_columns;
147 }
148
149 for (column=0; column < num_checking_columns; ++column)
150 {
151 // Get an element of the matrix
152 matrix_element = this->A[row * this->num_columns + column];
153
154 // Check the value of element with identity matrix
155 if (((row == column) && \
156 (!c_arithmetics::is_equal(matrix_element,
157 diagonal))) || \
158 ((row != column) && \
159 (!c_arithmetics::is_equal(matrix_element,
160 off_diagonal))))
161 {
162 #if defined(USE_OPENMP) && (USE_OPENMP == 1)
163 #pragma omp atomic write
164 #endif
165 matrix_is_identity = 0;
166
167 break;
168 }
169 }
170 }
171 }
172 }
173 else
174 {
175 // Column-major matrix
176 LongIndexType row;
177 LongIndexType num_checking_rows;
178
179 #if defined(USE_OPENMP) && (USE_OPENMP == 1)
180 #pragma omp parallel for \
181 schedule(static) \
182 if (!omp_in_parallel()) \
183 default(none) \
184 shared(matrix_is_identity, diagonal, off_diagonal) \
185 private(row, num_checking_rows, matrix_element)
186 #endif
187 for (LongIndexType column=0; column < this-> num_columns; ++column)
188 {
189 if (matrix_is_identity)
190 {
191 if (this->A_is_symmetric)
192 {
193 // Check only half of the rows up to diagonal element
194 num_checking_rows = column + 1;
195 }
196 else
197 {
198 num_checking_rows = this->num_rows;
199 }
200
201 for (row=0; row < num_checking_rows; ++row)
202 {
203 // Get an element of the matrix
204 matrix_element = this->A[column * this->num_rows + row];
205
206 // Check the value of element with identity matrix
207 if (((row == column) && \
208 (!c_arithmetics::is_equal(matrix_element,
209 diagonal))) || \
210 ((row != column) && \
211 (!c_arithmetics::is_equal(matrix_element,
212 off_diagonal))))
213 {
214 #if defined(USE_OPENMP) && (USE_OPENMP == 1)
215 #pragma omp atomic write
216 #endif
217 matrix_is_identity = 0;
218
219 break;
220 }
221 }
222 }
223 }
224 }
225
226 return matrix_is_identity;
227}
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 cDenseMatrix< 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
cDenseMatrix::dot_plus, cDenseMatrix::dot cDenseMatrix::transposed_dot_plus

Implements cLinearOperator< DataType >.

Definition at line 329 of file c_dense_matrix.cpp.

332{
334 this->A,
335 vector,
336 this->num_rows,
337 this->num_columns,
338 this->A_is_row_major,
339 this->A_is_symmetric,
340 product);
341}
static void dense_transposed_matvec(const DataType *RESTRICT A, const DataType *RESTRICT b, const LongIndexType num_rows, const LongIndexType num_columns, const FlagType A_is_row_major, const FlagType A_is_symmetric, DataType *RESTRICT c)
Computes matrix vector multiplication where is dense, and is the transpose of the matrix .

References cMatrixOperations< DataType >::dense_transposed_matvec().

Here is the call graph for this function:

◆ transpose_dot_plus()

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

Implements cMatrix< DataType >.

Definition at line 368 of file c_dense_matrix.cpp.

372{
374 this->A,
375 vector,
376 alpha,
377 this->num_rows,
378 this->num_columns,
379 this->A_is_row_major,
380 this->A_is_symmetric,
381 product);
382}
static void dense_transposed_matvec_plus(const DataType *RESTRICT A, const DataType *RESTRICT b, const DataType alpha, const LongIndexType num_rows, const LongIndexType num_columns, const FlagType A_is_row_major, const FlagType A_is_symmetric, DataType *RESTRICT c)
Computes where is dense, and is the transpose of the matrix .

References cMatrixOperations< DataType >::dense_transposed_matvec_plus().

Here is the call graph for this function:

Member Data Documentation

◆ A

template<typename DataType >
const DataType* cDenseMatrix< DataType >::A
protected

Definition at line 82 of file c_dense_matrix.h.

◆ A_is_row_major

template<typename DataType >
const FlagType cDenseMatrix< DataType >::A_is_row_major
protected

Definition at line 83 of file c_dense_matrix.h.


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