![]() |
Peano
|
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 |
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.
Create empty matrix.
Definition at line 117 of file DynamicMatrix.cpp.
References _m, cols(), tarch::Heap, and rows().
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.
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().
tarch::la::DynamicMatrix::DynamicMatrix | ( | const DynamicMatrix & | rhs | ) |
Definition at line 73 of file DynamicMatrix.cpp.
References _cols, _m, _rows, and tarch::Heap.
tarch::la::DynamicMatrix::DynamicMatrix | ( | DynamicMatrix && | rhs | ) |
Definition at line 84 of file DynamicMatrix.cpp.
tarch::la::DynamicMatrix::DynamicMatrix | ( | const DynamicMatrix & | lhs, |
const DynamicMatrix & | rhs, | ||
bool | innerProduct ) |
innerProduct | If 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().
Definition at line 93 of file DynamicMatrix.cpp.
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.
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.
batchSize | Number of elements within x/result to which the matrix has to be applied in one rush. |
resultSize | Number of entries in vector result. Please note that this number will be multiplied with batchSize, i.e. it is the entries per batch entry. |
firstRow | First 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().
int tarch::la::DynamicMatrix::cols | ( | ) | const |
Definition at line 456 of file DynamicMatrix.cpp.
Referenced by toolbox::blockstructured::internal::createInterpolationMatrixFrom1dTemplateByInsertingZeroColsAndRows(), toolbox::blockstructured::internal::createInterpolationMatrixFrom1dTemplateByLinearInterpolationAlongNormal(), DynamicMatrix(), DynamicMatrix(), toolbox::blockstructured::interpolateCellDataAssociatedToVolumesIntoOverlappingCell_secondOrder(), tarch::la::modifiedGramSchmidt(), multiplyBySmallMatrix(), operator*(), and tarch::la::transpose().
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().
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().
|
static |
Create (square) identify matrix with rows rows and column.
Definition at line 169 of file DynamicMatrix.cpp.
void tarch::la::DynamicMatrix::insertEmptyColumns | ( | int | number, |
int | where, | ||
int | repeatEveryKColumns = 0 ) |
Insert zero columns.
number | How many columns shall be inserted. Has to be at least one. |
where | Number of the first column to be inserted. Put in 0 to insert one to the left of the matrix. |
repeatEveryKColumns | If 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().
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().
Definition at line 184 of file DynamicMatrix.cpp.
References tarch::la::col(), and tarch::la::row().
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().
Definition at line 153 of file DynamicMatrix.cpp.
References assertion4, tarch::la::col(), and tarch::la::row().
Definition at line 161 of file DynamicMatrix.cpp.
References assertion, tarch::la::col(), and tarch::la::row().
|
delete |
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.
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().
Definition at line 109 of file DynamicMatrix.h.
References _cols, _m, _rows, tarch::la::col(), tarch::la::equals(), tarch::la::row(), and serialise().
Definition at line 389 of file DynamicMatrix.cpp.
References tarch::la::col(), tarch::freeMemory(), tarch::Heap, and tarch::la::row().
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().
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().
int tarch::la::DynamicMatrix::rows | ( | ) | const |
Definition at line 454 of file DynamicMatrix.cpp.
Referenced by toolbox::blockstructured::internal::createInterpolationMatrixFrom1dTemplateByInsertingZeroColsAndRows(), toolbox::blockstructured::internal::createInterpolationMatrixFrom1dTemplateByLinearInterpolationAlongNormal(), DynamicMatrix(), DynamicMatrix(), toolbox::blockstructured::interpolateCellDataAssociatedToVolumesIntoOverlappingCell_secondOrder(), tarch::la::modifiedGramSchmidt(), operator*(), and tarch::la::transpose().
Scale all entries.
Definition at line 177 of file DynamicMatrix.cpp.
References tarch::la::col(), and tarch::la::row().
Definition at line 35 of file DynamicMatrix.h.
References _cols, _rows, tarch::la::col(), tarch::la::row(), and serialise().
|
staticprivate |
Definition at line 26 of file DynamicMatrix.h.
References tarch::la::col(), and tarch::la::row().
Referenced by DynamicMatrix(), operator==(), and serialise().
Definition at line 433 of file DynamicMatrix.cpp.
References tarch::la::col(), tarch::freeMemory(), tarch::Heap, and tarch::la::row().
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().
std::string tarch::la::DynamicMatrix::toString | ( | bool | addLineBreaks = false | ) | const |
Definition at line 215 of file DynamicMatrix.cpp.
References tarch::la::col(), and tarch::la::row().
Referenced by toolbox::blockstructured::internal::createInterpolationMatrixFrom1dTemplateByInsertingZeroColsAndRows(), toolbox::blockstructured::internal::createInterpolationMatrixFrom1dTemplateByLinearInterpolationAlongNormal(), toolbox::blockstructured::internal::createLinearInterpolationMatrix(), and toolbox::blockstructured::internal::createPiecewiseConstantInterpolationMatrix().
|
static |
I often need this in combination with the toString() operation above.
Definition at line 246 of file DynamicMatrix.cpp.
|
private |
Definition at line 22 of file DynamicMatrix.h.
Referenced by DynamicMatrix(), DynamicMatrix(), operator==(), operator==(), and serialise().
|
private |
Definition at line 24 of file DynamicMatrix.h.
Referenced by data(), data(), DynamicMatrix(), DynamicMatrix(), DynamicMatrix(), DynamicMatrix(), operator==(), and operator==().
|
private |
Definition at line 23 of file DynamicMatrix.h.
Referenced by DynamicMatrix(), DynamicMatrix(), operator==(), operator==(), and serialise().