NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
Matrix Class Reference

This class defines a dynamic size 2D matrix with a single 1D internal buffer. If the internal buffer is used directly within the parser, parallelisation is far more common. More...

#include <matdatastructures.hpp>

Collaboration diagram for Matrix:

Public Member Functions

 Matrix ()
 Empty matrix default constructor. More...
 
 Matrix (size_t r, size_t c=1u, const mu::value_type &init=NAN)
 Fill constructor. More...
 
 Matrix (const Matrix &mat)
 Matrix copy constructor. More...
 
 Matrix (Matrix &&mat)=default
 
 Matrix (const std::vector< std::vector< mu::value_type > > &vectMatrix)
 Construct a matrix from a vector matrix. More...
 
 Matrix (size_t r, size_t c, mu::value_type *vVals, int nVals)
 Assign constructor from large array. More...
 
Matrixoperator= (const Matrix &mat)
 Assignment operator overload. More...
 
void assign (const Matrix &mat)
 Assign a matrix. More...
 
void assign (size_t r, size_t c, mu::value_type *vVals, int nVals)
 Assign a large array. More...
 
void assign (size_t r, size_t c, const std::vector< mu::value_type > &vVals)
 Assign a vector. More...
 
std::vector< mu::value_type > & data ()
 Get a reference to the internal data structure. More...
 
const std::vector< mu::value_type > & data () const
 Get a const reference to the internal data structure. More...
 
void transpose ()
 Transpose this matrix. More...
 
size_t rows () const
 The rows of this matrix. More...
 
size_t cols () const
 The cols of this matrix. More...
 
std::pair< size_t, size_t > dims () const
 Get both dimensions at once. More...
 
bool isScalar () const
 Check, whether this matrix is actually a scalar. More...
 
bool isSquare () const
 Simple function to identify square matrices. More...
 
bool isEmpty () const
 Simple function to identify empty matrices. More...
 
bool containsInvalidValues () const
 Returns true, if this matrix contains invalid values. More...
 
std::string printDims () const
 Convert the dimensions to a printable string. More...
 
mu::value_typeoperator() (size_t i, size_t j=0u)
 Get a reference to the indexed element. More...
 
const mu::value_typeoperator() (size_t i, size_t j=0u) const
 Get a const reference to the indexed element. More...
 
void resize (size_t r, size_t c)
 Resize the matrix to another dimension. New elements will be zero-initialized. More...
 
void extend (size_t r, size_t c)
 Extend this matrix to be prepared for the acutal mathematical operation. Scalars are not touched and vectors are repmat()-ed to enable elementwise operations. More...
 
Matrixoperator*= (const Matrix &mat)
 Multiply a matrix from the right to this matrix. More...
 
Matrix operator* (const Matrix &mat) const
 Multiply this matrix with a matrix from the right. More...
 
Matrix hcat (const Matrix &mat) const
 Horizontally concatenate two matrices. More...
 
Matrix vcat (const Matrix &mat) const
 Vertically concatenate two matrices. More...
 

Private Member Functions

mu::value_typeget (size_t i, size_t j)
 Unchecked method to access indexed elements. More...
 
const mu::value_typeget (size_t i, size_t j) const
 Const declared overload to the indexed access. More...
 
void bakeTransposition ()
 Bakes the transposition by swapping the actual elements instead of changing the read order. More...
 

Private Attributes

std::vector< mu::value_typem_storage
 The internal buffer. More...
 
size_t m_rows
 Number of rows. More...
 
size_t m_cols
 Number of columns. More...
 
bool m_transpose
 Is this Matrix transposed. More...
 

Detailed Description

This class defines a dynamic size 2D matrix with a single 1D internal buffer. If the internal buffer is used directly within the parser, parallelisation is far more common.

Definition at line 37 of file matdatastructures.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/6]

Matrix::Matrix ( )
inline

Empty matrix default constructor.

Definition at line 104 of file matdatastructures.hpp.

◆ Matrix() [2/6]

Matrix::Matrix ( size_t  r,
size_t  c = 1u,
const mu::value_type init = NAN 
)
inline

Fill constructor.

Parameters
rsize_t
csize_t
initconst mu::value_type&

Definition at line 114 of file matdatastructures.hpp.

References m_storage.

◆ Matrix() [3/6]

Matrix::Matrix ( const Matrix mat)
inline

Matrix copy constructor.

Parameters
matconst Matrix&

Definition at line 125 of file matdatastructures.hpp.

References assign().

Here is the call graph for this function:

◆ Matrix() [4/6]

Matrix::Matrix ( Matrix &&  mat)
default

◆ Matrix() [5/6]

Matrix::Matrix ( const std::vector< std::vector< mu::value_type > > &  vectMatrix)
inline

Construct a matrix from a vector matrix.

Parameters
vectMatrixconst std::vector<std::vector<mu::value_type>>&

Definition at line 140 of file matdatastructures.hpp.

References get(), m_cols, m_rows, m_storage, and max.

Here is the call graph for this function:

◆ Matrix() [6/6]

Matrix::Matrix ( size_t  r,
size_t  c,
mu::value_type vVals,
int  nVals 
)
inline

Assign constructor from large array.

Parameters
rsize_t
csize_t
vValsmu::value_type*
nValsint

Definition at line 168 of file matdatastructures.hpp.

References assign().

Here is the call graph for this function:

Member Function Documentation

◆ assign() [1/3]

void Matrix::assign ( const Matrix mat)
inline

Assign a matrix.

Parameters
matconst Matrix&
Returns
void

Definition at line 193 of file matdatastructures.hpp.

References m_cols, m_rows, m_storage, and m_transpose.

Referenced by Matrix(), matrixUnique(), operator*=(), and operator=().

◆ assign() [2/3]

void Matrix::assign ( size_t  r,
size_t  c,
const std::vector< mu::value_type > &  vVals 
)
inline

Assign a vector.

Parameters
rsize_t
csize_t
vValsconst std::vector<mu::value_type>&
Returns
void

Definition at line 229 of file matdatastructures.hpp.

References m_cols, m_rows, m_storage, m_transpose, and min.

◆ assign() [3/3]

void Matrix::assign ( size_t  r,
size_t  c,
mu::value_type vVals,
int  nVals 
)
inline

Assign a large array.

Parameters
rsize_t
csize_t
vValsmu::value_type*
nValsint
Returns
void

Definition at line 211 of file matdatastructures.hpp.

References m_cols, m_rows, m_storage, m_transpose, and min.

◆ bakeTransposition()

void Matrix::bakeTransposition ( )
inlineprivate

Bakes the transposition by swapping the actual elements instead of changing the read order.

Returns
void

Definition at line 81 of file matdatastructures.hpp.

References m_cols, m_rows, m_storage, and m_transpose.

Referenced by extend().

◆ cols()

◆ containsInvalidValues()

bool Matrix::containsInvalidValues ( ) const
inline

Returns true, if this matrix contains invalid values.

Returns
bool

Definition at line 350 of file matdatastructures.hpp.

References mu::isinf(), mu::isnan(), and m_storage.

Referenced by __attribute__(), and invertMatrix().

Here is the call graph for this function:

◆ data() [1/2]

std::vector< mu::value_type > & Matrix::data ( )
inline

Get a reference to the internal data structure.

Returns
std::vector<mu::value_type>&

Definition at line 245 of file matdatastructures.hpp.

References m_storage.

Referenced by Assertion::checkAssertion(), evalMatOp(), matrixCumPrd(), matrixCumSum(), matrixMed(), matrixPct(), and matrixUnique().

◆ data() [2/2]

const std::vector< mu::value_type > & Matrix::data ( ) const
inline

Get a const reference to the internal data structure.

Returns
const std::vector<mu::value_type>&

Definition at line 257 of file matdatastructures.hpp.

References m_storage.

◆ dims()

std::pair< size_t, size_t > Matrix::dims ( ) const
inline

Get both dimensions at once.

Returns
std::pair<size_t,size_t>

Definition at line 302 of file matdatastructures.hpp.

References m_cols, and m_rows.

◆ extend()

void Matrix::extend ( size_t  r,
size_t  c 
)
inline

Extend this matrix to be prepared for the acutal mathematical operation. Scalars are not touched and vectors are repmat()-ed to enable elementwise operations.

Parameters
rsize_t
csize_t
Returns
void

Definition at line 458 of file matdatastructures.hpp.

References bakeTransposition(), get(), isScalar(), m_cols, m_rows, and resize().

Referenced by evalMatOp().

Here is the call graph for this function:

◆ get() [1/2]

mu::value_type & Matrix::get ( size_t  i,
size_t  j 
)
inlineprivate

Unchecked method to access indexed elements.

Parameters
isize_t
jsize_t
Returns
mu::value_type&

Definition at line 54 of file matdatastructures.hpp.

References m_cols, m_rows, m_storage, and m_transpose.

Referenced by extend(), hcat(), Matrix(), operator()(), operator*(), and vcat().

◆ get() [2/2]

const mu::value_type & Matrix::get ( size_t  i,
size_t  j 
) const
inlineprivate

Const declared overload to the indexed access.

Parameters
isize_t
jsize_t
Returns
const mu::value_type&

Definition at line 68 of file matdatastructures.hpp.

References m_cols, m_rows, m_storage, and m_transpose.

◆ hcat()

Matrix Matrix::hcat ( const Matrix mat) const
inline

Horizontally concatenate two matrices.

Parameters
matconst Matrix&
Returns
Matrix

Definition at line 553 of file matdatastructures.hpp.

References cols(), get(), m_cols, m_rows, max, and rows().

Referenced by hcat().

Here is the call graph for this function:

◆ isEmpty()

◆ isScalar()

bool Matrix::isScalar ( ) const
inline

Check, whether this matrix is actually a scalar.

Returns
bool

Definition at line 314 of file matdatastructures.hpp.

References m_cols, and m_rows.

Referenced by assemble(), extend(), and selection().

◆ isSquare()

bool Matrix::isSquare ( ) const
inline

Simple function to identify square matrices.

Returns
bool

Definition at line 326 of file matdatastructures.hpp.

References m_cols, and m_rows.

Referenced by __attribute__(), calcTrace(), getDeterminant(), and invertMatrix().

◆ operator()() [1/2]

mu::value_type & Matrix::operator() ( size_t  i,
size_t  j = 0u 
)
inline

Get a reference to the indexed element.

Parameters
isize_t
jsize_t
Returns
mu::value_type&

Definition at line 382 of file matdatastructures.hpp.

References get(), SyntaxError::INVALID_INDEX, SyntaxError::invalid_position, m_cols, m_rows, printDims(), and toString().

Here is the call graph for this function:

◆ operator()() [2/2]

const mu::value_type & Matrix::operator() ( size_t  i,
size_t  j = 0u 
) const
inline

Get a const reference to the indexed element.

Parameters
isize_t
jsize_t
Returns
const mu::value_type&

Definition at line 401 of file matdatastructures.hpp.

References get(), SyntaxError::INVALID_INDEX, SyntaxError::invalid_position, m_cols, m_rows, printDims(), and toString().

Here is the call graph for this function:

◆ operator*()

Matrix Matrix::operator* ( const Matrix mat) const
inline

Multiply this matrix with a matrix from the right.

Parameters
matconst Matrix&
Returns
Matrix

Definition at line 520 of file matdatastructures.hpp.

References get(), SyntaxError::invalid_position, m_cols, m_rows, printDims(), and SyntaxError::WRONG_MATRIX_DIMENSIONS_FOR_MATOP.

Here is the call graph for this function:

◆ operator*=()

Matrix & Matrix::operator*= ( const Matrix mat)
inline

Multiply a matrix from the right to this matrix.

Parameters
matconst Matrix&
Returns
Matrix&

Definition at line 506 of file matdatastructures.hpp.

References assign().

Here is the call graph for this function:

◆ operator=()

Matrix & Matrix::operator= ( const Matrix mat)
inline

Assignment operator overload.

Parameters
matconst Matrix&
Returns
Matrix&

Definition at line 180 of file matdatastructures.hpp.

References assign().

Here is the call graph for this function:

◆ printDims()

std::string Matrix::printDims ( ) const
inline

Convert the dimensions to a printable string.

Returns
std::string

Definition at line 368 of file matdatastructures.hpp.

References m_cols, m_rows, and toString().

Referenced by evalMatOp(), multiplyMatrices(), operator()(), operator*(), and printMatrixDim().

Here is the call graph for this function:

◆ resize()

void Matrix::resize ( size_t  r,
size_t  c 
)
inline

Resize the matrix to another dimension. New elements will be zero-initialized.

Parameters
rsize_t
csize_t
Returns
void

Definition at line 421 of file matdatastructures.hpp.

References m_cols, m_rows, m_storage, and min.

Referenced by correlation(), createShuffledMatrix(), extend(), and matrixResize().

◆ rows()

◆ transpose()

void Matrix::transpose ( )
inline

Transpose this matrix.

Returns
void

Definition at line 268 of file matdatastructures.hpp.

References m_cols, m_rows, and m_transpose.

Referenced by matrixUnique(), and transposeMatrix().

◆ vcat()

Matrix Matrix::vcat ( const Matrix mat) const
inline

Vertically concatenate two matrices.

Parameters
matconst Matrix&
Returns
Matrix

Definition at line 588 of file matdatastructures.hpp.

References cols(), get(), m_cols, m_rows, max, and rows().

Referenced by vcat().

Here is the call graph for this function:

Member Data Documentation

◆ m_cols

size_t Matrix::m_cols
private

◆ m_rows

size_t Matrix::m_rows
private

◆ m_storage

std::vector<mu::value_type> Matrix::m_storage
private

The internal buffer.

Definition at line 40 of file matdatastructures.hpp.

Referenced by assign(), bakeTransposition(), containsInvalidValues(), data(), get(), Matrix(), and resize().

◆ m_transpose

bool Matrix::m_transpose
private

Is this Matrix transposed.

Definition at line 43 of file matdatastructures.hpp.

Referenced by assign(), bakeTransposition(), get(), and transpose().


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