Template Numerical Library: TNL::Matrices Namespace Reference

Template Numerical Library version\ main:be7e16d88

Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
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...

## Typedefs
template<typename T>
using | is_dense_matrix = decltype( isDenseMatrix( std::declval< T >() ) )
template<typename T>
using | is_matrix = decltype( isMatrix( std::declval< T >() ) )
template<typename Matrix>
using | is_sparse_csr_matrix = decltype( isSparseMatrix( std::declval< Matrix >() ) )

## Enumerations
enum | ElementsOrganization
enum class | SymmetricMatrixEncoding : std::uint8_t { Complete , LowerPart , UpperPart , SparseMixed }
| Encoding of the matrix elements of the symmetric matrix. More...
enum class | TransposeState : std::uint8_t { None , Transpose }

## Functions
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 Matrix1, typename Matrix2>
void | copyDenseToDenseMatrix (Matrix1 &A, const Matrix2 &B)
template<typename Matrix1, typename Matrix2>
void | copyDenseToSparseMatrix (Matrix1 &A, const Matrix2 &B)
template<typename Matrix1, typename Matrix2>
void | copySparseMatrix (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<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 (...)
| This checks if the matrix is dense matrix.
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 (...)
| This checks if given type is matrix.
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 > &)
constexpr std::false_type | isSparseMatrix (...)
| This checks if the sparse matrix is stored in CSR format.
template<typename Real, typename Device, typename Index, typename MatrixType, typename SegmentsView, typename ComputeReal>
constexpr std::true_type | isSparseMatrix (const SparseMatrixBase< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > &)
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>
File & | operator<< (File &&file, const DenseMatrixBase< Real, Device, Index, Organization > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator<< (File &&file, const MultidiagonalMatrixBase< Real, Device, Index, Organization > &matrix)
template<typename Real, typename Device, typename Index, typename MatrixType, typename SegmentsView, typename ComputeReal>
File & | operator<< (File &&file, const SparseMatrixBase< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator<< (File &&file, const TridiagonalMatrixBase< Real, Device, Index, Organization > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator<< (File &file, const DenseMatrixBase< Real, Device, Index, Organization > &matrix)
| Serialization of dense matrices into binary files.
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator<< (File &file, const MultidiagonalMatrixBase< Real, Device, Index, Organization > &matrix)
| Serialization of multidiagonal matrices into binary files.
template<typename Real, typename Device, typename Index, typename MatrixType, typename SegmentsView, typename ComputeReal>
File & | operator<< (File &file, const SparseMatrixBase< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > &matrix)
| Serialization of sparse matrices into binary files.
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator<< (File &file, const TridiagonalMatrixBase< Real, Device, Index, Organization > &matrix)
| Serialization of tridiagonal matrices into binary files.
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
std::ostream & | operator<< (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::ostream & | operator<< (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::ostream & | operator<< (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::ostream & | operator<< (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::ostream & | operator<< (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::ostream & | operator<< (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::ostream & | operator<< (std::ostream &str, const StaticMatrix< Value, Rows, Columns, Permutation > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
std::ostream & | operator<< (std::ostream &str, const TridiagonalMatrixBase< Real, Device, Index, Organization > &matrix)
| Overloaded insertion operator for printing a matrix to output stream.
template<typename Real, typename Device, typename Index, ElementsOrganization Organization, typename RealAllocator>
File & | operator>> (File &&file, DenseMatrix< Real, Device, Index, Organization, RealAllocator > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator>> (File &&file, DenseMatrixView< Real, Device, Index, Organization > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization, typename RealAllocator, typename IndexAllocator>
File & | operator>> (File &&file, MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator>> (File &&file, MultidiagonalMatrixView< Real, Device, Index, Organization > &matrix)
template<typename Real, typename Device, typename Index, typename MatrixType, template< typename, typename, typename > class Segments, typename ComputeReal, typename RealAllocator, typename IndexAllocator>
File & | operator>> (File &&file, SparseMatrix< Real, Device, Index, MatrixType, Segments, ComputeReal, RealAllocator, IndexAllocator > &matrix)
template<typename Real, typename Device, typename Index, typename MatrixType, template< typename, typename > class SegmentsView, typename ComputeReal>
File & | operator>> (File &&file, SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization, typename RealAllocator>
File & | operator>> (File &&file, TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator>> (File &&file, TridiagonalMatrixView< Real, Device, Index, Organization > &matrix)
template<typename Real, typename Device, typename Index, ElementsOrganization Organization, typename RealAllocator>
File & | operator>> (File &file, DenseMatrix< Real, Device, Index, Organization, RealAllocator > &matrix)
| Deserialization of dense matrices from binary files.
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator>> (File &file, DenseMatrixView< Real, Device, Index, Organization > &matrix)
| Deserialization of dense matrix views from binary files.
template<typename Real, typename Device, typename Index, ElementsOrganization Organization, typename RealAllocator, typename IndexAllocator>
File & | operator>> (File &file, MultidiagonalMatrix< Real, Device, Index, Organization, RealAllocator, IndexAllocator > &matrix)
| Deserialization of multidiagonal matrices from binary files.
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator>> (File &file, MultidiagonalMatrixView< Real, Device, Index, Organization > &matrix)
| Deserialization of multidiagonal matrix views from binary files.
template<typename Real, typename Device, typename Index, typename MatrixType, template< typename, typename, typename > class Segments, typename ComputeReal, typename RealAllocator, typename IndexAllocator>
File & | operator>> (File &file, SparseMatrix< Real, Device, Index, MatrixType, Segments, ComputeReal, RealAllocator, IndexAllocator > &matrix)
| Deserialization of sparse matrices from binary files.
template<typename Real, typename Device, typename Index, typename MatrixType, template< typename, typename > class SegmentsView, typename ComputeReal>
File & | operator>> (File &file, SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > &matrix)
| Deserialization of sparse matrix views from binary files.
template<typename Real, typename Device, typename Index, ElementsOrganization Organization, typename RealAllocator>
File & | operator>> (File &file, TridiagonalMatrix< Real, Device, Index, Organization, RealAllocator > &matrix)
| Deserialization of tridiagonal matrices from binary files.
template<typename Real, typename Device, typename Index, ElementsOrganization Organization>
File & | operator>> (File &file, TridiagonalMatrixView< Real, Device, Index, Organization > &matrix)
| Deserialization of tridiagonal matrix views from binary files.
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, Real > | solve (const StaticMatrix< Real, 2, 2 > &A, const Containers::StaticVector< 2, Real > &b)
template<typename Real>
__cuda_callable__ Containers::StaticVector< 3, Real > | solve (const StaticMatrix< Real, 3, 3 > &A, const Containers::StaticVector< 3, Real > &b)
template<typename Real>
__cuda_callable__ Containers::StaticVector< 4, Real > | solve (const StaticMatrix< Real, 4, 4 > &A, const Containers::StaticVector< 4, Real > &b)
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 Device, typename Real, typename Index>
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.
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_v = is_dense_matrix< T >::value
template<typename T>
constexpr bool | is_matrix_v = is_matrix< T >::value
template<typename Matrix>
constexpr bool | is_sparse_csr_matrix_v = is_sparse_csr_matrix< Matrix >::value
template<typename Index>
constexpr Index | paddingIndex = static_cast< Index >( -1 )
| Padding index value.

## Detailed Description

Namespace for matrix formats.

## Enumeration Type Documentation

## ◆ SymmetricMatrixEncoding

enum class TNL::Matrices::SymmetricMatrixEncoding : std::uint8_t
| strong

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 useful for removing of explicitly coded zero elements but it also removes unnecessary padding elements.

Template Parameters

  Matrix | is the matrix type.

Parameters

  A | is 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

  InMatrix | is the type of the input matrix.
  OutMatrix | is the type of the output matrix.

Parameters

  inMatrix | is 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

  str | is the output stream.
  matrix | is 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

  str | is the output stream.
  matrix | is 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

  str | is an output stream.
  row | is 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

  Real | is a type of the matrix elements.
  Device | is a device where the matrix is allocated.
  Index | is a type used for the indexing of the matrix elements.

Parameters

  str | is a output stream.
  matrix | is 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

  Real | is a type of the matrix elements.
  Device | is a device where the matrix is allocated.
  Index | is a type used for the indexing of the matrix elements.

Parameters

  str | is a output stream.
  matrix | is 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

  str | is an output stream.
  row | is 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

  Real | is a type of the matrix elements.
  Device | is a device where the matrix is allocated.
  Index | is a type used for the indexing of the matrix elements.

Parameters

  str | is a output stream.
  matrix | is 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

  Device | is a device on which the arrays are allocated.
  Real | is a type of matrix elements values.
  Index | is a type for matrix elements indexing.

Parameters

  rows | is a number of matrix rows.
  columns | is a number of matrix columns.
  rowPointers | is an array holding row pointers of the CSR format ( ROW_INDEX here)
  values | is an array with values of matrix elements ( V here)
  columnIndexes | is 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;
  const int 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:\n" << matrix << '\n';
  }
  int
  main( int argc, char* argv[] )
  {
  std::cout << "Wrapping matrix view on host:\n";
  wrapMatrixView< TNL::Devices::Host >();
  #ifdef __CUDACC__
  std::cout << "Wrapping matrix view on CUDA device:\n";
  wrapMatrixView< TNL::Devices::Cuda >();
  #endif
  }
  std::cout
  TNL::Containers::Array::getData
  __cuda_callable__ const Value * getData() const
  Returns a const-qualified raw pointer to the data.
  TNL::Containers::Vector
  Vector extends Array with algebraic operations.
  Definition Vector.h:36
  TNL::Matrices::wrapCSRMatrix
  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
  Wrapping 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

## ◆ 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

  Device | is a device on which the array is allocated.
  Real | is a type of array elements.
  Index | is a type for indexing of matrix elements.
  Organization | is matrix elements organization - see TNL::Algorithms::Segments::ElementsOrganization.

Parameters

  rows | is a number of matrix rows.
  columns | is a number of matrix columns.
  values | is 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;
  const int columns = 4;
  TNL::Containers::Vector< double, Device > valuesVector{
  // 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:\n" << matrix << '\n';
  }
  int
  main( int argc, char* argv[] )
  {
  std::cout << "Wrapping matrix view on host:\n";
  wrapMatrixView< TNL::Devices::Host >();
  #ifdef __CUDACC__
  std::cout << "Wrapping matrix view on CUDA device:\n";
  wrapMatrixView< TNL::Devices::Cuda >();
  #endif
  }
  TNL::Matrices::wrapDenseMatrix
  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
  Wrapping 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

## ◆ 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

  Device | is a device on which the arrays are allocated.
  Real | is a type of matrix elements values.
  Index | is a type for matrix elements indexing.
  Alignment | defines alignment of data. The number of matrix rows is rounded to a multiple of this number. It it useful mainly for GPUs.

Parameters

  rows | is a number of matrix rows.
  columns | is a number of matrix columns.
  nonzerosPerRow | is number of nonzero matrix elements in each row.
  values | is an array with values of matrix elements.
  columnIndexes | is 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;
  const int 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
  */
  auto matrix = TNL::Matrices::wrapEllpackMatrix< Device, TNL::Algorithms::Segments::RowMajorOrder >(
  rows, columns, 2, values, columnIndexes );
  std::cout << "Matrix reads as:\n" << matrix << '\n';
  }
  int
  main( int argc, char* argv[] )
  {
  std::cout << "Wrapping matrix view on host:\n";
  wrapMatrixView< TNL::Devices::Host >();
  #ifdef __CUDACC__
  std::cout << "Wrapping matrix view on CUDA device:\n";
  wrapMatrixView< TNL::Devices::Cuda >();
  #endif
  }
  TNL::Matrices::wrapEllpackMatrix
  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
  Wrapping 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

## 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.