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)
 
DynamicMatrix & operator= (const DynamicMatrix &)=delete
 
DynamicMatrix & operator= (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 * data ()
 
const double * data () const
 
double & operator() (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.

◆ ~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.

◆ DynamicMatrix() [2/6]

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

◆ DynamicMatrix() [3/6]

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

◆ DynamicMatrix() [4/6]

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

◆ 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.

◆ DynamicMatrix() [6/6]

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

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.

◆ 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.

◆ cols()

int tarch::la::DynamicMatrix::cols ( ) const

◆ data() [1/2]

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

Definition at line 130 of file DynamicMatrix.h.

References _m.

Referenced by peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__generate_dastgen_input_file(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_file_name(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_full_qualified_file_name(), exaparty.api.particle.Particle.Particle::__init__(), exaparty.api.particle.Particle.Particle::_add_dependency_checks(), exaparty.api.particle.Particle.Particle::_dependency_checks_modify_steps(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_enum_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_double_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_integer_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_string_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_user_defined_attributes(), peano4.api.datamodel.PatchToDoubleArray.PatchToDoubleArray::_get_dictionary_for_output(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::construct_output(), peano4.api.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::construct_output(), peano4.api.datamodel.PatchToDoubleArray.PatchToDoubleArray::construct_output(), peano4.api.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::construct_output(), peano4.api.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::construct_output(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_header_file_include(), peano4.api.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::get_header_file_include(), peano4.api.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_header_file_include(), peano4.api.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_header_file_include(), peano4.api.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_header_file_include(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_stack_container(), peano4.api.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_stack_container(), peano4.api.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_stack_container(), peano4.api.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_stack_container(), peano4.api.datamodel.DaStGen2.DaStGen2::hosts_smart_pointer_attribute(), exaparty.api.particle.Particle.Particle::readme_descriptor(), exaparty.api.particle.SPHLeapfrogFixedSearchRadius.SPHLeapfrogFixedSearchRadius::set_parameters(), exaparty.api.particle.SPHParticle.SPHParticle::set_parameters(), and exaparty.api.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.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__generate_dastgen_input_file(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_file_name(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_full_qualified_file_name(), exaparty.api.particle.Particle.Particle::__init__(), exaparty.api.particle.Particle.Particle::_add_dependency_checks(), exaparty.api.particle.Particle.Particle::_dependency_checks_modify_steps(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_enum_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_double_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_integer_array_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_string_attributes(), exaparty.api.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_user_defined_attributes(), peano4.api.datamodel.PatchToDoubleArray.PatchToDoubleArray::_get_dictionary_for_output(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::construct_output(), peano4.api.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::construct_output(), peano4.api.datamodel.PatchToDoubleArray.PatchToDoubleArray::construct_output(), peano4.api.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::construct_output(), peano4.api.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::construct_output(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_header_file_include(), peano4.api.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::get_header_file_include(), peano4.api.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_header_file_include(), peano4.api.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_header_file_include(), peano4.api.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_header_file_include(), peano4.api.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_stack_container(), peano4.api.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_stack_container(), peano4.api.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_stack_container(), peano4.api.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_stack_container(), peano4.api.datamodel.DaStGen2.DaStGen2::hosts_smart_pointer_attribute(), exaparty.api.particle.Particle.Particle::readme_descriptor(), exaparty.api.particle.SPHLeapfrogFixedSearchRadius.SPHLeapfrogFixedSearchRadius::set_parameters(), exaparty.api.particle.SPHParticle.SPHParticle::set_parameters(), and exaparty.api.particle.tests.testLeapfrogFixedTimeStepSize.testLeapfrogFixedTimeStepSize::set_parameters().

Here is the caller graph for this function:

◆ id()

◆ 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.

◆ insertEmptyRows()

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

◆ multiply()

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

◆ multiplyBySmallMatrix()

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

◆ operator()() [1/2]

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

◆ operator()() [2/2]

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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;

   

◆ operator==() [1/2]

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

◆ 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)

◆ replicateCols()

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

◆ 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.

◆ rows()

int tarch::la::DynamicMatrix::rows ( ) const

◆ scale()

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

Scale all entries.

◆ 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 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 
)

◆ shiftRowsDown()

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

Shift the rows to the right.

◆ toString()

std::string tarch::la::DynamicMatrix::toString ( bool  addLineBreaks = false) const

◆ vectorToString()

static 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.

Field Documentation

◆ _cols

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

Definition at line 22 of file DynamicMatrix.h.

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

◆ _m

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

Definition at line 24 of file DynamicMatrix.h.

Referenced by data(), data(), and operator==().

◆ _rows

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

Definition at line 23 of file DynamicMatrix.h.

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


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