Peano 4
Loading...
Searching...
No Matches
DynamicMatrix.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include "tarch/Assertions.h"
6#include "ScalarOperations.h"
7
8#include <string>
9
10namespace tarch {
11 namespace la {
12 class DynamicMatrix;
13 }
14}
15
21 private:
22 int _cols;
23 int _rows;
24 double* _m;
25
26 static inline int serialise( int row, int col, [[maybe_unused]] int Rows, int Cols ) {
27 return col + row * Cols;
28 }
29
30 int inline serialise( int row, int col ) const {
31 return serialise( row, col, _rows, _cols );
32 }
33
34 public:
38 DynamicMatrix(int rows, int cols);
39
46
47 DynamicMatrix( int rows, int cols, std::initializer_list< std::initializer_list<double> > values );
48
51
57 DynamicMatrix(const DynamicMatrix& lhs, const DynamicMatrix& rhs, bool innerProduct);
58
60
79 DynamicMatrix& operator=( std::initializer_list< std::initializer_list<double> > values );
80/*
81 template <int Cols>
82 DynamicMatrix& operator=( double values[][Cols] ) {
83 assertionEquals(Cols,_cols);
84 for (int col=0; col<_cols; col++)
85 for (int row=0; row<_rows; row++) {
86 _m[ serialise(row,col) ] = values[row][col];
87 }
88 return *this;
89 }
90*/
91
92 template <int Cols>
93 bool operator==(double values[][Cols]) const {
94 bool result = Cols==_cols;
95 for (int col=0; col<_cols; col++)
96 for (int row=0; row<_rows; row++) {
97 result &= tarch::la::equals( _m[ serialise(row,col) ], values[row][col]);
98 }
99 return result;
100 }
101
102 bool operator==(const DynamicMatrix& matrix) const;
103
104 std::string toString(bool addLineBreaks=false) const;
108 static std::string vectorToString( double* values, int entries, bool addLineBreaks=false );
109
110 double& operator()(int row, int col);
111 double operator()(int row, int col) const;
112
113 void multiply( double* result, double* x );
114
135 double* __restrict__ result,
136 const double* __restrict__ x,
137 int batchCount, int resultSize, int firstRow
138 );
139
144 double* __restrict__ result,
145 const double* __restrict__ x,
146 int batchCount
147 );
148
160 void replicateRows( int blockSize, int numberOfReplications, int shiftAfterEveryReplication, bool extendColumnsToAccommodateShifts );
161 void replicateCols( int blockSize, int numberOfReplications, int shiftAfterEveryReplication, bool extendColumnsToAccommodateShifts );
162
174 void insertEmptyColumns( int number, int where, int repeatEveryKColumns=0 );
175 void insertEmptyRows( int number, int where, int repeatEveryKColumns=0 );
176
180 void shiftRowsDown(int shift, bool wrap=false);
181 void shiftColumnsRight(int shift, bool wrap=false);
182
183 void removeColumn( int number );
184
188 void scale(double value);
189
193 static tarch::la::DynamicMatrix id( int rows );
194
195 int rows() const;
196 int cols() const;
197};
198
203
205
206//void multiply( double* result, double* x );
And from this we can write down f$ nabla phi_i nabla phi_i dx but since we are constructing matrix let s investigate the f$ our matrix elements will nabla phi_i dx f By this will be a sparse as these basis functions are chosen to not overlap with each other almost everywhere In other they have only local support We can read off the right hand side values
And from this we can write down f$ nabla phi_i nabla phi_i dx but since we are constructing matrix let s investigate the f$ our matrix elements will nabla phi_i dx f By this will be a sparse matrix
tarch::la::DynamicMatrix operator*(const tarch::la::DynamicMatrix &A, const tarch::la::DynamicMatrix &B)
tarch::la::DynamicMatrix kroneckerProduct(const tarch::la::DynamicMatrix &lhs, const tarch::la::DynamicMatrix &rhs)
Wrapper around static routine, so I don't have to use full-qualified name.
My standard matrix is a matrix where the size is fixed at compile time.
double & operator()(int row, int col)
~DynamicMatrix()
Free the array on the heap.
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 insertEmptyRows(int number, int where, int repeatEveryKColumns=0)
static std::string vectorToString(double *values, int entries, bool addLineBreaks=false)
I often need this in combination with the toString() operation above.
void removeColumn(int number)
void shiftColumnsRight(int shift, bool wrap=false)
DynamicMatrix & operator=(const DynamicMatrix &)=delete
bool operator==(double values[][Cols]) const
void shiftRowsDown(int shift, bool wrap=false)
Shift the rows to the right.
void insertEmptyColumns(int number, int where, int repeatEveryKColumns=0)
Insert zero columns.
void replicateRows(int blockSize, int numberOfReplications, int shiftAfterEveryReplication, bool extendColumnsToAccommodateShifts)
Split the matrix into blocks of rows of size blockSize.
DynamicMatrix(int rows, int cols)
Create empty matrix.
void replicateCols(int blockSize, int numberOfReplications, int shiftAfterEveryReplication, bool extendColumnsToAccommodateShifts)
int serialise(int row, int col) const
std::string toString(bool addLineBreaks=false) const
static tarch::la::DynamicMatrix id(int rows)
Create (square) identify matrix with rows rows and column.
static int serialise(int row, int col, int Rows, int Cols)
void scale(double value)
Scale all entries.
Vector< Rows, Scalar > col(const Matrix< Rows, Cols, Scalar > &matrix, int whichColumn)
Extract row from matrix.
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.
Vector< Cols, Scalar > row(const Matrix< Rows, Cols, Scalar > &matrix, int whichRow)
Extract row from matrix.
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:17