Template Numerical Library version\ main:8b8c8226
|
Implementation of dense matrix, i.e. matrix storing explicitly all of its elements including zeros. More...
#include <TNL/Matrices/DenseMatrix.h>
Public Types | |
using | ConstRowView = typename ConstViewType::ConstRowView |
Type for accessing immutable matrix rows. | |
using | ConstViewType = typename DenseMatrixView< Real, Device, Index, Organization >::ConstViewType |
Matrix view type 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 |
The allocator for matrix elements. | |
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 = Algorithms::Segments::DefaultElementsOrganization< _Device >::getOrganization(), typename _RealAllocator = typename Allocators::Default< _Device >::template Allocator< _Real >> | |
using | Self = DenseMatrix< _Real, _Device, _Index, _Organization, _RealAllocator > |
Helper type for getting self type or its modifications. | |
using | ViewType = DenseMatrixView< 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 | |
DenseMatrix (const DenseMatrix &matrix)=default | |
Copy constructor. More... | |
DenseMatrix (const RealAllocatorType &allocator=RealAllocatorType()) | |
Constructor only with values allocator. More... | |
DenseMatrix (DenseMatrix &&matrix) noexcept=default | |
Move constructor. More... | |
DenseMatrix (IndexType rows, IndexType columns, const RealAllocatorType &allocator=RealAllocatorType()) | |
Constructor with matrix dimensions. More... | |
template<typename Value > | |
DenseMatrix (std::initializer_list< std::initializer_list< Value > > data, const RealAllocatorType &allocator=RealAllocatorType()) | |
Constructor with 2D initializer list. 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 Matrix > | |
void | addMatrix (const Matrix &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 all matrix rows for non-constant instances. More... | |
template<typename Function > | |
void | forElements (IndexType begin, IndexType end, Function &&function) const |
Method for iteration over all 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 RowLengthsVector > | |
void | getCompressedRowLengths (RowLengthsVector &rowLengths) const |
Computes number of non-zeros in each row. More... | |
ConstViewType | getConstView () const |
Returns a non-modifiable view of the dense matrix. More... | |
__cuda_callable__ Real | getElement (IndexType row, IndexType column) const |
Returns value of matrix element at position given by its row and column index. More... | |
template<typename Matrix1 , typename Matrix2 , int tileDim = 32> | |
void | getMatrixProduct (const Matrix1 &matrix1, const Matrix2 &matrix2, const RealType &matrixMultiplicator=1.0) |
IndexType | getNonzeroElementsCount () const override |
Returns number of non-zero matrix elements. More... | |
__cuda_callable__ RowView | getRow (const IndexType &rowIdx) |
Non-constant getter of simple structure for accessing given matrix row. More... | |
__cuda_callable__ ConstRowView | getRow (const 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... | |
std::string | getSerializationTypeVirtual () const override |
Returns string with serialization type. More... | |
template<typename Matrix , int tileDim = 32> | |
void | getTransposition (const Matrix &matrix, const RealType &matrixMultiplicator=1.0) |
ViewType | getView () |
Returns a modifiable view of the dense 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_ , typename RealAllocator_ > | |
bool | operator!= (const DenseMatrix< Real_, Device_, Index_, Organization, RealAllocator_ > &matrix) const |
Comparison operator with another dense matrix. More... | |
template<typename Real_ , typename Device_ , typename Index_ > | |
bool | operator!= (const DenseMatrixView< Real_, Device_, Index_, Organization > &matrix) const |
Comparison operator with another dense matrix view. More... | |
template<typename Matrix > | |
bool | operator!= (const Matrix &matrix) const |
Comparison operator with another arbitrary matrix type. More... | |
__cuda_callable__ Real & | operator() (IndexType row, IndexType column) |
Returns non-constant reference to element at row row and column column. More... | |
__cuda_callable__ const Real & | operator() (IndexType row, IndexType column) const |
Returns constant reference to element at row row and column column. More... | |
DenseMatrix & | operator= (const DenseMatrix &matrix) |
Assignment operator with exactly the same type of the dense matrix. More... | |
template<typename Real , typename Device , typename Index , ElementsOrganization Organization, typename RealAllocator > | |
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & | operator= (const DenseMatrix< Real, Device, Index, Organization, RealAllocator > &matrix) |
template<typename RHSReal , typename RHSDevice , typename RHSIndex , typename RHSRealAllocator > | |
DenseMatrix & | operator= (const DenseMatrix< RHSReal, RHSDevice, RHSIndex, Organization, RHSRealAllocator > &matrix) |
Assignment operator with the same organization. More... | |
template<typename RHSReal , typename RHSDevice , typename RHSIndex , typename RHSRealAllocator > | |
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & | operator= (const DenseMatrix< RHSReal, RHSDevice, RHSIndex, Organization, RHSRealAllocator > &matrix) |
template<typename RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization, typename RHSRealAllocator > | |
DenseMatrix & | operator= (const DenseMatrix< RHSReal, RHSDevice, RHSIndex, RHSOrganization, RHSRealAllocator > &matrix) |
Assignment operator with other dense matrices. More... | |
template<typename RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization, typename RHSRealAllocator > | |
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & | operator= (const DenseMatrix< RHSReal, RHSDevice, RHSIndex, RHSOrganization, RHSRealAllocator > &matrix) |
template<typename RHSReal , typename RHSDevice , typename RHSIndex > | |
DenseMatrix & | operator= (const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, Organization > &matrix) |
Assignment operator with matrix view having the same elements organization. More... | |
template<typename RHSReal , typename RHSDevice , typename RHSIndex > | |
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & | operator= (const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, Organization > &matrix) |
template<typename RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization> | |
DenseMatrix & | operator= (const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, RHSOrganization > &matrix) |
Assignment operator with other dense matrices. More... | |
template<typename RHSReal , typename RHSDevice , typename RHSIndex , ElementsOrganization RHSOrganization> | |
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & | operator= (const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, RHSOrganization > &matrix) |
template<typename RHSMatrix > | |
DenseMatrix & | operator= (const RHSMatrix &matrix) |
Assignment operator with other (sparse) types of matrices. More... | |
template<typename RHSMatrix > | |
DenseMatrix< Real, Device, Index, Organization, RealAllocator > & | operator= (const RHSMatrix &matrix) |
template<typename Real_ , typename Device_ , typename Index_ , typename RealAllocator_ > | |
bool | operator== (const DenseMatrix< Real_, Device_, Index_, Organization, RealAllocator_ > &matrix) const |
Comparison operator with another dense matrix. More... | |
template<typename Real_ , typename Device_ , typename Index_ > | |
bool | operator== (const DenseMatrixView< Real_, Device_, Index_, Organization > &matrix) const |
Comparison operator with another dense matrix view. More... | |
template<typename Matrix > | |
bool | operator== (const Matrix &matrix) const |
Comparison operator with another arbitrary matrix type. 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, const 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, const 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 FetchValue > | |
void | reduceRows (IndexType begin, IndexType end, Fetch &fetch, const Reduce &reduce, Keep &keep, const FetchValue &identity) |
Method for performing general reduction on matrix rows. More... | |
template<typename Fetch , typename Reduce , typename Keep , typename FetchValue > | |
void | reduceRows (IndexType begin, IndexType end, Fetch &fetch, const Reduce &reduce, Keep &keep, const FetchValue &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... | |
void | setDimensions (IndexType rows, IndexType columns) override |
Set number of rows and columns of this matrix. 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 Value > | |
void | setElements (std::initializer_list< std::initializer_list< Value > > data) |
This method recreates the dense matrix from 2D initializer list. More... | |
template<typename Matrix > | |
void | setLike (const Matrix &matrix) |
Set the number of matrix rows and columns by the given matrix. More... | |
template<typename Matrix_ > | |
void | setLike (const Matrix_ &matrix) |
template<typename RowCapacitiesVector > | |
void | setRowCapacities (const RowCapacitiesVector &rowCapacities) |
This method is only for the compatibility with the sparse matrices. More... | |
void | setValue (const RealType &v) |
Sets all matrix elements to value v. More... | |
template<typename InVector , typename OutVector > | |
void | vectorProduct (const InVector &inVector, OutVector &outVector, const RealType &matrixMultiplicator=1.0, const 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 () |
Matrix elements organization getter. More... | |
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 Types | |
using | BaseType = Matrix< Real, Device, Index, RealAllocator > |
using | SegmentsType = Algorithms::Segments::Ellpack< Device, Index, typename Allocators::Default< Device >::template Allocator< Index >, Organization, 1 > |
using | SegmentViewType = typename SegmentsType::SegmentViewType |
using | ValuesVectorType = typename BaseType::ValuesType |
using | ValuesViewType = typename ValuesVectorType::ViewType |
Protected Member Functions | |
__cuda_callable__ IndexType | getElementIndex (IndexType row, IndexType column) const |
Protected Attributes | |
SegmentsType | segments |
ViewType | view |
![]() | |
IndexType | columns |
IndexType | rows |
ValuesType | values |
Array containing the allocated matrix elements. | |
Implementation of dense matrix, i.e. matrix storing explicitly all of its elements including zeros.
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. |
using TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::ConstViewType = typename DenseMatrixView< Real, Device, Index, Organization >::ConstViewType |
Matrix view type for constant instances.
See DenseMatrixView.
using TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::ViewType = DenseMatrixView< Real, Device, Index, Organization > |
Type of related matrix view.
See DenseMatrixView.
TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::DenseMatrix | ( | const RealAllocatorType & | allocator = RealAllocatorType() | ) |
Constructor only with values allocator.
allocator | is used for allocation of matrix elements values. |
|
default |
Copy constructor.
matrix | is the source matrix |
|
defaultnoexcept |
Move constructor.
matrix | is the source matrix |
TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::DenseMatrix | ( | IndexType | rows, |
IndexType | columns, | ||
const RealAllocatorType & | allocator = RealAllocatorType() |
||
) |
Constructor with matrix dimensions.
rows | is number of matrix rows. |
columns | is number of matrix columns. |
allocator | is used for allocation of matrix elements values. |
TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::DenseMatrix | ( | std::initializer_list< std::initializer_list< Value > > | data, |
const RealAllocatorType & | allocator = RealAllocatorType() |
||
) |
Constructor with 2D initializer list.
The number of matrix rows is set to the outer list size and the number of matrix columns is set to maximum size of inner lists. Missing elements are filled in with zeros.
data | is a initializer list of initializer lists representing list of matrix rows. |
allocator | is used for allocation of matrix elements values. |
__cuda_callable__ void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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. DenseMatrix::getRow or DenseMatrix::forElements and DenseMatrix::forAllElements.
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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::forAllElements | ( | Function && | function | ) |
This method calls forElements for all matrix rows.
See DenseMatrix::forAllElements.
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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::forAllElements | ( | Function && | function | ) | const |
This method calls forElements for all matrix rows (for constant instances).
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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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 DenseMatrix::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::DenseMatrix::RowView.
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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 DenseMatrix::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::DenseMatrix::RowView.
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::forElements | ( | IndexType | begin, |
IndexType | end, | ||
Function && | function | ||
) |
Method for 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::forElements | ( | IndexType | begin, |
IndexType | end, | ||
Function && | function | ||
) | const |
Method for 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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 DenseMatrix::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::DenseMatrix::RowView.
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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 DenseMatrix::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::DenseMatrix::RowView.
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::getCompressedRowLengths | ( | RowLengthsVector & | 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::getConstView |
__cuda_callable__ Real TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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. DenseMatrix::getRow or DenseMatrix::forElements and DenseMatrix::forAllElements.
row | is a row index of the matrix element. |
column | i a column index of the matrix element. |
|
overridevirtual |
Returns number of non-zero matrix elements.
Reimplemented from TNL::Matrices::Matrix< Real, Device, Index, RealAllocator >.
|
inlinestaticconstexpr |
Matrix elements organization getter.
__cuda_callable__ auto TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::getRow | ( | const IndexType & | rowIdx | ) |
Non-constant getter of simple structure for accessing given matrix row.
rowIdx | is matrix row index. |
See DenseMatrixRowView.
__cuda_callable__ auto TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::getRow | ( | const IndexType & | rowIdx | ) | const |
Constant getter of simple structure for accessing given matrix row.
rowIdx | is matrix row index. |
See DenseMatrixRowView.
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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 `MatricesDenseMatrix< RealType, [any_device], IndexType, [any_allocator], true/false >`.
|
overridevirtual |
Returns string with serialization type.
See DenseMatrix::getSerializationType.
Reimplemented from TNL::Object.
auto TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::getView |
|
inlinestaticconstexpr |
This is only for compatibility with sparse matrices.
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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 file from which the matrix will be loaded. |
Reimplemented from TNL::Object.
bool TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator!= | ( | const DenseMatrix< Real_, Device_, Index_, Organization, RealAllocator_ > & | matrix | ) | const |
Comparison operator with another dense matrix.
matrix | is the right-hand side matrix. |
bool TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator!= | ( | const DenseMatrixView< Real_, Device_, Index_, Organization > & | matrix | ) | const |
Comparison operator with another dense matrix view.
matrix | is the right-hand side matrix view. |
bool TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator!= | ( | const Matrix & | matrix | ) | const |
Comparison operator with another arbitrary matrix type.
matrix | is the right-hand side matrix. |
__cuda_callable__ Real & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator() | ( | IndexType | row, |
IndexType | column | ||
) |
Returns non-constant reference to element at row row and column column.
Since this method returns reference to the element, it cannot be called across different address spaces. It means that it can be called only form CPU if the matrix is allocated on CPU or only from GPU kernels if the matrix is allocated on GPU.
row | is a row index of the element. |
column | is a columns index of the element. |
__cuda_callable__ const Real & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator() | ( | IndexType | row, |
IndexType | column | ||
) | const |
Returns constant reference to element at row row and column column.
Since this method returns reference to the element, it cannot be called across different address spaces. It means that it can be called only form CPU if the matrix is allocated on CPU or only from GPU kernels if the matrix is allocated on GPU.
row | is a row index of the element. |
column | is a columns index of the element. |
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= | ( | const DenseMatrix< Real, Device, Index, Organization, RealAllocator > & | matrix | ) |
Assignment operator with exactly the same type of the dense matrix.
matrix | is the right-hand side matrix. |
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= | ( | const DenseMatrix< RHSReal, RHSDevice, RHSIndex, Organization, RHSRealAllocator > & | matrix | ) |
Assignment operator with the same organization.
matrix | is the right-hand side matrix. |
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= | ( | const DenseMatrix< RHSReal, RHSDevice, RHSIndex, RHSOrganization, RHSRealAllocator > & | matrix | ) |
Assignment operator with other dense matrices.
matrix | is the right-hand side matrix. |
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= | ( | const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, Organization > & | matrix | ) |
Assignment operator with matrix view having the same elements organization.
matrix | is the right-hand side matrix. |
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= | ( | const DenseMatrixView< RHSReal, RHSDevice, RHSIndex, RHSOrganization > & | matrix | ) |
Assignment operator with other dense matrices.
matrix | is the right-hand side matrix. |
DenseMatrix & TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator= | ( | const RHSMatrix & | matrix | ) |
Assignment operator with other (sparse) types of matrices.
matrix | is the right-hand side matrix. |
bool TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator== | ( | const DenseMatrix< Real_, Device_, Index_, Organization, RealAllocator_ > & | matrix | ) | const |
Comparison operator with another dense matrix.
matrix | is the right-hand side matrix. |
bool TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator== | ( | const DenseMatrixView< Real_, Device_, Index_, Organization > & | matrix | ) | const |
Comparison operator with another dense matrix view.
matrix | is the right-hand side matrix view. |
bool TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::operator== | ( | const Matrix & | matrix | ) | const |
Comparison operator with another arbitrary matrix type.
matrix | is the right-hand side 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::reduceAllRows | ( | Fetch & | fetch, |
const 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::reduceAllRows | ( | Fetch & | fetch, |
const 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::reduceRows | ( | IndexType | begin, |
IndexType | end, | ||
Fetch & | fetch, | ||
const Reduce & | reduce, | ||
Keep & | keep, | ||
const FetchValue & | 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::reduceRows | ( | IndexType | begin, |
IndexType | end, | ||
Fetch & | fetch, | ||
const Reduce & | reduce, | ||
Keep & | keep, | ||
const FetchValue & | 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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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 file where the matrix will be saved. |
Reimplemented from TNL::Object.
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::sequentialForAllRows | ( | Function && | function | ) |
This method calls sequentialForRows for all matrix rows.
See DenseMatrix::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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::sequentialForAllRows | ( | Function && | function | ) | const |
This method calls sequentialForRows for all matrix rows (for constant instances).
See DenseMatrix::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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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 |
RowView represents matrix row - see TNL::Matrices::DenseMatrix::RowView.
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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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 |
RowView represents matrix row - see TNL::Matrices::DenseMatrix::RowView.
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. |
|
overridevirtual |
Set number of rows and columns of this matrix.
rows | is the number of matrix rows. |
columns | is the number of matrix columns. |
Reimplemented from TNL::Matrices::Matrix< Real, Device, Index, RealAllocator >.
__cuda_callable__ void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::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. DenseMatrix::getRow or DenseMatrix::forElements and DenseMatrix::forAllElements.
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::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::setElements | ( | std::initializer_list< std::initializer_list< Value > > | data | ) |
This method recreates the dense matrix from 2D initializer list.
The number of matrix rows is set to the outer list size and the number of matrix columns is set to maximum size of inner lists. Missing elements are filled in with zeros.
data | is a initializer list of initializer lists representing list of matrix rows. |
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::setLike | ( | const Matrix & | matrix | ) |
Set the number of matrix rows and columns by the given matrix.
Matrix | is matrix type. This can be any matrix having methods getRows and getColumns. |
matrix | in the input matrix dimensions of which are to be adopted. |
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::setRowCapacities | ( | const RowCapacitiesVector & | rowCapacities | ) |
This method is only for the compatibility with the sparse matrices.
This method does nothing. In debug mode it contains assertions checking that given rowCapacities are compatible with the current matrix dimensions.
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::setValue | ( | const RealType & | v | ) |
Sets all matrix elements to value v.
v | is value all matrix elements will be set to. |
void TNL::Matrices::DenseMatrix< Real, Device, Index, Organization, RealAllocator >::vectorProduct | ( | const InVector & | inVector, |
OutVector & | outVector, | ||
const RealType & | matrixMultiplicator = 1.0 , |
||
const 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. |
Note that the ouput vector dimension must be the same as the number of matrix rows no matter how we set begin
and end
parameters. These parameters just say that some matrix rows and the output vector elements are omitted.