MoCSI API Reference
Loading...
Searching...
No Matches
Public Member Functions | List of all members
DenseMatrix< T > Class Template Reference

Concrete implemenatation of a matrix class representing a dense matrix. Offers basic access and element wise arithmetic functionality and mathematical matrix product. More...

#include <DenseMatrix.h>

Inheritance diagram for DenseMatrix< T >:
Inheritance graph
Collaboration diagram for DenseMatrix< T >:
Collaboration graph

Public Member Functions

 DenseMatrix ()
 Constructor used for buildAtRuntime.
 
 DenseMatrix (int rows, int cols)
 Constructor for an empty DenseMatrix object whose value array holds rows*cols values.
 
 DenseMatrix (int rows, int cols, const std::valarray< T > &values)
 Constructor for a DenseMatrix class whose value array holds rows*cols values given by the user. Can throw an std::ivalid_argument if provided with a value array of different size than rows*cols.
 
Toperator() (int rows, int cols) override
 Parentheses operator to allow access to the matrix values as Matrix(row,column).
 
T operator() (int rows, int cols) const override
 Parentheses operator to allow access to the matrix values as Matrix(row,column) in a constant context.
 
 DenseMatrix (const DenseMatrix &)=default
 
DenseMatrixoperator= (const DenseMatrix &)=default
 
 DenseMatrix (DenseMatrix &&)=default
 
DenseMatrixoperator= (DenseMatrix &&)=default
 
std::valarray< TscalarAdd (T value) const override
 Addition of a scalar to the matrix values element-wise.
 
std::valarray< TmatrixAddElementWise (const DenseMatrix &dense_matrix) const
 Addition of two DenseMatrix objects element-wise.
 
std::valarray< TscalarSubtract (T value) const override
 Subtraction of a scalar from the matrix values element-wise.
 
std::valarray< TmatrixSubtractElementWise (const DenseMatrix &dense_matrix) const
 Subtraction of two DenseMatrix objects element-wise.
 
std::valarray< TscalarMultiply (T value) const override
 Multiplication of a scalar to the matrix values element-wise.
 
std::valarray< TmatrixMultiplyElementWise (const DenseMatrix &dense_matrix) const
 Multiplication of two DenseMatrix objects element-wise.
 
DenseMatrix< TmatrixMultiply (const DenseMatrix &dense_matrix) const
 Mathematical matrix multiplication of two DenseMatrix objects.
 
std::valarray< TscalarDivide (T value) const override
 Division of a scalar from the matrix values element-wise.
 
std::valarray< TmatrixDivideElementWise (const DenseMatrix &dense_matrix) const
 Division of two DenseMatrix objects element-wise.
 
std::valarray< TvectorElemAdd (const std::valarray< T > &value) const override
 Addition of a vector to the matrix values element-wise.
 
std::valarray< TvectorElemSubtract (const std::valarray< T > &value) const override
 Subtraction of a vector from the matrix values element-wise.
 
std::valarray< TvectorElemMultiply (const std::valarray< T > &value) const override
 Multiplication of a vector to the matrix values element-wise.
 
std::valarray< TvectorElemDivide (const std::valarray< T > &value) const override
 Division of a vector from the matrix values element-wise.
 
std::valarray< TmatrixVectorMultiplication (const std::valarray< T > &value) const override
 Matrix-vector-multiplication for dense matrices.
 
void buildAtRuntime (int rows, int cols) override
 Updates row, col values and array size if creation was deferred at invocation of constructor.
 
void updateNonZeroElements () override
 Updates the vector containing the non-zero element row-col pairs. Used for optimization.
 
const std::vector< std::pair< int, int > > & getNonZeroElements () override
 
const MatrixType getMatrixType () override
 
 ~DenseMatrix () override=default
 
- Public Member Functions inherited from GenericMatrix< T >
 GenericMatrix ()
 Constructor for an empty GenericMatrix object. This should only be used for dynamically created matrices.
 
 GenericMatrix (int rows, int cols)
 Constructor for an empty GenericMatrix object whose value array holds rows*cols values.
 
 GenericMatrix (int rows, int cols, const std::valarray< T > &values, bool allow_mismatched_size)
 Constructor for a GenericMatrix object whose value array holds rows*cols values given by the user. Can throw an std::ivalid_argument if provided with a value array of different size than rows*cols.
 
 GenericMatrix (const GenericMatrix &)=default
 
GenericMatrixoperator= (const GenericMatrix &)=default
 
 GenericMatrix (GenericMatrix &&)=default
 
GenericMatrixoperator= (GenericMatrix &&)=default
 
std::pair< int, intsize () const
 Function that returns the size of the matrix as a pair in (rows, columns) format.
 
virtual void registerElement (T value, int rows, int cols)
 
void zeroMatrix ()
 Function that zeros out the matrix.
 
void overwriteMatrixValues (const std::valarray< T > &value)
 Overwrites the matrix values with a new valarray. This is used for optimized overwrite when arithmetic operations on multiple matrices are used.
 
virtual ~GenericMatrix ()=default
 

Additional Inherited Members

- Protected Attributes inherited from GenericMatrix< T >
int m_rows {0}
 
int m_cols {0}
 
std::valarray< Tm_matrix {}
 
std::vector< std::pair< int, int > > m_non_zero_elements
 

Detailed Description

template<typename T>
class DenseMatrix< T >

Concrete implemenatation of a matrix class representing a dense matrix. Offers basic access and element wise arithmetic functionality and mathematical matrix product.

Constructor & Destructor Documentation

◆ DenseMatrix() [1/5]

template<typename T >
DenseMatrix< T >::DenseMatrix ( )

Constructor used for buildAtRuntime.

◆ DenseMatrix() [2/5]

template<typename T >
DenseMatrix< T >::DenseMatrix ( int  rows,
int  cols 
)

Constructor for an empty DenseMatrix object whose value array holds rows*cols values.

Parameters
rowsThe number of rows.
colsThe number of columns.

◆ DenseMatrix() [3/5]

template<typename T >
DenseMatrix< T >::DenseMatrix ( int  rows,
int  cols,
const std::valarray< T > &  values 
)

Constructor for a DenseMatrix class whose value array holds rows*cols values given by the user. Can throw an std::ivalid_argument if provided with a value array of different size than rows*cols.

Parameters
rowsThe number of rows.
colsThe number of columns.
valuesThe values to be stored in the m_matrix valarray.

◆ DenseMatrix() [4/5]

template<typename T >
DenseMatrix< T >::DenseMatrix ( const DenseMatrix< T > &  )
default

◆ DenseMatrix() [5/5]

template<typename T >
DenseMatrix< T >::DenseMatrix ( DenseMatrix< T > &&  )
default

◆ ~DenseMatrix()

template<typename T >
DenseMatrix< T >::~DenseMatrix ( )
overridedefault

Member Function Documentation

◆ buildAtRuntime()

template<typename T >
void DenseMatrix< T >::buildAtRuntime ( int  rows,
int  cols 
)
overridevirtual

Updates row, col values and array size if creation was deferred at invocation of constructor.

Template Parameters
TNumeric type used in the simulation (e.g., float, double).
Parameters
rowsThe number of rows of the matrix.
colsThe number of columns of the matrix.

Implements GenericMatrix< T >.

◆ getMatrixType()

template<typename T >
const MatrixType DenseMatrix< T >::getMatrixType ( )
inlineoverridevirtual

Implements GenericMatrix< T >.

◆ getNonZeroElements()

template<typename T >
const std::vector< std::pair< int, int > > & DenseMatrix< T >::getNonZeroElements ( )
inlineoverridevirtual

Implements GenericMatrix< T >.

◆ matrixAddElementWise()

template<typename T >
std::valarray< T > DenseMatrix< T >::matrixAddElementWise ( const DenseMatrix< T > &  dense_matrix) const

Addition of two DenseMatrix objects element-wise.

Parameters
dense_matrixThe DenseMatrix object to be added to the calling object.

◆ matrixDivideElementWise()

template<typename T >
std::valarray< T > DenseMatrix< T >::matrixDivideElementWise ( const DenseMatrix< T > &  dense_matrix) const

Division of two DenseMatrix objects element-wise.

Parameters
dense_matrixThe DenseMatrix object to divide the calling object by.

◆ matrixMultiply()

template<typename T >
DenseMatrix< T > DenseMatrix< T >::matrixMultiply ( const DenseMatrix< T > &  dense_matrix) const

Mathematical matrix multiplication of two DenseMatrix objects.

Parameters
dense_matrixThe DenseMatrix object to be multiplied from the right to the calling object.

◆ matrixMultiplyElementWise()

template<typename T >
std::valarray< T > DenseMatrix< T >::matrixMultiplyElementWise ( const DenseMatrix< T > &  dense_matrix) const

Multiplication of two DenseMatrix objects element-wise.

Parameters
dense_matrixThe DenseMatrix object to be multiplied to the calling object.

◆ matrixSubtractElementWise()

template<typename T >
std::valarray< T > DenseMatrix< T >::matrixSubtractElementWise ( const DenseMatrix< T > &  dense_matrix) const

Subtraction of two DenseMatrix objects element-wise.

Parameters
dense_matrixThe DenseMatrix object to be subtracted from the calling object.

◆ matrixVectorMultiplication()

template<typename T >
std::valarray< T > DenseMatrix< T >::matrixVectorMultiplication ( const std::valarray< T > &  value) const
overridevirtual

Matrix-vector-multiplication for dense matrices.

Template Parameters
TNumeric type used in the simulation (e.g., float, double)
Parameters
valueThe vector with the values to multiply to the matrix from the right.
Returns
std::valarray<T> std::valarray<T> The resulting vector.

Implements GenericMatrix< T >.

◆ operator()() [1/2]

template<typename T >
T DenseMatrix< T >::operator() ( int  rows,
int  cols 
) const
overridevirtual

Parentheses operator to allow access to the matrix values as Matrix(row,column) in a constant context.

Parameters
rowsthe row to access.
columnthe column to access.

Implements GenericMatrix< T >.

◆ operator()() [2/2]

template<typename T >
T & DenseMatrix< T >::operator() ( int  rows,
int  cols 
)
overridevirtual

Parentheses operator to allow access to the matrix values as Matrix(row,column).

Parameters
rowsthe row to access.
columnthe column to access.

Implements GenericMatrix< T >.

◆ operator=() [1/2]

template<typename T >
DenseMatrix & DenseMatrix< T >::operator= ( const DenseMatrix< T > &  )
default

◆ operator=() [2/2]

template<typename T >
DenseMatrix & DenseMatrix< T >::operator= ( DenseMatrix< T > &&  )
default

◆ scalarAdd()

template<typename T >
std::valarray< T > DenseMatrix< T >::scalarAdd ( T  value) const
overridevirtual

Addition of a scalar to the matrix values element-wise.

Parameters
valueThe scalar value to be added to the calling object.

Implements GenericMatrix< T >.

◆ scalarDivide()

template<typename T >
std::valarray< T > DenseMatrix< T >::scalarDivide ( T  value) const
overridevirtual

Division of a scalar from the matrix values element-wise.

Parameters
valueThe scalar value to divide to the calling object by.

Implements GenericMatrix< T >.

◆ scalarMultiply()

template<typename T >
std::valarray< T > DenseMatrix< T >::scalarMultiply ( T  value) const
overridevirtual

Multiplication of a scalar to the matrix values element-wise.

Parameters
valueThe scalar value to be multiplied to the calling object.

Implements GenericMatrix< T >.

◆ scalarSubtract()

template<typename T >
std::valarray< T > DenseMatrix< T >::scalarSubtract ( T  value) const
overridevirtual

Subtraction of a scalar from the matrix values element-wise.

Parameters
valueThe scalar value to be subtracted from the calling object.

Implements GenericMatrix< T >.

◆ updateNonZeroElements()

template<typename T >
void DenseMatrix< T >::updateNonZeroElements ( )
overridevirtual

Updates the vector containing the non-zero element row-col pairs. Used for optimization.

Template Parameters
TNumeric type used in the simulation (e.g., float, double)

Implements GenericMatrix< T >.

◆ vectorElemAdd()

template<typename T >
std::valarray< T > DenseMatrix< T >::vectorElemAdd ( const std::valarray< T > &  value) const
overridevirtual

Addition of a vector to the matrix values element-wise.

Parameters
valueThe vector values to be added to the calling object.

Implements GenericMatrix< T >.

◆ vectorElemDivide()

template<typename T >
std::valarray< T > DenseMatrix< T >::vectorElemDivide ( const std::valarray< T > &  value) const
overridevirtual

Division of a vector from the matrix values element-wise.

Parameters
valueThe vector value to divide to the calling object by.

Implements GenericMatrix< T >.

◆ vectorElemMultiply()

template<typename T >
std::valarray< T > DenseMatrix< T >::vectorElemMultiply ( const std::valarray< T > &  value) const
overridevirtual

Multiplication of a vector to the matrix values element-wise.

Parameters
valueThe vector value to be multiplied to the calling object.

Implements GenericMatrix< T >.

◆ vectorElemSubtract()

template<typename T >
std::valarray< T > DenseMatrix< T >::vectorElemSubtract ( const std::valarray< T > &  value) const
overridevirtual

Subtraction of a vector from the matrix values element-wise.

Parameters
valueThe vector value to be subtracted from the calling object.

Implements GenericMatrix< T >.


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