Template Numerical Library version\ main:8b8c8226
|
Implementation of sparse multidiagonal matrix. More...
#include <TNL/Matrices/MultidiagonalMatrix.h>
Public Types | |
using | BaseType = Matrix< Real, Device, Index, RealAllocator > |
using | ConstRowView = typename ViewType::ConstRowView |
Type for accessing constant matrix rows. | |
using | ConstViewType = MultidiagonalMatrixView< std::add_const_t< Real >, Device, Index, Organization > |
Matrix view type for constant instances. More... | |
using | DeviceType = Device |
The device where the matrix is allocated. | |
using | DiagonalsOffsetsType = Containers::Vector< Index, Device, Index, IndexAllocator > |
using | DiagonalsOffsetsView = typename DiagonalsOffsetsType::ViewType |
using | HostDiagonalsOffsetsType = Containers::Vector< Index, Devices::Host, Index > |
using | HostDiagonalsOffsetsView = typename HostDiagonalsOffsetsType::ViewType |
using | IndexAllocatorType = IndexAllocator |
The allocator for matrix elements offsets from the diagonal. | |
using | IndexerType = details::MultidiagonalMatrixIndexer< Index, Organization==Algorithms::Segments::RowMajorOrder > |
using | IndexType = Index |
The type used for matrix elements indexing. | |
using | RealAllocatorType = RealAllocator |
The allocator for matrix elements values. | |
using | RealType = Real |
The type of matrix elements. | |
using | RowView = typename ViewType::RowView |
Type for accessing matrix rows. | |
template<typename _Real = Real, typename _Device = Device, typename _Index = Index, ElementsOrganization _Organization = Organization, typename _RealAllocator = typename Allocators::Default< _Device >::template Allocator< _Real >, typename _IndexAllocator = typename Allocators::Default< _Device >::template Allocator< _Index >> | |
using | Self = MultidiagonalMatrix< _Real, _Device, _Index, _Organization, _RealAllocator, _IndexAllocator > |
Helper type for getting self type or its modifications. | |
using | ValuesType = typename BaseType::ValuesType |
using | ValuesView = typename ValuesType::ViewType |
using | ViewType = MultidiagonalMatrixView< Real, Device, Index, Organization > |
Type of related matrix view. More... | |
![]() | |
using | ConstRowsCapacitiesView = typename RowsCapacitiesView::ConstViewType |
using | ConstValuesType = Containers::Vector< std::add_const_t< Real >, Device, Index, RealAllocator > |
Type of constant vector holding values of matrix elements. | |
using | ConstValuesView = typename ViewType::ConstValuesView |
Type of constant vector view holding values of matrix elements. | |
using | ConstViewType = typename MatrixView< Real, Device, Index >::ConstViewType |
Type of base matrix view for constant instances. More... | |
using | DeviceType = Device |
The device where the matrix is allocated. | |
using | IndexType = Index |
The type used for matrix elements indexing. | |
using | RealAllocatorType = RealAllocator |
using | RealType = Real |
The type of matrix elements. | |
using | RowsCapacitiesType = Containers::Vector< Index, Device, Index > |
using | RowsCapacitiesView = Containers::VectorView< Index, Device, Index > |
using | ValuesType = Containers::Vector< Real, Device, Index, RealAllocator > |
Type of vector holding values of matrix elements. | |
using | ValuesView = typename ViewType::ValuesView |
Type of vector view holding values of matrix elements. | |
using | ViewType = MatrixView< Real, Device, Index > |
Type of base matrix view. More... | |
Public Member Functions | |
MultidiagonalMatrix () | |
Constructor with no parameters. | |
MultidiagonalMatrix (const MultidiagonalMatrix &matrix)=default | |
Copy constructor. More... | |
template<typename ListIndex , typename ListReal > | |
MultidiagonalMatrix (IndexType columns, std::initializer_list< ListIndex > diagonalsOffsets, const std::initializer_list< std::initializer_list< ListReal > > &data) | |
Constructor with matrix dimensions, diagonals offsets and matrix elements. More... | |
MultidiagonalMatrix (IndexType rows, IndexType columns) | |
Constructor with matrix dimensions. More... | |
template<typename Vector > | |
MultidiagonalMatrix (IndexType rows, IndexType columns, const Vector &diagonalsOffsets) | |
Constructor with matrix dimensions and matrix elements offsets. More... | |
template<typename ListIndex > | |
MultidiagonalMatrix (IndexType rows, IndexType columns, std::initializer_list< ListIndex > diagonalsOffsets) | |
Constructor with matrix dimensions and diagonals offsets. More... | |
MultidiagonalMatrix (MultidiagonalMatrix &&matrix) noexcept=default | |
Move constructor. More... | |
__cuda_callable__ void | addElement (IndexType row, IndexType column, const RealType &value, const RealType &thisElementMultiplicator=1.0) |
Add element at given row and column to given value. More... | |
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ > | |
void | addMatrix (const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_ > &matrix, const RealType &matrixMultiplicator=1.0, const RealType &thisMatrixMultiplicator=1.0) |
template<typename Function > | |
void | forAllElements (Function &function) |
This method calls forElements for all matrix rows. More... | |
template<typename Function > | |
void | forAllElements (Function &function) const |
This method calls forElements for all matrix rows (for constant instances). More... | |
template<typename Function > | |
void | forAllRows (Function &&function) |
Method for parallel iteration over all matrix rows. More... | |
template<typename Function > | |
void | forAllRows (Function &&function) const |
Method for parallel iteration over all matrix rows for constant instances. More... | |
template<typename Function > | |
void | forElements (IndexType begin, IndexType end, Function &function) |
Method for iteration over matrix rows for non-constant instances. More... | |
template<typename Function > | |
void | forElements (IndexType begin, IndexType end, Function &function) const |
Method for iteration over matrix rows for constant instances. More... | |
template<typename Function > | |
void | forRows (IndexType begin, IndexType end, Function &&function) |
Method for parallel iteration over matrix rows from interval [ begin, end). More... | |
template<typename Function > | |
void | forRows (IndexType begin, IndexType end, Function &&function) const |
Method for parallel iteration over matrix rows from interval [ begin, end) for constant instances. More... | |
template<typename Vector > | |
void | getCompressedRowLengths (Vector &rowLengths) const |
Computes number of non-zeros in each row. More... | |
ConstViewType | getConstView () const |
Returns a non-modifiable view of the multidiagonal matrix. More... | |
IndexType | getDiagonalsCount () const |
Returns number of diagonals. More... | |
const DiagonalsOffsetsType & | getDiagonalsOffsets () const |
Returns vector with diagonals offsets. More... | |
__cuda_callable__ RealType | getElement (IndexType row, IndexType column) const |
Returns value of matrix element at position given by its row and column index. More... | |
IndexerType & | getIndexer () |
This method returns matrix elements indexer used by this matrix. More... | |
const IndexerType & | getIndexer () const |
This method returns matrix elements indexer used by this matrix. More... | |
IndexType | getNonzeroElementsCount () const override |
Returns number of non-zero matrix elements. More... | |
__cuda_callable__ IndexType | getPaddingIndex () const |
Returns padding index denoting padding zero elements. More... | |
__cuda_callable__ RowView | getRow (IndexType rowIdx) |
Non-constant getter of simple structure for accessing given matrix row. More... | |
__cuda_callable__ ConstRowView | getRow (IndexType rowIdx) const |
Constant getter of simple structure for accessing given matrix row. More... | |
template<typename Vector > | |
void | getRowCapacities (Vector &rowCapacities) const |
Compute capacities of all rows. More... | |
IndexType | getRowLength (IndexType row) const |
std::string | getSerializationTypeVirtual () const override |
Returns string with serialization type. More... | |
template<typename Real2 , typename Index2 > | |
void | getTransposition (const MultidiagonalMatrix< Real2, Device, Index2 > &matrix, const RealType &matrixMultiplicator=1.0) |
ViewType | getView () |
Returns a modifiable view of the multidiagonal matrix. More... | |
void | load (const String &fileName) |
Method for loading the matrix from the file with given filename. More... | |
void | load (File &file) override |
Method for loading the matrix from a file. More... | |
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ , typename IndexAllocator_ > | |
bool | operator!= (const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ > &matrix) const |
Comparison operator with another multidiagonal matrix. More... | |
MultidiagonalMatrix & | operator= (const MultidiagonalMatrix &matrix) |
Assignment of exactly the same matrix type. More... | |
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ , typename IndexAllocator_ > | |
MultidiagonalMatrix & | operator= (const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ > &matrix) |
Assignment of another multidiagonal matrix. More... | |
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ , typename IndexAllocator_ > | |
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator > & | operator= (const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ > &matrix) |
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ , typename IndexAllocator_ > | |
bool | operator== (const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ > &matrix) const |
Comparison operator with another multidiagonal matrix. More... | |
void | print (std::ostream &str) const override |
Method for printing the matrix to output stream. More... | |
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal > | |
void | reduceAllRows (Fetch &fetch, Reduce &reduce, Keep &keep, const FetchReal &identity) |
Method for performing general reduction on all matrix rows. More... | |
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal > | |
void | reduceAllRows (Fetch &fetch, Reduce &reduce, Keep &keep, const FetchReal &identity) const |
Method for performing general reduction on all matrix rows for constant instances. More... | |
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal > | |
void | reduceRows (IndexType begin, IndexType end, Fetch &fetch, Reduce &reduce, Keep &keep, const FetchReal &identity) |
Method for performing general reduction on matrix rows. More... | |
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal > | |
void | reduceRows (IndexType begin, IndexType end, Fetch &fetch, Reduce &reduce, Keep &keep, const FetchReal &identity) const |
Method for performing general reduction on matrix rows for constant instances. More... | |
void | reset () |
Resets the matrix to zero dimensions. | |
void | save (const String &fileName) const |
Method for saving the matrix to the file with given filename. More... | |
void | save (File &file) const override |
Method for saving the matrix to a file. More... | |
template<typename Function > | |
void | sequentialForAllRows (Function &function) |
This method calls sequentialForRows for all matrix rows. More... | |
template<typename Function > | |
void | sequentialForAllRows (Function &function) const |
This method calls sequentialForRows for all matrix rows (for constant instances). More... | |
template<typename Function > | |
void | sequentialForRows (IndexType begin, IndexType end, Function &function) |
Method for sequential iteration over all matrix rows for non-constant instances. More... | |
template<typename Function > | |
void | sequentialForRows (IndexType begin, IndexType end, Function &function) const |
Method for sequential iteration over all matrix rows for constant instances. More... | |
template<typename Vector > | |
void | setDiagonalsOffsets (const Vector &diagonalsOffsets) |
Set the diagonals offsets by means of vector-like container. More... | |
template<typename ListIndex > | |
void | setDiagonalsOffsets (std::initializer_list< ListIndex > diagonalsOffsets) |
Set the diagonals offsets by means of initializer list. More... | |
template<typename Vector > | |
void | setDimensions (IndexType rows, IndexType columns, const Vector &diagonalsOffsets) |
Set matrix dimensions and diagonals offsets. More... | |
__cuda_callable__ void | setElement (IndexType row, IndexType column, const RealType &value) |
Sets element at given row and column to given value. More... | |
template<typename ListReal > | |
void | setElements (const std::initializer_list< std::initializer_list< ListReal > > &data) |
Set matrix elements from an initializer list. More... | |
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization_, typename RealAllocator_ , typename IndexAllocator_ > | |
void | setLike (const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ > &matrix) |
Setup the matrix dimensions and diagonals offsets based on another multidiagonal matrix. More... | |
template<typename RowCapacitiesVector > | |
void | setRowCapacities (const RowCapacitiesVector &rowCapacities) |
This method is for compatibility with SparseMatrix. More... | |
void | setValue (const RealType &value) |
Set all matrix elements to given value. More... | |
template<typename InVector , typename OutVector > | |
void | vectorProduct (const InVector &inVector, OutVector &outVector, RealType matrixMultiplicator=1.0, RealType outVectorMultiplicator=0.0, IndexType begin=0, IndexType end=0) const |
Computes product of matrix and vector. More... | |
![]() | |
Matrix (const RealAllocatorType &allocator=RealAllocatorType()) | |
Construct a new Matrix object possibly with user defined allocator of the matrix values. More... | |
Matrix (IndexType rows, IndexType columns, const RealAllocatorType &allocator=RealAllocatorType()) | |
Construct a new Matrix object with given dimensions and possibly user defined allocator of the matrix values. More... | |
IndexType | getAllocatedElementsCount () const |
Tells the number of allocated matrix elements. More... | |
__cuda_callable__ IndexType | getColumns () const |
Returns number of matrix columns. More... | |
virtual IndexType | getNonzeroElementsCount () const |
Computes a current number of nonzero matrix elements. More... | |
__cuda_callable__ IndexType | getRows () const |
Returns number of matrix rows. More... | |
ValuesType & | getValues () |
Returns a reference to a vector with the matrix elements values. More... | |
const ValuesType & | getValues () const |
Returns a constant reference to a vector with the matrix elements values. More... | |
void | load (File &file) override |
Method for loading the matrix from a file. More... | |
template<typename Matrix > | |
bool | operator!= (const Matrix &matrix) const |
Comparison operator with another arbitrary matrix type. More... | |
template<typename MatrixT > | |
bool | operator!= (const MatrixT &matrix) const |
template<typename Matrix > | |
bool | operator== (const Matrix &matrix) const |
Comparison operator with another arbitrary matrix type. More... | |
template<typename MatrixT > | |
bool | operator== (const MatrixT &matrix) const |
virtual void | print (std::ostream &str) const |
Method for printing the matrix to output stream. More... | |
void | reset () |
Reset the matrix. More... | |
void | save (File &file) const override |
Method for saving the matrix to a file. More... | |
virtual void | setDimensions (IndexType rows, IndexType columns) |
Method for setting or changing of the matrix dimensions. More... | |
template<typename Matrix_ > | |
void | setLike (const Matrix_ &matrix) |
Set the matrix dimensions to be equal to those of the input matrix. More... | |
![]() | |
virtual | ~Object ()=default |
Destructor. More... | |
virtual std::string | getSerializationTypeVirtual () const |
void | load (const String &fileName) |
Method for restoring the object from a file. More... | |
virtual void | load (File &file) |
Method for restoring the object from a file. More... | |
void | save (const String &fileName) const |
Method for saving the object to a file as a binary data. More... | |
virtual void | save (File &file) const |
Method for saving the object to a file as a binary data. More... | |
Static Public Member Functions | |
static constexpr ElementsOrganization | getOrganization () |
Elements organization getter. | |
static std::string | getSerializationType () |
Returns string with serialization type. More... | |
static constexpr bool | isSymmetric () |
This is only for compatibility with sparse matrices. More... | |
![]() | |
static std::string | getSerializationType () |
Static serialization type getter. More... | |
Protected Attributes | |
DiagonalsOffsetsType | diagonalsOffsets |
HostDiagonalsOffsetsType | hostDiagonalsOffsets |
IndexerType | indexer |
ViewType | view |
![]() | |
IndexType | columns |
IndexType | rows |
ValuesType | values |
Array containing the allocated matrix elements. | |
Implementation of sparse multidiagonal matrix.
Use this matrix type for storing of matrices where the offsets of non-zero elements from the diagonal are the same in each row. Typically such matrices arise from discretization of partial differential equations on regular numerical grids. This is one example (dots represent zero matrix elements):
\[ \left( \begin{array}{ccccccc} 4 & -1 & . & -1 & . & . \\ -1 & 4 & -1 & . & -1 & . \\ . & -1 & 4 & -1 & . & -1 \\ -1 & . & -1 & 4 & -1 & . \\ . & -1 & . & -1 & 4 & -1 \\ . & . & -1 & . & -1 & 4 \end{array} \right) \]
In this matrix, the column indexes in each row \(i\) can be expressed as \(\{i-3, i-1, i, i+1, i+3\}\) (where the resulting index is non-negative and smaller than the number of matrix columns). Therefore the diagonals offsets are \(\{-3,-1,0,1,3\}\). Advantage is that we do not store the column indexes explicitly as it is in SparseMatrix. This can reduce significantly the memory requirements which also means better performance. See the following table for the storage requirements comparison between TNL::Matrices::MultidiagonalMatrix and TNL::Matrices::SparseMatrix.
Real | Index | SparseMatrix | MultidiagonalMatrix | Ratio |
---|---|---|---|---|
float | 32-bit int | 8 bytes per element | 4 bytes per element | 50% |
double | 32-bit int | 12 bytes per element | 8 bytes per element | 75% |
float | 64-bit int | 12 bytes per element | 4 bytes per element | 30% |
double | 64-bit int | 16 bytes per element | 8 bytes per element | 50% |
Real | is a type of matrix elements. |
Device | is a device where the matrix is allocated. |
Index | is a type for indexing of the matrix elements. |
Organization | tells the ordering of matrix elements. It is either RowMajorOrder or ColumnMajorOrder. |
RealAllocator | is allocator for the matrix elements. |
IndexAllocator | is allocator for the matrix elements offsets. |
using TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::ConstViewType = MultidiagonalMatrixView< std::add_const_t< Real >, Device, Index, Organization > |
Matrix view type for constant instances.
using TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::ViewType = MultidiagonalMatrixView< Real, Device, Index, Organization > |
Type of related matrix view.
TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::MultidiagonalMatrix | ( | IndexType | rows, |
IndexType | columns | ||
) |
Constructor with matrix dimensions.
rows | is number of matrix rows. |
columns | is number of matrix columns. |
TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::MultidiagonalMatrix | ( | IndexType | rows, |
IndexType | columns, | ||
const Vector & | diagonalsOffsets | ||
) |
Constructor with matrix dimensions and matrix elements offsets.
rows | is number of matrix rows. |
columns | is number of matrix columns. |
diagonalsOffsets | are offsets of subdiagonals from the main diagonal. |
TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::MultidiagonalMatrix | ( | IndexType | rows, |
IndexType | columns, | ||
std::initializer_list< ListIndex > | diagonalsOffsets | ||
) |
Constructor with matrix dimensions and diagonals offsets.
rows | is number of matrix rows. |
columns | is number of matrix columns. |
diagonalsOffsets | are offsets of sub-diagonals from the main diagonal. |
TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::MultidiagonalMatrix | ( | IndexType | columns, |
std::initializer_list< ListIndex > | diagonalsOffsets, | ||
const std::initializer_list< std::initializer_list< ListReal > > & | data | ||
) |
Constructor with matrix dimensions, diagonals offsets and matrix elements.
The number of matrix rows is deduced from the size of the initializer list data.
ListIndex | is type used in the initializer list defining matrix diagonals offsets. |
ListReal | is type used in the initializer list defining matrix elements values. |
columns | is number of matrix columns. |
diagonalsOffsets | are offsets of sub-diagonals from the main diagonal. |
data | is initializer list holding matrix elements. The size of the outer list defines the number of matrix rows. Each inner list defines values of each sub-diagonal and so its size should be lower or equal to the size of diagonalsOffsets. Values of sub-diagonals which do not fit to given row are omitted. |
|
default |
Copy constructor.
matrix | is an input matrix. |
|
defaultnoexcept |
Move constructor.
matrix | is an input matrix. |
__cuda_callable__ void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::addElement | ( | IndexType | row, |
IndexType | column, | ||
const RealType & | value, | ||
const RealType & | thisElementMultiplicator = 1.0 |
||
) |
Add element at given row and column to given value.
This method can be called from the host system (CPU) no matter where the matrix is allocated. If the matrix is allocated on GPU this method can be called even from device kernels. If the matrix is allocated in GPU device this method is called from CPU, it transfers values of each matrix element separately and so the performance is very low. For higher performance see. MultidiagonalMatrix::getRow or MultidiagonalMatrix::forElements and MultidiagonalMatrix::forAllElements. The call may fail if the matrix row capacity is exhausted.
row | is row index of the element. |
column | is columns index of the element. |
value | is the value the element will be set to. |
thisElementMultiplicator | is multiplicator the original matrix element value is multiplied by before addition of given value. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::forAllElements | ( | Function & | function | ) |
This method calls forElements for all matrix rows.
See MultidiagonalMatrix::forElements.
Function | is a type of lambda function that will operate on matrix elements. |
function | is an instance of the lambda function to be called in each row. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::forAllElements | ( | Function & | function | ) | const |
This method calls forElements for all matrix rows (for constant instances).
See MultidiagonalMatrix::forElements.
Function | is a type of lambda function that will operate on matrix elements. |
function | is an instance of the lambda function to be called in each row. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::forAllRows | ( | Function && | function | ) |
Method for parallel iteration over all matrix rows.
In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method MultidiagonalMatrix::forAllElements where more than one thread can be mapped to each row.
Function | is type of the lambda function. |
function | is an instance of the lambda function to be called for each row. |
RowView represents matrix row - see TNL::Matrices::MultidiagonalMatrix::RowView.
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::forAllRows | ( | Function && | function | ) | const |
Method for parallel iteration over all matrix rows for constant instances.
In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method MultidiagonalMatrix::forAllElements where more than one thread can be mapped to each row.
Function | is type of the lambda function. |
function | is an instance of the lambda function to be called for each row. |
RowView represents matrix row - see TNL::Matrices::MultidiagonalMatrix::RowView.
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::forElements | ( | IndexType | begin, |
IndexType | end, | ||
Function & | function | ||
) |
Method for iteration over matrix rows for non-constant instances.
Function | is type of lambda function that will operate on matrix elements. It is should have form like |
where
rowIdx is an index of the matrix row.
localIdx parameter is a rank of the non-zero element in given row. It is also, in fact, index of the matrix subdiagonal.
columnIdx is a column index of the matrix element.
value is a reference to the matrix element value. It can be used even for changing the matrix element value.
begin | defines beginning of the range [begin,end) of rows to be processed. |
end | defines ending of the range [begin,end) of rows to be processed. |
function | is an instance of the lambda function to be called in each row. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::forElements | ( | IndexType | begin, |
IndexType | end, | ||
Function & | function | ||
) | const |
Method for iteration over matrix rows for constant instances.
Function | is type of lambda function that will operate on matrix elements. It is should have form like |
where
rowIdx is an index of the matrix row.
localIdx parameter is a rank of the non-zero element in given row. It is also, in fact, index of the matrix subdiagonal.
columnIdx is a column index of the matrix element.
value is the matrix element value.
begin | defines beginning of the range [begin,end) of rows to be processed. |
end | defines ending of the range [begin,end) of rows to be processed. |
function | is an instance of the lambda function to be called in each row. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::forRows | ( | IndexType | begin, |
IndexType | end, | ||
Function && | function | ||
) |
Method for parallel iteration over matrix rows from interval [ begin, end).
In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method MultidiagonalMatrix::forElements where more than one thread can be mapped to each row.
Function | is type of the lambda function. |
begin | defines beginning of the range [ begin,end ) of rows to be processed. |
end | defines ending of the range [ begin, end ) of rows to be processed. |
function | is an instance of the lambda function to be called for each row. |
RowView represents matrix row - see TNL::Matrices::MultidiagonalMatrix::RowView.
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::forRows | ( | IndexType | begin, |
IndexType | end, | ||
Function && | function | ||
) | const |
Method for parallel iteration over matrix rows from interval [ begin, end) for constant instances.
In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method MultidiagonalMatrix::forElements where more than one thread can be mapped to each row.
Function | is type of the lambda function. |
begin | defines beginning of the range [ begin,end ) of rows to be processed. |
end | defines ending of the range [ begin, end ) of rows to be processed. |
function | is an instance of the lambda function to be called for each row. |
RowView represents matrix row - see TNL::Matrices::MultidiagonalMatrix::RowView.
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getCompressedRowLengths | ( | Vector & | rowLengths | ) | const |
Computes number of non-zeros in each row.
rowLengths | is a vector into which the number of non-zeros in each row will be stored. |
auto TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getConstView |
Returns a non-modifiable view of the multidiagonal matrix.
Index TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getDiagonalsCount |
Returns number of diagonals.
auto TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getDiagonalsOffsets |
Returns vector with diagonals offsets.
__cuda_callable__ Real TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getElement | ( | IndexType | row, |
IndexType | column | ||
) | const |
Returns value of matrix element at position given by its row and column index.
This method can be called from the host system (CPU) no matter where the matrix is allocated. If the matrix is allocated on GPU this method can be called even from device kernels. If the matrix is allocated in GPU device this method is called from CPU, it transfers values of each matrix element separately and so the performance is very low. For higher performance see. MultidiagonalMatrix::getRow or MultidiagonalMatrix::forElements and MultidiagonalMatrix::forAllElements.
row | is a row index of the matrix element. |
column | i a column index of the matrix element. |
auto TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getIndexer |
This method returns matrix elements indexer used by this matrix.
auto TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getIndexer |
This method returns matrix elements indexer used by this matrix.
|
overridevirtual |
Returns number of non-zero matrix elements.
This method really counts the non-zero matrix elements and so it returns zero for matrix having all allocated elements set to zero.
Reimplemented from TNL::Matrices::Matrix< Real, Device, Index, RealAllocator >.
__cuda_callable__ Index TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getPaddingIndex |
Returns padding index denoting padding zero elements.
These elements are used for efficient data alignment in memory.
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getRow | ( | IndexType | rowIdx | ) |
Non-constant getter of simple structure for accessing given matrix row.
rowIdx | is matrix row index. |
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getRow | ( | IndexType | rowIdx | ) | const |
Constant getter of simple structure for accessing given matrix row.
rowIdx | is matrix row index. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getRowCapacities | ( | Vector & | rowCapacities | ) | const |
Compute capacities of all rows.
The row capacities are not stored explicitly and must be computed.
rowCapacities | is a vector where the row capacities will be stored. |
|
static |
Returns string with serialization type.
The string has a form Matrices::MultidiagonalMatrix< RealType, [any_device], IndexType, ElementsOrganization, [any_allocator], [any_allocator] >
.
|
overridevirtual |
Returns string with serialization type.
See MultidiagonalMatrix::getSerializationType.
Reimplemented from TNL::Object.
auto TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::getView |
Returns a modifiable view of the multidiagonal matrix.
|
inlinestaticconstexpr |
This is only for compatibility with sparse matrices.
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::load | ( | const String & | fileName | ) |
Method for loading the matrix from the file with given filename.
fileName | is name of the file. |
|
overridevirtual |
Method for loading the matrix from a file.
file | is the input file. |
Reimplemented from TNL::Matrices::Matrix< Real, Device, Index, RealAllocator >.
bool TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::operator!= | ( | const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ > & | matrix | ) | const |
Comparison operator with another multidiagonal matrix.
Real_ | is Real type of the source matrix. |
Device_ | is Device type of the source matrix. |
Index_ | is Index type of the source matrix. |
Organization_ | is Organization of the source matrix. |
RealAllocator_ | is RealAllocator of the source matrix. |
IndexAllocator_ | is IndexAllocator of the source matrix. |
matrix | is the source matrix. |
MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator > & TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::operator= | ( | const MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator > & | matrix | ) |
Assignment of exactly the same matrix type.
matrix | is input matrix for the assignment. |
MultidiagonalMatrix & TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::operator= | ( | const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ > & | matrix | ) |
Assignment of another multidiagonal matrix.
matrix | is input matrix for the assignment. |
bool TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::operator== | ( | const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ > & | matrix | ) | const |
Comparison operator with another multidiagonal matrix.
Real_ | is Real type of the source matrix. |
Device_ | is Device type of the source matrix. |
Index_ | is Index type of the source matrix. |
Organization_ | is Organization of the source matrix. |
RealAllocator_ | is RealAllocator of the source matrix. |
IndexAllocator_ | is IndexAllocator of the source matrix. |
|
overridevirtual |
Method for printing the matrix to output stream.
str | is the output stream. |
Reimplemented from TNL::Matrices::Matrix< Real, Device, Index, RealAllocator >.
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::reduceAllRows | ( | Fetch & | fetch, |
Reduce & | reduce, | ||
Keep & | keep, | ||
const FetchReal & | identity | ||
) |
Method for performing general reduction on all matrix rows.
Fetch | is a type of lambda function for data fetch declared as |
The return type of this lambda can be any non void.
Reduce | is a type of lambda function for reduction declared as |
Keep | is a type of lambda function for storing results of reduction in each row. It is declared as |
FetchValue | is type returned by the Fetch lambda function. |
fetch | is an instance of lambda function for data fetch. |
reduce | is an instance of lambda function for reduction. |
keep | in an instance of lambda function for storing results. |
identity | is the identity element for the reduction operation, i.e. element which does not change the result of the reduction. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::reduceAllRows | ( | Fetch & | fetch, |
Reduce & | reduce, | ||
Keep & | keep, | ||
const FetchReal & | identity | ||
) | const |
Method for performing general reduction on all matrix rows for constant instances.
Fetch | is a type of lambda function for data fetch declared as |
The return type of this lambda can be any non void.
Reduce | is a type of lambda function for reduction declared as |
Keep | is a type of lambda function for storing results of reduction in each row. It is declared as |
FetchValue | is type returned by the Fetch lambda function. |
fetch | is an instance of lambda function for data fetch. |
reduce | is an instance of lambda function for reduction. |
keep | in an instance of lambda function for storing results. |
identity | is the identity element for the reduction operation, i.e. element which does not change the result of the reduction. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::reduceRows | ( | IndexType | begin, |
IndexType | end, | ||
Fetch & | fetch, | ||
Reduce & | reduce, | ||
Keep & | keep, | ||
const FetchReal & | identity | ||
) |
Method for performing general reduction on matrix rows.
Fetch | is a type of lambda function for data fetch declared as |
The return type of this lambda can be any non void.
Reduce | is a type of lambda function for reduction declared as |
Keep | is a type of lambda function for storing results of reduction in each row. It is declared as |
FetchValue | is type returned by the Fetch lambda function. |
begin | defines beginning of the range [begin,end) of rows to be processed. |
end | defines ending of the range [begin,end) of rows to be processed. |
fetch | is an instance of lambda function for data fetch. |
reduce | is an instance of lambda function for reduction. |
keep | in an instance of lambda function for storing results. |
identity | is the identity element for the reduction operation, i.e. element which does not change the result of the reduction. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::reduceRows | ( | IndexType | begin, |
IndexType | end, | ||
Fetch & | fetch, | ||
Reduce & | reduce, | ||
Keep & | keep, | ||
const FetchReal & | identity | ||
) | const |
Method for performing general reduction on matrix rows for constant instances.
Fetch | is a type of lambda function for data fetch declared as |
The return type of this lambda can be any non void.
Reduce | is a type of lambda function for reduction declared as |
Keep | is a type of lambda function for storing results of reduction in each row. It is declared as |
FetchValue | is type returned by the Fetch lambda function. |
begin | defines beginning of the range [begin,end) of rows to be processed. |
end | defines ending of the range [begin,end) of rows to be processed. |
fetch | is an instance of lambda function for data fetch. |
reduce | is an instance of lambda function for reduction. |
keep | in an instance of lambda function for storing results. |
identity | is the identity element for the reduction operation, i.e. element which does not change the result of the reduction. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::save | ( | const String & | fileName | ) | const |
Method for saving the matrix to the file with given filename.
fileName | is name of the file. |
|
overridevirtual |
Method for saving the matrix to a file.
file | is the output file. |
Reimplemented from TNL::Matrices::Matrix< Real, Device, Index, RealAllocator >.
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::sequentialForAllRows | ( | Function & | function | ) |
This method calls sequentialForRows for all matrix rows.
See MultidiagonalMatrix::sequentialForAllRows.
Function | is a type of lambda function that will operate on matrix elements. |
function | is an instance of the lambda function to be called in each row. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::sequentialForAllRows | ( | Function & | function | ) | const |
This method calls sequentialForRows for all matrix rows (for constant instances).
See MultidiagonalMatrix::sequentialForRows.
Function | is a type of lambda function that will operate on matrix elements. |
function | is an instance of the lambda function to be called in each row. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::sequentialForRows | ( | IndexType | begin, |
IndexType | end, | ||
Function & | function | ||
) |
Method for sequential iteration over all matrix rows for non-constant instances.
Function | is type of lambda function that will operate on matrix elements. It is should have form like |
The column index repeats twice only for compatibility with sparse matrices.
begin | defines beginning of the range [begin,end) of rows to be processed. |
end | defines ending of the range [begin,end) of rows to be processed. |
function | is an instance of the lambda function to be called in each row. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::sequentialForRows | ( | IndexType | begin, |
IndexType | end, | ||
Function & | function | ||
) | const |
Method for sequential iteration over all matrix rows for constant instances.
Function | is type of lambda function that will operate on matrix elements. It is should have form like |
The column index repeats twice only for compatibility with sparse matrices.
begin | defines beginning of the range [begin,end) of rows to be processed. |
end | defines ending of the range [begin,end) of rows to be processed. |
function | is an instance of the lambda function to be called in each row. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::setDiagonalsOffsets | ( | const Vector & | diagonalsOffsets | ) |
Set the diagonals offsets by means of vector-like container.
This method deletes current matrix elements.
Vector | is a type of vector-like container holding the subdiagonals offsets. |
diagonalsOffsets | is a vector-like container holding the subdiagonals offsets. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::setDiagonalsOffsets | ( | std::initializer_list< ListIndex > | diagonalsOffsets | ) |
Set the diagonals offsets by means of initializer list.
This method deletes current matrix elements.
ListIndex | is type of indexes used for the subdiagonals offsets definition. |
diagonalsOffsets | is a initializer list with subdiagonals offsets. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::setDimensions | ( | IndexType | rows, |
IndexType | columns, | ||
const Vector & | diagonalsOffsets | ||
) |
Set matrix dimensions and diagonals offsets.
Vector | is type of vector like container holding the diagonals offsets. |
rows | is number of matrix rows. |
columns | is number of matrix columns. |
diagonalsOffsets | is vector with diagonals offsets. |
__cuda_callable__ void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::setElement | ( | IndexType | row, |
IndexType | column, | ||
const RealType & | value | ||
) |
Sets element at given row and column to given value.
This method can be called from the host system (CPU) no matter where the matrix is allocated. If the matrix is allocated on GPU this method can be called even from device kernels. If the matrix is allocated in GPU device this method is called from CPU, it transfers values of each matrix element separately and so the performance is very low. For higher performance see. MultidiagonalMatrix::getRow or MultidiagonalMatrix::forElements and MultidiagonalMatrix::forAllElements. The call may fail if the matrix row capacity is exhausted.
row | is row index of the element. |
column | is columns index of the element. |
value | is the value the element will be set to. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::setElements | ( | const std::initializer_list< std::initializer_list< ListReal > > & | data | ) |
Set matrix elements from an initializer list.
ListReal | is data type of the initializer list. |
data | is initializer list holding matrix elements. The size of the outer list defines the number of matrix rows. Each inner list defines values of each sub-diagonal and so its size should be lower or equal to the size of diagonalsOffsets. Values of sub-diagonals which do not fit to given row are omitted. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::setLike | ( | const MultidiagonalMatrix< Real_, Device_, Index_, Organization_, RealAllocator_, IndexAllocator_ > & | matrix | ) |
Setup the matrix dimensions and diagonals offsets based on another multidiagonal matrix.
Real_ | is Real type of the source matrix. |
Device_ | is Device type of the source matrix. |
Index_ | is Index type of the source matrix. |
Organization_ | is Organization of the source matrix. |
RealAllocator_ | is RealAllocator of the source matrix. |
IndexAllocator_ | is IndexAllocator of the source matrix. |
matrix | is the source matrix. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::setRowCapacities | ( | const RowCapacitiesVector & | rowCapacities | ) |
This method is for compatibility with SparseMatrix.
It checks if the number of matrix diagonals is compatible with required number of non-zero matrix elements in each row. If not exception is thrown.
RowCapacitiesVector | is vector-like container type for holding required row capacities. |
rowCapacities | is vector-like container holding required row capacities. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::setValue | ( | const RealType & | value | ) |
Set all matrix elements to given value.
value | is the new value of all matrix elements. |
void TNL::Matrices::MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator >::vectorProduct | ( | const InVector & | inVector, |
OutVector & | outVector, | ||
RealType | matrixMultiplicator = 1.0 , |
||
RealType | outVectorMultiplicator = 0.0 , |
||
IndexType | begin = 0 , |
||
IndexType | end = 0 |
||
) | const |
Computes product of matrix and vector.
More precisely, it computes:
InVector | is type of input vector. It can be TNL::Containers::Vector, TNL::Containers::VectorView, TNL::Containers::Array, TNL::Containers::ArrayView, or similar container. |
OutVector | is type of output vector. It can be TNL::Containers::Vector, TNL::Containers::VectorView, TNL::Containers::Array, TNL::Containers::ArrayView, or similar container. |
inVector | is input vector. |
outVector | is output vector. |
matrixMultiplicator | is a factor by which the matrix is multiplied. It is one by default. |
outVectorMultiplicator | is a factor by which the outVector is multiplied before added to the result of matrix-vector product. It is zero by default. |
begin | is the beginning of the rows range for which the vector product is computed. It is zero by default. |
end | is the end of the rows range for which the vector product is computed. It is number if the matrix rows by default. |