Peano
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)
 
 DynamicMatrix (int rows, int cols, double *data)
 
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
 
doubledata ()
 
const doubledata () const
 
doubleoperator() (int row, int col)
 
double operator() (int row, int col) const
 
void multiply (double *result, double *x)
 
void multiplyBySmallMatrix (double *result, const DynamicMatrix &matrix) const
 
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/6]

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

Create empty matrix.

Definition at line 117 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 133 of file DynamicMatrix.cpp.

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

Here is the call graph for this function:

◆ DynamicMatrix() [2/6]

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

Definition at line 49 of file DynamicMatrix.cpp.

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

Here is the call graph for this function:

◆ DynamicMatrix() [3/6]

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

Definition at line 73 of file DynamicMatrix.cpp.

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

◆ DynamicMatrix() [4/6]

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

Definition at line 84 of file DynamicMatrix.cpp.

◆ DynamicMatrix() [5/6]

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 20 of file DynamicMatrix.cpp.

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

Here is the call graph for this function:

◆ DynamicMatrix() [6/6]

tarch::la::DynamicMatrix::DynamicMatrix ( int rows,
int cols,
double * data )

Definition at line 93 of file DynamicMatrix.cpp.

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 263 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 271 of file DynamicMatrix.cpp.

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

Here is the call graph for this function:

◆ cols()

◆ data() [1/2]

double * tarch::la::DynamicMatrix::data ( )

Definition at line 130 of file DynamicMatrix.h.

References _m.

Referenced by peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__generate_dastgen_input_file(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_file_name(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_full_qualified_file_name(), swift2.particle.Particle.Particle::__init__(), swift2.particle.Particle.Particle::_add_dependency_checks(), swift2.particle.Particle.Particle::_dependency_checks_modify_steps(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_enum_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_double_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_integer_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_string_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_user_defined_attributes(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::_get_dictionary_for_output(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::construct_output(), peano4.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::construct_output(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::construct_output(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::construct_output(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::construct_output(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_header_file_include(), peano4.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::get_header_file_include(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_header_file_include(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_header_file_include(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_header_file_include(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_stack_container(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_stack_container(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_stack_container(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_stack_container(), operator*(), swift2.particle.Particle.Particle::readme_descriptor(), swift2.particle.SPHLeapfrogFixedSearchRadius.SPHLeapfrogFixedSearchRadius::set_parameters(), swift2.particle.SPHParticle.SPHParticle::set_parameters(), and swift2.particle.tests.testLeapfrogFixedTimeStepSize.testLeapfrogFixedTimeStepSize::set_parameters().

Here is the caller graph for this function:

◆ data() [2/2]

const double * tarch::la::DynamicMatrix::data ( ) const

Definition at line 131 of file DynamicMatrix.h.

References _m.

Referenced by peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__generate_dastgen_input_file(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_file_name(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_full_qualified_file_name(), swift2.particle.Particle.Particle::__init__(), swift2.particle.Particle.Particle::_add_dependency_checks(), swift2.particle.Particle.Particle::_dependency_checks_modify_steps(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_enum_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_double_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_integer_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_string_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_user_defined_attributes(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::_get_dictionary_for_output(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::construct_output(), peano4.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::construct_output(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::construct_output(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::construct_output(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::construct_output(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_header_file_include(), peano4.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::get_header_file_include(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_header_file_include(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_header_file_include(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_header_file_include(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_stack_container(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_stack_container(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_stack_container(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_stack_container(), swift2.particle.Particle.Particle::readme_descriptor(), swift2.particle.SPHLeapfrogFixedSearchRadius.SPHLeapfrogFixedSearchRadius::set_parameters(), swift2.particle.SPHParticle.SPHParticle::set_parameters(), and swift2.particle.tests.testLeapfrogFixedTimeStepSize.testLeapfrogFixedTimeStepSize::set_parameters().

Here is the caller graph for this function:

◆ id()

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

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

Definition at line 169 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 303 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 349 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 184 of file DynamicMatrix.cpp.

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

Here is the call graph for this function:

◆ multiplyBySmallMatrix()

void tarch::la::DynamicMatrix::multiplyBySmallMatrix ( double * result,
const DynamicMatrix & matrix ) const

Definition at line 200 of file DynamicMatrix.cpp.

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

Referenced by toolbox::blockstructured::interpolateCellDataAssociatedToVolumesIntoOverlappingCell_secondOrder().

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

◆ operator()() [1/2]

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

Definition at line 153 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 161 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 98 of file DynamicMatrix.cpp.

References assertion3.

◆ operator==() [1/2]

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

Definition at line 139 of file DynamicMatrix.cpp.

References _cols, _m, _rows, tarch::la::col(), tarch::la::equals(), 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 109 of file DynamicMatrix.h.

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

Here is the call graph for this function:

◆ removeColumn()

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

Definition at line 389 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 533 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 458 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 177 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 35 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 433 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 412 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 246 of file DynamicMatrix.cpp.

Field Documentation

◆ _cols

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

Definition at line 22 of file DynamicMatrix.h.

Referenced by DynamicMatrix(), DynamicMatrix(), operator==(), 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==(), operator==(), and serialise().


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