Template Numerical Library version\ main:4e58ea6
Loading...
Searching...
No Matches
TNL::Matrices Namespace Reference

Namespace for matrix formats. More...

Classes

class  DenseMatrix
 Implementation of dense matrix, i.e. matrix storing explicitly all of its elements including zeros. More...
 
class  DenseMatrixBase
 Implementation of dense matrix view. More...
 
class  DenseMatrixElement
 Accessor for dense matrix elements. More...
 
class  DenseMatrixRowView
 RowView is a simple structure for accessing rows of dense matrix. More...
 
class  DenseMatrixView
 Implementation of dense matrix view. More...
 
class  DistributedMatrix
 
struct  GeneralMatrix
 General non-symmetric matrix type. More...
 
class  GinkgoOperator
 Wraps a general TNL matrix as a Ginkgo LinOp. More...
 
class  HypreCSRMatrix
 Wrapper for Hypre's sequential CSR matrix. More...
 
class  HypreParCSRMatrix
 Wrapper for Hypre's sequential CSR matrix. More...
 
class  LambdaMatrix
 "Matrix-free matrix" based on lambda functions. More...
 
class  LambdaMatrixElement
 Accessor for elements of lambda matrix. More...
 
struct  LambdaMatrixFactory
 Helper class for creating instances of LambdaMatrix. More...
 
class  LambdaMatrixRowView
 RowView is a simple structure for accessing rows of Lambda matrix. More...
 
class  LambdaMatrixRowViewIterator
 
class  MatrixBase
 Base class for the implementation of concrete matrix types. More...
 
struct  MatrixInfo
 
class  MatrixOperations
 
class  MatrixOperations< Devices::Cuda >
 
class  MatrixReader
 Helper class for importing of matrices from different input formats. More...
 
class  MatrixRowViewIterator
 
struct  MatrixType
 Structure for specifying type of sparse matrix. More...
 
class  MatrixWriter
 Helper class for exporting of matrices to different output formats. More...
 
class  MultidiagonalMatrix
 Implementation of sparse multidiagonal matrix. More...
 
class  MultidiagonalMatrixBase
 A common base class for MultidiagonalMatrix and MultidiagonalMatrixView. More...
 
class  MultidiagonalMatrixElement
 Accessor for multidiagonal matrix elements. More...
 
class  MultidiagonalMatrixRowView
 RowView is a simple structure for accessing rows of multidiagonal matrix. More...
 
class  MultidiagonalMatrixView
 Implementation of sparse multidiagonal matrix. More...
 
class  SparseMatrix
 Implementation of sparse matrix, i.e. matrix storing only non-zero elements. More...
 
class  SparseMatrixBase
 Implementation of sparse matrix view. More...
 
class  SparseMatrixElement
 Accessor for sparse matrix elements. More...
 
class  SparseMatrixRowView
 RowView is a simple structure for accessing rows of sparse matrix. More...
 
class  SparseMatrixView
 Implementation of sparse matrix view. More...
 
class  StaticMatrix
 
struct  SymmetricMatrix
 Symmetric matrix type. More...
 
class  TridiagonalMatrix
 Implementation of sparse tridiagonal matrix. More...
 
class  TridiagonalMatrixBase
 A common base class for TridiagonalMatrix and TridiagonalMatrixView. More...
 
class  TridiagonalMatrixRowView
 RowView is a simple structure for accessing rows of tridiagonal matrix. More...
 
class  TridiagonalMatrixView
 Implementation of sparse tridiagonal matrix. More...
 

Enumerations

enum class  SymmetricMatrixEncoding { Complete , LowerPart , UpperPart , SparseMixed }
 Encoding of the matrix elements of the symmetric matrix. More...
 
enum class  TransposeState { None , Transpose }
 

Functions

template<typename Matrix , typename InVector , typename OutVector >
__global__ void ColumnMajorDenseMatrixVectorMultiplicationKernel (const Matrix matrix, const InVector inVector, OutVector outVector, int begin, int end, int gridIdx, typename Matrix::RealType matrixMultiplicator, typename Matrix::RealType outVectorMultiplicator)
 
template<typename Matrix >
void compressSparseMatrix (Matrix &A)
 Avoids unnecessary zero elements.
 
template<typename Matrix , typename AdjacencyMatrix >
void copyAdjacencyStructure (const Matrix &A, AdjacencyMatrix &B, bool has_symmetric_pattern=false, bool ignore_diagonal=true)
 
template<typename Matrix , typename Index , typename IndexVectorView , typename ValueVectorView , typename RowLengthsVector >
void copyBuffersToMatrixElements (Matrix &m, const IndexVectorView &thisColumnsBuffer_view, const ValueVectorView &thisValuesBuffer_view, Index baseRow, Index lastRow, Index maxRowLength, RowLengthsVector &thisRowLengths, IndexVectorView rowLocalIndexes_view)
 
template<typename Matrix1 , typename Matrix2 >
void copyDenseToDenseMatrix (Matrix1 &A, const Matrix2 &B)
 
template<typename Matrix1 , typename Matrix2 >
void copyDenseToSparseMatrix (Matrix1 &A, const Matrix2 &B)
 
template<typename Matrix , typename Index , typename IndexVector , typename ValueVector >
void copyMatrixElementsToBuffers (const Matrix &m, Index baseRow, Index lastRow, Index maxRowLength, IndexVector &columnsBuffer, ValueVector &valuesBuffer)
 
template<typename Matrix1 , typename Matrix2 >
void copySparseMatrix (Matrix1 &A, const Matrix2 &B)
 
template<typename Matrix1 , typename Matrix2 >
std::enable_if_t< std::is_same_v< typename Matrix1::DeviceType, typename Matrix2::DeviceType > > copySparseMatrix_impl (Matrix1 &A, const Matrix2 &B)
 
template<typename Matrix1 , typename Matrix2 >
std::enable_if_t< ! std::is_same_v< typename Matrix1::DeviceType, typename Matrix2::DeviceType > &&std::is_same_v< typename Matrix2::DeviceType, Devices::Host > > copySparseMatrix_impl (Matrix1 &A, const Matrix2 &B)
 
template<typename Matrix1 , typename Matrix2 >
std::enable_if_t< ! std::is_same_v< typename Matrix1::DeviceType, typename Matrix2::DeviceType > &&std::is_same_v< typename Matrix2::DeviceType, Devices::Cuda > > copySparseMatrix_impl (Matrix1 &A, const Matrix2 &B)
 
template<typename Matrix1 , typename Matrix2 >
void copySparseToDenseMatrix (Matrix1 &A, const Matrix2 &B)
 
template<typename Matrix1 , typename Matrix2 >
void copySparseToSparseMatrix (Matrix1 &A, const Matrix2 &B)
 
template<int tileDim, typename Matrix , typename Real , typename Index >
__global__ void DenseInPlaceTranspositionKernel (Matrix matrix, const Real matrixMultiplicator, const typename Matrix::IndexType gridIdx_x, const typename Matrix::IndexType gridIdx_y)
 
template<int tileDim, typename ResultMatrix , typename Matrix1 , typename Matrix2 >
__global__ void DenseMatrixProductKernel (ResultMatrix resultMatrix, const Matrix1 matrixA, const Matrix2 matrixB, const typename ResultMatrix::RealType matrixMultiplicator, TransposeState TransposeA, TransposeState TransposeB, const typename ResultMatrix::IndexType gridIdx_x, const typename ResultMatrix::IndexType gridIdx_y)
 
template<int tileDim, typename OutputMatrix , typename InputMatrix , typename Real , typename Index >
__global__ void DenseTranspositionKernel (OutputMatrix resultMatrix, const InputMatrix inputMatrix, const Real matrixMultiplicator, const typename OutputMatrix::IndexType gridIdx_x, const typename OutputMatrix::IndexType gridIdx_y)
 
template<typename Real >
__cuda_callable__ Real determinant (const StaticMatrix< Real, 2, 2 > &A)
 
template<typename Real >
__cuda_callable__ Real determinant (const StaticMatrix< Real, 3, 3 > &A)
 
template<typename Real >
__cuda_callable__ Real determinant (const StaticMatrix< Real, 4, 4 > &A)
 
template<typename RealType , typename IndexType >
__global__ void GeamCudaKernel (const IndexType m, const IndexType n, const RealType alpha, const RealType *A, const IndexType lda, const RealType beta, const RealType *B, const IndexType ldb, RealType *C, const IndexType ldc)
 
template<typename RealType , typename IndexType >
__global__ void GemvCudaKernel (const IndexType m, const IndexType n, const RealType alpha, const RealType *A, const IndexType lda, const RealType *x, const RealType beta, RealType *y)
 
template<typename Matrix >
auto getGinkgoMatrixCsr (std::shared_ptr< const gko::Executor > exec, Matrix &matrix) -> std::unique_ptr< gko::matrix::Csr< typename Matrix::RealType, typename Matrix::IndexType > >
 Converts any TNL sparse matrix to a Ginkgo Csr matrix.
 
template<typename Matrix >
auto getGinkgoMatrixCsrView (std::shared_ptr< const gko::Executor > exec, Matrix &matrix) -> std::unique_ptr< gko::matrix::Csr< typename Matrix::RealType, typename Matrix::IndexType > >
 Creates a Ginkgo Csr matrix view from a TNL CSR matrix.
 
template<typename Matrix , typename Real , int tileDim = 16>
void getInPlaceTransposition (Matrix &matrix, Real matrixMultiplicator=1.0)
 
template<typename ResultMatrix , typename Matrix1 , typename Matrix2 , typename Real , int tileDim = 16>
void getMatrixProduct (ResultMatrix &resultMatrix, const Matrix1 &matrix1, const Matrix2 &matrix2, Real matrixMultiplicator=1.0, TransposeState transposeA=TransposeState::None, TransposeState transposeB=TransposeState::None)
 
template<typename OutMatrix , typename InMatrix >
OutMatrix getSymmetricPart (const InMatrix &inMatrix)
 This function computes \(( A + A^T ) / 2 \), where \( A \) is a square matrix.
 
template<typename ResultMatrix , typename Matrix , typename Real , int tileDim = 16>
void getTransposition (ResultMatrix &resultMatrix, const Matrix &matrix, Real matrixMultiplicator=1.0)
 
template<typename Real >
__cuda_callable__ StaticMatrix< Real, 2, 2 > inverse (const StaticMatrix< Real, 2, 2 > &A)
 
template<typename Real >
__cuda_callable__ StaticMatrix< Real, 3, 3 > inverse (const StaticMatrix< Real, 3, 3 > &A)
 
template<typename Real >
__cuda_callable__ StaticMatrix< Real, 4, 4 > inverse (const StaticMatrix< Real, 4, 4 > &A)
 
constexpr std::false_type isDenseMatrix (...)
 
template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
constexpr std::true_type isDenseMatrix (const DenseMatrixBase< Real, Device, Index, Organization > &)
 
constexpr std::false_type isMatrix (...)
 
template<typename MatrixElementsLambda , typename CompressedRowLengthsLambda , typename Real , typename Device , typename Index >
constexpr std::true_type isMatrix (const LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index > &)
 
template<typename Real , typename Device , typename Index , typename MatrixType , ElementsOrganization Organization>
constexpr std::true_type isMatrix (const MatrixBase< Real, Device, Index, MatrixType, Organization > &)
 
template<typename InMatrixView , typename OutMatrixView , typename Real , typename Index >
__global__ void MultidiagonalMatrixTranspositionCudaKernel (const InMatrixView inMatrix, OutMatrixView outMatrix, const Real matrixMultiplicator, const Index gridIdx)
 
template<typename Value , std::size_t Rows1, std::size_t SharedDim, std::size_t Columns2, typename Permutation >
StaticMatrix< Value, Rows1, Columns2, Permutation > operator* (const StaticMatrix< Value, Rows1, SharedDim, Permutation > &matrix1, const StaticMatrix< Value, SharedDim, Columns2, Permutation > &matrix2)
 
template<typename Value , std::size_t Rows, std::size_t Columns, typename Permutation , typename T >
__cuda_callable__ StaticMatrix< Value, Rows, Columns, Permutation > operator* (const T &value, StaticMatrix< Value, Rows, Columns, Permutation > a)
 
template<typename Value , std::size_t Rows, std::size_t Columns, typename Permutation , typename T >
__cuda_callable__ StaticMatrix< Value, Rows, Columns, Permutation > operator* (StaticMatrix< Value, Rows, Columns, Permutation > a, const T &value)
 
template<typename Value , std::size_t Rows, std::size_t Columns, typename Permutation >
__cuda_callable__ StaticMatrix< Value, Rows, Columns, Permutation > operator+ (StaticMatrix< Value, Rows, Columns, Permutation > a, const StaticMatrix< Value, Rows, Columns > &b)
 
template<typename Value , std::size_t Rows, std::size_t Columns, typename Permutation >
__cuda_callable__ StaticMatrix< Value, Rows, Columns, Permutation > operator- (StaticMatrix< Value, Rows, Columns, Permutation > a, const StaticMatrix< Value, Rows, Columns > &b)
 
template<typename Value , std::size_t Rows, std::size_t Columns, typename Permutation , typename T >
__cuda_callable__ StaticMatrix< Value, Rows, Columns, Permutation > operator/ (StaticMatrix< Value, Rows, Columns, Permutation > a, const T &b)
 
template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
std::ostreamoperator<< (std::ostream &str, const DenseMatrixBase< Real, Device, Index, Organization > &matrix)
 Insertion operator for dense matrix and output stream.
 
template<typename MatrixElementsLambda , typename CompressedRowLengthsLambda , typename Real , typename Device , typename Index >
std::ostreamoperator<< (std::ostream &str, const LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index > &matrix)
 Insertion operator for lambda matrix and output stream.
 
template<typename MatrixElementsLambda , typename CompressedRowLengthsLambda , typename Real , typename Index >
std::ostreamoperator<< (std::ostream &str, const LambdaMatrixRowView< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Index > &row)
 Insertion operator for a Lambda matrix row.
 
template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
std::ostreamoperator<< (std::ostream &str, const MultidiagonalMatrixBase< Real, Device, Index, Organization > &matrix)
 Overloaded insertion operator for printing a matrix to output stream.
 
template<typename Real , typename Device , typename Index , typename MatrixType , typename SegmentsView , typename ComputeReal >
std::ostreamoperator<< (std::ostream &str, const SparseMatrixBase< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > &matrix)
 Overloaded insertion operator for printing a matrix to output stream.
 
template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
std::ostreamoperator<< (std::ostream &str, const SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView > &row)
 Insertion operator for a sparse matrix row.
 
template<typename Value , std::size_t Rows, std::size_t Columns, typename Permutation >
std::ostreamoperator<< (std::ostream &str, const StaticMatrix< Value, Rows, Columns, Permutation > &matrix)
 
template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
std::ostreamoperator<< (std::ostream &str, const TridiagonalMatrixBase< Real, Device, Index, Organization > &matrix)
 Overloaded insertion operator for printing a matrix to output stream.
 
template<typename Matrix , typename PermutationArray >
void permuteMatrixColumns (Matrix &matrix, const PermutationArray &iperm)
 
template<typename Matrix , typename PermutationArray >
void permuteMatrixRows (Matrix &matrix, const PermutationArray &perm)
 
template<typename Array1 , typename Array2 , typename PermutationArray >
void reorderArray (const Array1 &src, Array2 &dest, const PermutationArray &perm)
 
template<typename Matrix1 , typename Matrix2 , typename PermutationArray >
void reorderSparseMatrix (const Matrix1 &matrix1, Matrix2 &matrix2, const PermutationArray &perm, const PermutationArray &iperm)
 
template<typename Real >
__cuda_callable__ Containers::StaticVector< 2, Realsolve (const StaticMatrix< Real, 2, 2 > &A, const Containers::StaticVector< 2, Real > &b)
 
template<typename Real >
__cuda_callable__ Containers::StaticVector< 3, Realsolve (const StaticMatrix< Real, 3, 3 > &A, const Containers::StaticVector< 3, Real > &b)
 
template<typename Real >
__cuda_callable__ Containers::StaticVector< 4, Realsolve (const StaticMatrix< Real, 4, 4 > &A, const Containers::StaticVector< 4, Real > &b)
 
template<typename Matrix1 , typename Matrix2 >
__global__ void SparseMatrixCopyKernel (Matrix1 *A, const Matrix2 *B, const typename Matrix2::IndexType *rowLengths, typename Matrix2::IndexType rows)
 
template<typename Vector , typename Matrix >
__global__ void SparseMatrixSetRowLengthsVectorKernel (Vector *rowLengths, const Matrix *matrix, typename Matrix::IndexType rows, typename Matrix::IndexType cols)
 
template<typename Value , std::size_t Rows, std::size_t Columns, typename Permutation >
StaticMatrix< Value, Columns, Rows, Permutation > transpose (const StaticMatrix< Value, Rows, Columns, Permutation > &A)
 
template<typename InMatrixView , typename OutMatrixView , typename Real , typename Index >
__global__ void TridiagonalMatrixTranspositionCudaKernel (const InMatrixView inMatrix, OutMatrixView outMatrix, Real matrixMultiplicator, Index gridIdx)
 
template<int BlockSize, int ThreadsPerRow, typename Matrix , typename InVector , typename OutVector >
__global__ void VectorColumnMajorDenseMatrixVectorMultiplicationKernel (const Matrix matrix, const InVector inVector, OutVector outVector, int begin, int end, int gridIdx, typename Matrix::RealType matrixMultiplicator, typename Matrix::RealType outVectorMultiplicator)
 
template<typename Device , typename Real , typename Index >
SparseMatrixView< Real, Device, Index, GeneralMatrix, Algorithms::Segments::CSRViewwrapCSRMatrix (const Index &rows, const Index &columns, Index *rowPointers, Real *values, Index *columnIndexes)
 Function for wrapping of arrays defining CSR format into a sparse matrix view.
 
template<typename Device , typename Real , typename Index , ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization()>
DenseMatrixView< Real, Device, Index, Organization > wrapDenseMatrix (const Index &rows, const Index &columns, Real *values)
 Function for wrapping an array of values into a dense matrix view.
 
template<typename Device , ElementsOrganization Organization, typename Real , typename Index , int Alignment = 1>
auto wrapEllpackMatrix (const Index rows, const Index columns, const Index nonzerosPerRow, Real *values, Index *columnIndexes) -> decltype(EllpackMatrixWrapper< Device, Organization, Real, Index, Alignment >::wrap(rows, columns, nonzerosPerRow, values, columnIndexes))
 Function for wrapping of arrays defining Ellpack format into a sparse matrix view.
 

Variables

template<typename T >
constexpr bool is_dense_matrix_type_v = decltype( isDenseMatrix( std::declval< T >() ) )::value
 
template<typename T >
constexpr bool is_matrix_type_v = decltype( isMatrix( std::declval< T >() ) )::value
 
template<typename Index >
constexpr Index paddingIndex = static_cast< Index >( -1 )
 Padding index value.
 

Detailed Description

Namespace for matrix formats.

Enumeration Type Documentation

◆ SymmetricMatrixEncoding

Encoding of the matrix elements of the symmetric matrix.

Enumerator
Complete 

All elements of the matrix are stored.

LowerPart 

Only lower part of the matrix is stored.

UpperPart 

Only upper part of the matrix is stored.

SparseMixed 

For each couple of non-zero elements a_ij and a_ji, at least one is encoded. It is handy for example for adjacency matrices of undirected graphs.

Function Documentation

◆ compressSparseMatrix()

template<typename Matrix >
void TNL::Matrices::compressSparseMatrix ( Matrix & A)

Avoids unnecessary zero elements.

This method is especially usefull for removing of explicitly coded zero elements but it also removes unnecessary padding elements.

Template Parameters
Matrixis the matrix type.
Parameters
Ais the matrix to be compressed.

◆ getSymmetricPart()

template<typename OutMatrix , typename InMatrix >
OutMatrix TNL::Matrices::getSymmetricPart ( const InMatrix & inMatrix)

This function computes \(( A + A^T ) / 2 \), where \( A \) is a square matrix.

Template Parameters
InMatrixis the type of the input matrix.
OutMatrixis the type of the output matrix.
Parameters
inMatrixis the input matrix.
Returns
the output matrix.

◆ operator<<() [1/7]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
std::ostream & TNL::Matrices::operator<< ( std::ostream & str,
const DenseMatrixBase< Real, Device, Index, Organization > & matrix )

Insertion operator for dense matrix and output stream.

Parameters
stris the output stream.
matrixis the dense matrix.
Returns
reference to the stream.

◆ operator<<() [2/7]

template<typename MatrixElementsLambda , typename CompressedRowLengthsLambda , typename Real , typename Device , typename Index >
std::ostream & TNL::Matrices::operator<< ( std::ostream & str,
const LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index > & matrix )

Insertion operator for lambda matrix and output stream.

Parameters
stris the output stream.
matrixis the lambda matrix.
Returns
reference to the stream.

◆ operator<<() [3/7]

template<typename MatrixElementsLambda , typename CompressedRowLengthsLambda , typename Real , typename Index >
std::ostream & TNL::Matrices::operator<< ( std::ostream & str,
const LambdaMatrixRowView< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Index > & row )

Insertion operator for a Lambda matrix row.

Parameters
stris an output stream.
rowis an input Lambda matrix row.
Returns
reference to the output stream.

◆ operator<<() [4/7]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
std::ostream & TNL::Matrices::operator<< ( std::ostream & str,
const MultidiagonalMatrixBase< Real, Device, Index, Organization > & matrix )

Overloaded insertion operator for printing a matrix to output stream.

Template Parameters
Realis a type of the matrix elements.
Deviceis a device where the matrix is allocated.
Indexis a type used for the indexing of the matrix elements.
Parameters
stris a output stream.
matrixis the matrix to be printed.
Returns
a reference to the output stream std::ostream.

◆ operator<<() [5/7]

template<typename Real , typename Device , typename Index , typename MatrixType , typename SegmentsView , typename ComputeReal >
std::ostream & TNL::Matrices::operator<< ( std::ostream & str,
const SparseMatrixBase< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > & matrix )

Overloaded insertion operator for printing a matrix to output stream.

Template Parameters
Realis a type of the matrix elements.
Deviceis a device where the matrix is allocated.
Indexis a type used for the indexing of the matrix elements.
Parameters
stris a output stream.
matrixis the matrix to be printed.
Returns
a reference to the output stream std::ostream.

◆ operator<<() [6/7]

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
std::ostream & TNL::Matrices::operator<< ( std::ostream & str,
const SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView > & row )

Insertion operator for a sparse matrix row.

Parameters
stris an output stream.
rowis an input sparse matrix row.
Returns
reference to the output stream.

◆ operator<<() [7/7]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
std::ostream & TNL::Matrices::operator<< ( std::ostream & str,
const TridiagonalMatrixBase< Real, Device, Index, Organization > & matrix )

Overloaded insertion operator for printing a matrix to output stream.

Template Parameters
Realis a type of the matrix elements.
Deviceis a device where the matrix is allocated.
Indexis a type used for the indexing of the matrix elements.
Parameters
stris a output stream.
matrixis the matrix to be printed.
Returns
a reference to the output stream std::ostream.

◆ wrapCSRMatrix()

template<typename Device , typename Real , typename Index >
SparseMatrixView< Real, Device, Index, GeneralMatrix, Algorithms::Segments::CSRView > TNL::Matrices::wrapCSRMatrix ( const Index & rows,
const Index & columns,
Index * rowPointers,
Real * values,
Index * columnIndexes )
nodiscard

Function for wrapping of arrays defining CSR format into a sparse matrix view.

Template Parameters
Deviceis a device on which the arrays are allocated.
Realis a type of matrix elements values.
Indexis a type for matrix elements indexing.
Parameters
rowsis a number of matrix rows.
columnsis a number of matrix columns.
rowPointersis an array holding row pointers of the CSR format ( ROW_INDEX here)
valuesis an array with values of matrix elements ( V here)
columnIndexesis an array with column indexes of matrix elements ( COL_INDEX here)
Returns
instance of SparseMatrixView with CSR format.

The size of array rowPointers must be equal to number of rows + 1. The last element of the array equals to the number of all nonzero matrix elements. The sizes of arrays values and columnIndexes must be equal to this number.

Example
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Matrices/MatrixWrapping.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
wrapMatrixView()
{
/***
* Encode the following matrix to CSR format...
*
* / 1 2 0 0 \.
* | 0 6 0 0 |
* | 9 0 0 0 |
* \ 0 0 15 16 /
*/
const int rows( 4 ), columns( 4 );
TNL::Containers::Vector< double, Device > valuesVector{ 1, 2, 6, 9, 15, 16 };
TNL::Containers::Vector< int, Device > columnIndexesVector{ 0, 1, 1, 0, 2, 3 };
TNL::Containers::Vector< int, Device > rowPointersVector{ 0, 2, 3, 4, 6 };
double* values = valuesVector.getData();
int* columnIndexes = columnIndexesVector.getData();
int* rowPointers = rowPointersVector.getData();
/***
* Wrap the arrays `rowPointers, `values` and `columnIndexes` to sparse matrix view
*/
auto matrix = TNL::Matrices::wrapCSRMatrix< Device >( rows, columns, rowPointers, values, columnIndexes );
std::cout << "Matrix reads as: " << std::endl << matrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Wraping matrix view on host: " << std::endl;
wrapMatrixView< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Wraping matrix view on CUDA device: " << std::endl;
wrapMatrixView< TNL::Devices::Cuda >();
#endif
}
__cuda_callable__ const Value * getData() const
Returns a const-qualified raw pointer to the data.
Definition Array.hpp:325
Vector extends Array with algebraic operations.
Definition Vector.h:36
T endl(T... args)
SparseMatrixView< Real, Device, Index, GeneralMatrix, Algorithms::Segments::CSRView > wrapCSRMatrix(const Index &rows, const Index &columns, Index *rowPointers, Real *values, Index *columnIndexes)
Function for wrapping of arrays defining CSR format into a sparse matrix view.
Definition MatrixWrapping.h:73
Output
Wraping matrix view on host:
Matrix reads as:
Row: 0 -> 0:1 1:2
Row: 1 -> 1:6
Row: 2 -> 0:9
Row: 3 -> 2:15 3:16
Wraping matrix view on CUDA device:
Matrix reads as:
Row: 0 -> 0:1 1:2
Row: 1 -> 1:6
Row: 2 -> 0:9
Row: 3 -> 2:15 3:16

◆ wrapDenseMatrix()

template<typename Device , typename Real , typename Index , ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization()>
DenseMatrixView< Real, Device, Index, Organization > TNL::Matrices::wrapDenseMatrix ( const Index & rows,
const Index & columns,
Real * values )
nodiscard

Function for wrapping an array of values into a dense matrix view.

Template Parameters
Deviceis a device on which the array is allocated.
Realis a type of array elements.
Indexis a type for indexing of matrix elements.
Organizationis matrix elements organization - see TNL::Algorithms::Segments::ElementsOrganization.
Parameters
rowsis a number of matrix rows.
columnsis a number of matrix columns.
valuesis the array with matrix elements values.
Returns
instance of DenseMatrixView wrapping the array.

The array size must be equal to product of rows and columns. The dense matrix view does not deallocate the input array at the end of its lifespan.

Example
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Matrices/MatrixWrapping.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
wrapMatrixView()
{
const int rows( 3 ), columns( 4 );
// clang-format off
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12
// clang-format on
};
double* values = valuesVector.getData();
/***
* Wrap the array `values` to dense matrix view
*/
auto matrix = TNL::Matrices::wrapDenseMatrix< Device >( rows, columns, values );
std::cout << "Matrix reads as: " << std::endl << matrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Wraping matrix view on host: " << std::endl;
wrapMatrixView< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Wraping matrix view on CUDA device: " << std::endl;
wrapMatrixView< TNL::Devices::Cuda >();
#endif
}
DenseMatrixView< Real, Device, Index, Organization > wrapDenseMatrix(const Index &rows, const Index &columns, Real *values)
Function for wrapping an array of values into a dense matrix view.
Definition MatrixWrapping.h:38
Output
Wraping matrix view on host:
Matrix reads as:
Row: 0 -> 0:1 1:2 2:3 3:4
Row: 1 -> 0:5 1:6 2:7 3:8
Row: 2 -> 0:9 1:10 2:11 3:12
Wraping matrix view on CUDA device:
Matrix reads as:
Row: 0 -> 0:1 1:4 2:7 3:10
Row: 1 -> 0:2 1:5 2:8 3:11
Row: 2 -> 0:3 1:6 2:9 3:12

◆ wrapEllpackMatrix()

template<typename Device , ElementsOrganization Organization, typename Real , typename Index , int Alignment = 1>
auto TNL::Matrices::wrapEllpackMatrix ( const Index rows,
const Index columns,
const Index nonzerosPerRow,
Real * values,
Index * columnIndexes ) -> decltype( EllpackMatrixWrapper< Device, Organization, Real, Index, Alignment >::wrap( rows, columns, nonzerosPerRow, values, columnIndexes ) )
nodiscard

Function for wrapping of arrays defining Ellpack format into a sparse matrix view.

This is to prevent from appearing in Doxygen documentation.

Template Parameters
Deviceis a device on which the arrays are allocated.
Realis a type of matrix elements values.
Indexis a type for matrix elements indexing.
Alignmentdefines alignment of data. The number of matrix rows is rounded to a multiple of this number. It it usefull mainly for GPUs.
Parameters
rowsis a number of matrix rows.
columnsis a number of matrix columns.
nonzerosPerRowis number of nonzero matrix elements in each row.
valuesis an array with values of matrix elements.
columnIndexesis an array with column indexes of matrix elements.
Returns
instance of SparseMatrixView with CSR format.

The sizes of arrays values and columnIndexes must be equal to rows * nonzerosPerRow. Use -1 as a column index for padding zeros.

Example
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Matrices/MatrixWrapping.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
wrapMatrixView()
{
/***
* Encode the following matrix to Ellpack format...
*
* / 1 2 0 0 \.
* | 0 6 0 0 |
* | 9 0 0 0 |
* \ 0 0 15 16 /
*/
const int rows( 4 ), columns( 4 );
TNL::Containers::Vector< double, Device > valuesVector{ 1, 2, 6, 0, 9, 0, 15, 16 };
TNL::Containers::Vector< int, Device > columnIndexesVector{ 0, 1, 1, -1, 0, -1, 2, 3 };
double* values = valuesVector.getData();
int* columnIndexes = columnIndexesVector.getData();
/***
* Wrap the arrays `values` and `columnIndexes` to sparse matrix view
*/
rows, columns, 2, values, columnIndexes );
std::cout << "Matrix reads as: " << std::endl << matrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Wraping matrix view on host: " << std::endl;
wrapMatrixView< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Wraping matrix view on CUDA device: " << std::endl;
wrapMatrixView< TNL::Devices::Cuda >();
#endif
}
auto wrapEllpackMatrix(const Index rows, const Index columns, const Index nonzerosPerRow, Real *values, Index *columnIndexes) -> decltype(EllpackMatrixWrapper< Device, Organization, Real, Index, Alignment >::wrap(rows, columns, nonzerosPerRow, values, columnIndexes))
Function for wrapping of arrays defining Ellpack format into a sparse matrix view.
Definition MatrixWrapping.h:134
Output
Wraping matrix view on host:
Matrix reads as:
Row: 0 -> 0:1 1:2
Row: 1 -> 1:6
Row: 2 -> 0:9
Row: 3 -> 2:15 3:16
Wraping matrix view on CUDA device:
Matrix reads as:
Row: 0 -> 0:1 1:2
Row: 1 -> 1:6
Row: 2 -> 0:9
Row: 3 -> 2:15 3:16

Variable Documentation

◆ paddingIndex

template<typename Index >
Index TNL::Matrices::paddingIndex = static_cast< Index >( -1 )
constexpr

Padding index value.

Padding index is used for column indexes of padding zeros. Padding zeros are used in some sparse matrix formats for better data alignment in memory.