Peano 4
Loading...
Searching...
No Matches
tarch::la::DynamicMatrix Class Reference

My standard matrix is a matrix where the size is fixed at compile time. More...

#include <DynamicMatrix.h>

Public Member Functions

 DynamicMatrix (int rows, int cols)
 Create empty matrix.
 
 ~DynamicMatrix ()
 Free the array on the heap.
 
 DynamicMatrix (int rows, int cols, std::initializer_list< std::initializer_list< double > > values)
 
 DynamicMatrix (const DynamicMatrix &)
 
 DynamicMatrix (DynamicMatrix &&)
 
 DynamicMatrix (const DynamicMatrix &lhs, const DynamicMatrix &rhs, bool innerProduct)
 
DynamicMatrixoperator= (const DynamicMatrix &)=delete
 
DynamicMatrixoperator= (std::initializer_list< std::initializer_list< double > > values)
 This template allows you to write stuff like.
 
template<int Cols>
bool operator== (double values[][Cols]) const
 
bool operator== (const DynamicMatrix &matrix) const
 
std::string toString (bool addLineBreaks=false) const
 
double & operator() (int row, int col)
 
double operator() (int row, int col) const
 
void multiply (double *result, double *x)
 
void batchedMultiplyAoS (double *__restrict__ result, const double *__restrict__ x, int batchCount, int resultSize, int firstRow)
 This operation assumes that x holds a whole batch of vectors in AoS format.
 
void batchedMultiplyAoS (double *__restrict__ result, const double *__restrict__ x, int batchCount)
 Wrapper around other batch operation.
 
void replicateRows (int blockSize, int numberOfReplications, int shiftAfterEveryReplication, bool extendColumnsToAccommodateShifts)
 Split the matrix into blocks of rows of size blockSize.
 
void replicateCols (int blockSize, int numberOfReplications, int shiftAfterEveryReplication, bool extendColumnsToAccommodateShifts)
 
void insertEmptyColumns (int number, int where, int repeatEveryKColumns=0)
 Insert zero columns.
 
void insertEmptyRows (int number, int where, int repeatEveryKColumns=0)
 
void shiftRowsDown (int shift, bool wrap=false)
 Shift the rows to the right.
 
void shiftColumnsRight (int shift, bool wrap=false)
 
void removeColumn (int number)
 
void scale (double value)
 Scale all entries.
 
int rows () const
 
int cols () const
 

Static Public Member Functions

static std::string vectorToString (double *values, int entries, bool addLineBreaks=false)
 I often need this in combination with the toString() operation above.
 
static tarch::la::DynamicMatrix id (int rows)
 Create (square) identify matrix with rows rows and column.
 

Private Member Functions

int serialise (int row, int col) const
 

Static Private Member Functions

static int serialise (int row, int col, int Rows, int Cols)
 

Private Attributes

int _cols
 
int _rows
 
double * _m
 

Detailed Description

My standard matrix is a matrix where the size is fixed at compile time.

This is a matrix class where the size is fixed at runtime.

Definition at line 20 of file DynamicMatrix.h.

Constructor & Destructor Documentation

◆ DynamicMatrix() [1/5]

tarch::la::DynamicMatrix::DynamicMatrix ( int rows,
int cols )

Create empty matrix.

Definition at line 75 of file DynamicMatrix.cpp.

References _m, cols(), tarch::Heap, and rows().

Here is the call graph for this function:

◆ ~DynamicMatrix()

tarch::la::DynamicMatrix::~DynamicMatrix ( )

Free the array on the heap.

If the matrix has been moved before (due to return value optimisation, e.g.) _m is equal to nullptr and we should not delete it anymore. Otherwise, _m always has to be freed.

Definition at line 91 of file DynamicMatrix.cpp.

References tarch::freeMemory(), and tarch::Heap.

Here is the call graph for this function:

◆ DynamicMatrix() [2/5]

tarch::la::DynamicMatrix::DynamicMatrix ( int rows,
int cols,
std::initializer_list< std::initializer_list< double > > values )

Definition at line 33 of file DynamicMatrix.cpp.

References _m, cols(), tarch::Heap, rows(), and values.

Here is the call graph for this function:

◆ DynamicMatrix() [3/5]

tarch::la::DynamicMatrix::DynamicMatrix ( const DynamicMatrix & rhs)

Definition at line 47 of file DynamicMatrix.cpp.

References _cols, _m, _rows, and tarch::Heap.

◆ DynamicMatrix() [4/5]

tarch::la::DynamicMatrix::DynamicMatrix ( DynamicMatrix && rhs)

Definition at line 55 of file DynamicMatrix.cpp.

◆ DynamicMatrix() [5/5]

tarch::la::DynamicMatrix::DynamicMatrix ( const DynamicMatrix & lhs,
const DynamicMatrix & rhs,
bool innerProduct )
Parameters
innerProductIf this flag is set, I use the inner product between the two matrices. If it is not set, I use the generalised outer product, i.e. the Kronecker product to construct the new matrix.

Definition at line 13 of file DynamicMatrix.cpp.

References _cols, _m, _rows, assertionMsg, tarch::Heap, and serialise().

Here is the call graph for this function:

Member Function Documentation

◆ batchedMultiplyAoS() [1/2]

void tarch::la::DynamicMatrix::batchedMultiplyAoS ( double *__restrict__ result,
const double *__restrict__ x,
int batchCount )

Wrapper around other batch operation.

The whole matrix is used.

Definition at line 191 of file DynamicMatrix.cpp.

◆ batchedMultiplyAoS() [2/2]

void tarch::la::DynamicMatrix::batchedMultiplyAoS ( double *__restrict__ result,
const double *__restrict__ x,
int batchCount,
int resultSize,
int firstRow )

This operation assumes that x holds a whole batch of vectors in AoS format.

If batchSize is 5, then x points to five vectors of length _rows. The five vectors are store as AoS, i.e. x[0] is the first entry of the first vector, x[1] the first entry of the second vector, and so forth. The multiplication applies the matrix to all vectors stored in x. It assumes that result also holds a sequence of vectors.

Parameters
batchSizeNumber of elements within x/result to which the matrix has to be applied in one rush.
resultSizeNumber of entries in vector result. Please note that this number will be multiplied with batchSize, i.e. it is the entries per batch entry.
firstRowFirst row to pick from matrix. If the resultSize is equal to the number of rows of the matrix, then this entry should be 0. Otherwise, you can pick only a few rows from the matrix through this offset. The fact that I can use a subset of the matrix requires me to pass in resultSize explicitly.

Definition at line 199 of file DynamicMatrix.cpp.

References assertion3, and tarch::la::col().

Here is the call graph for this function:

◆ cols()

◆ id()

tarch::la::DynamicMatrix tarch::la::DynamicMatrix::id ( int rows)
static

Create (square) identify matrix with rows rows and column.

Definition at line 124 of file DynamicMatrix.cpp.

◆ insertEmptyColumns()

void tarch::la::DynamicMatrix::insertEmptyColumns ( int number,
int where,
int repeatEveryKColumns = 0 )

Insert zero columns.

Parameters
numberHow many columns shall be inserted. Has to be at least one.
whereNumber of the first column to be inserted. Put in 0 to insert one to the left of the matrix.
repeatEveryKColumnsIf this one is zero, we insert only once. If it is bigger then zero, we insert number columns every repeatEveryKColumns starting from where. So if you pass in one, then every other column, we'll insert number of columns.

Definition at line 225 of file DynamicMatrix.cpp.

References assertion4, tarch::la::col(), tarch::freeMemory(), tarch::Heap, tarch::la::row(), and tarch::toString().

Here is the call graph for this function:

◆ insertEmptyRows()

void tarch::la::DynamicMatrix::insertEmptyRows ( int number,
int where,
int repeatEveryKColumns = 0 )

Definition at line 258 of file DynamicMatrix.cpp.

References assertion4, tarch::la::col(), tarch::freeMemory(), tarch::Heap, tarch::la::row(), and tarch::toString().

Here is the call graph for this function:

◆ multiply()

void tarch::la::DynamicMatrix::multiply ( double * result,
double * x )

Definition at line 139 of file DynamicMatrix.cpp.

References tarch::la::col(), and tarch::la::row().

Here is the call graph for this function:

◆ operator()() [1/2]

double & tarch::la::DynamicMatrix::operator() ( int row,
int col )

Definition at line 108 of file DynamicMatrix.cpp.

References assertion4, tarch::la::col(), and tarch::la::row().

Here is the call graph for this function:

◆ operator()() [2/2]

double tarch::la::DynamicMatrix::operator() ( int row,
int col ) const

Definition at line 116 of file DynamicMatrix.cpp.

References assertion, tarch::la::col(), and tarch::la::row().

Here is the call graph for this function:

◆ operator=() [1/2]

DynamicMatrix & tarch::la::DynamicMatrix::operator= ( const DynamicMatrix & )
delete

◆ operator=() [2/2]

tarch::la::DynamicMatrix & tarch::la::DynamicMatrix::operator= ( std::initializer_list< std::initializer_list< double > > values)

This template allows you to write stuff like.


double P[Rows][Cols] = {
  {3.0/3.0, 0.0,    0.0/3.0, 0.0,     0.0/3.0, 0.0,    0.0/3.0, 0.0},
  {    0.0, 0.0,        0.0, 0.0,         0.0, 0.0,        0.0, 0.0},
  {3.0/3.0, 0.0,    0.0/3.0, 0.0,     0.0/3.0, 0.0,    0.0/3.0, 0.0},
  {    0.0, 0.0,        0.0, 0.0,         0.0, 0.0,        0.0, 0.0},
  ...

tarch::la::DynamicMatrix myP(Rows,Cols);
myP = P;

   

Definition at line 64 of file DynamicMatrix.cpp.

References assertion3, and values.

◆ operator==() [1/2]

bool tarch::la::DynamicMatrix::operator== ( const DynamicMatrix & matrix) const

Definition at line 97 of file DynamicMatrix.cpp.

References tarch::la::col(), tarch::la::equals(), matrix, and tarch::la::row().

Here is the call graph for this function:

◆ operator==() [2/2]

template<int Cols>
bool tarch::la::DynamicMatrix::operator== ( double values[][Cols]) const

Definition at line 93 of file DynamicMatrix.h.

References _cols, _m, _rows, tarch::la::col(), tarch::la::equals(), tarch::la::row(), serialise(), and values.

Here is the call graph for this function:

◆ removeColumn()

void tarch::la::DynamicMatrix::removeColumn ( int number)

Definition at line 291 of file DynamicMatrix.cpp.

References tarch::la::col(), tarch::freeMemory(), tarch::Heap, and tarch::la::row().

Here is the call graph for this function:

◆ replicateCols()

void tarch::la::DynamicMatrix::replicateCols ( int blockSize,
int numberOfReplications,
int shiftAfterEveryReplication,
bool extendColumnsToAccommodateShifts )

Definition at line 392 of file DynamicMatrix.cpp.

References assertion2, assertion3, tarch::freeMemory(), tarch::Heap, and tarch::la::row().

Here is the call graph for this function:

◆ replicateRows()

void tarch::la::DynamicMatrix::replicateRows ( int blockSize,
int numberOfReplications,
int shiftAfterEveryReplication,
bool extendColumnsToAccommodateShifts )

Split the matrix into blocks of rows of size blockSize.

The number of rows now is increased by a factor of numberOfReplications. Each block is replicated numberOfReplications in the final output. For the replicated blocks, we shift each column by shiftAfterEveryReplication. So this entry can be zero if you want no shifts. Due to the shifts, it might happen that we access additional columns. If extendColumnsToAccommodateShifts is set, the operation appends columns as required. If extendColumnsToAccommodateShifts, it simply truncates the shifts.

Definition at line 352 of file DynamicMatrix.cpp.

References assertion2, assertion3, tarch::la::col(), tarch::freeMemory(), and tarch::Heap.

Referenced by toolbox::blockstructured::internal::createLinearInterpolationMatrix(), toolbox::blockstructured::internal::createLinearInterpolationMatrix(), and toolbox::blockstructured::internal::createPiecewiseConstantInterpolationMatrix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rows()

◆ scale()

void tarch::la::DynamicMatrix::scale ( double value)

Scale all entries.

Definition at line 132 of file DynamicMatrix.cpp.

References tarch::la::col(), and tarch::la::row().

Here is the call graph for this function:

◆ serialise() [1/2]

int tarch::la::DynamicMatrix::serialise ( int row,
int col ) const
private

Definition at line 30 of file DynamicMatrix.h.

References _cols, _rows, tarch::la::col(), tarch::la::row(), and serialise().

Here is the call graph for this function:

◆ serialise() [2/2]

static int tarch::la::DynamicMatrix::serialise ( int row,
int col,
int Rows,
int Cols )
staticprivate

Definition at line 26 of file DynamicMatrix.h.

References tarch::la::col(), and tarch::la::row().

Referenced by DynamicMatrix(), operator==(), and serialise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shiftColumnsRight()

void tarch::la::DynamicMatrix::shiftColumnsRight ( int shift,
bool wrap = false )

Definition at line 327 of file DynamicMatrix.cpp.

References tarch::la::col(), tarch::freeMemory(), tarch::Heap, and tarch::la::row().

Here is the call graph for this function:

◆ shiftRowsDown()

void tarch::la::DynamicMatrix::shiftRowsDown ( int shift,
bool wrap = false )

Shift the rows to the right.

Definition at line 310 of file DynamicMatrix.cpp.

References tarch::la::col(), tarch::freeMemory(), tarch::Heap, and tarch::la::row().

Here is the call graph for this function:

◆ toString()

◆ vectorToString()

std::string tarch::la::DynamicMatrix::vectorToString ( double * values,
int entries,
bool addLineBreaks = false )
static

I often need this in combination with the toString() operation above.

Definition at line 176 of file DynamicMatrix.cpp.

References values.

Field Documentation

◆ _cols

int tarch::la::DynamicMatrix::_cols
private

Definition at line 22 of file DynamicMatrix.h.

Referenced by DynamicMatrix(), DynamicMatrix(), operator==(), and serialise().

◆ _m

double* tarch::la::DynamicMatrix::_m
private

◆ _rows

int tarch::la::DynamicMatrix::_rows
private

Definition at line 23 of file DynamicMatrix.h.

Referenced by DynamicMatrix(), DynamicMatrix(), operator==(), and serialise().


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