Template Numerical Library version\ main:f17d0c8
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator > Class Template Reference

Template of a sparse matrix that can be used for testing of new sparse-matrix formats. More...

#include <TNL/Matrices/Sandbox/SparseSandboxMatrix.h>

Inheritance diagram for TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >:
Inheritance graph
[legend]
Collaboration diagram for TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >:
Collaboration graph
[legend]

Public Types

using ColumnsIndexesVectorType
 
using ColumnsIndexesViewType = typename ColumnsIndexesVectorType::ViewType
 
using ConstColumnsIndexesViewType = typename ColumnsIndexesViewType::ConstViewType
 
using ConstRowCapacitiesView = typename RowCapacitiesView::ConstViewType
 
using ConstRowView = SparseSandboxMatrixRowView< ConstValuesViewType, ConstColumnsIndexesViewType, isBinary() >
 Type for accessing constant matrix rows.
 
using ConstValuesViewType = typename ValuesViewType::ConstViewType
 
using ConstViewType = SparseSandboxMatrixView< std::add_const_t< Real >, Device, Index, MatrixType >
 Matrix view type for constant instances.
 
using DeviceType = Device
 The device where the matrix is allocated.
 
using IndexAllocatorType = IndexAllocator
 The allocator for matrix elements column indexes.
 
using IndexType = Index
 The type used for matrix elements indexing.
 
using RealAllocatorType = RealAllocator
 The allocator for matrix elements values.
 
using RealType = std::remove_const_t< Real >
 The type of matrix elements.
 
using RowCapacitiesType = Containers::Vector< std::remove_const_t< Index >, Device, Index, IndexAllocator >
 
using RowCapacitiesView = Containers::VectorView< std::remove_const_t< Index >, Device, Index >
 
using RowPointers = TNL::Containers::Vector< IndexType, DeviceType, IndexType >
 Type of container for CSR row pointers.
 
using RowView = SparseSandboxMatrixRowView< ValuesViewType, ColumnsIndexesViewType, isBinary() >
 Type for accessing matrix rows.
 
template<typename _Real = Real, typename _Device = Device, typename _Index = Index, typename _MatrixType = MatrixType, typename _RealAllocator = typename Allocators::Default< _Device >::template Allocator< _Real >, typename _IndexAllocator = typename Allocators::Default< _Device >::template Allocator< _Index >>
using Self = SparseSandboxMatrix< _Real, _Device, _Index, _MatrixType, _RealAllocator, _IndexAllocator >
 Helper type for getting self type or its modifications.
 
using ValuesVectorType = Containers::Vector< Real, Device, Index, RealAllocator >
 
using ValuesViewType = typename ValuesVectorType::ViewType
 
using ViewType = SparseSandboxMatrixView< Real, Device, Index, MatrixType >
 Type of related matrix view.
 

Public Member Functions

 SparseSandboxMatrix (const RealAllocatorType &realAllocator=RealAllocatorType(), const IndexAllocatorType &indexAllocator=IndexAllocatorType())
 Constructor only with values and column indexes allocators.
 
template<typename RowCapacitiesVector , std::enable_if_t< TNL::IsArrayType< RowCapacitiesVector >::value, int > = 0>
 SparseSandboxMatrix (const RowCapacitiesVector &rowCapacities, IndexType columns, const RealAllocatorType &realAllocator=RealAllocatorType(), const IndexAllocatorType &indexAllocator=IndexAllocatorType())
 Constructor with matrix rows capacities given as a vector and number of columns.
 
 SparseSandboxMatrix (const SparseSandboxMatrix &matrix)=default
 Copy constructor.
 
template<typename ListIndex >
 SparseSandboxMatrix (const std::initializer_list< ListIndex > &rowCapacities, IndexType columns, const RealAllocatorType &realAllocator=RealAllocatorType(), const IndexAllocatorType &indexAllocator=IndexAllocatorType())
 Constructor with matrix rows capacities and number of columns.
 
template<typename Index_t , std::enable_if_t< std::is_integral< Index_t >::value, int > = 0>
 SparseSandboxMatrix (Index_t rows, Index_t columns, const RealAllocatorType &realAllocator=RealAllocatorType(), const IndexAllocatorType &indexAllocator=IndexAllocatorType())
 Constructor with matrix dimensions.
 
 SparseSandboxMatrix (IndexType rows, IndexType columns, const std::initializer_list< std::tuple< IndexType, IndexType, RealType > > &data, const RealAllocatorType &realAllocator=RealAllocatorType(), const IndexAllocatorType &indexAllocator=IndexAllocatorType())
 Constructor with matrix dimensions and data in initializer list.
 
template<typename MapIndex , typename MapValue >
 SparseSandboxMatrix (IndexType rows, IndexType columns, const std::map< std::pair< MapIndex, MapIndex >, MapValue > &map, const RealAllocatorType &realAllocator=RealAllocatorType(), const IndexAllocatorType &indexAllocator=IndexAllocatorType())
 Constructor with matrix dimensions and data in std::map.
 
 SparseSandboxMatrix (SparseSandboxMatrix &&matrix) noexcept=default
 Move constructor.
 
__cuda_callable__ void addElement (IndexType row, IndexType column, const RealType &value, const RealType &thisElementMultiplicator)
 Add element at given row and column to given value.
 
template<typename Function >
void forAllElements (Function &&function)
 Method for parallel iteration over all matrix elements for non-constant instances.
 
template<typename Function >
void forAllElements (Function &&function) const
 Method for parallel iteration over all matrix elements for constant instances.
 
template<typename Function >
void forAllRows (Function &&function)
 Method for parallel iteration over all matrix rows.
 
template<typename Function >
void forAllRows (Function &&function) const
 Method for parallel iteration over all matrix rows for constant instances.
 
template<typename Function >
void forElements (IndexType begin, IndexType end, Function &&function)
 Method for parallel iteration over all matrix elements of given rows for non-constant instances.
 
template<typename Function >
void forElements (IndexType begin, IndexType end, Function &&function) const
 Method for parallel iteration over matrix elements of given rows for constant instances.
 
template<typename Function >
void forRows (IndexType begin, IndexType end, Function &&function)
 Method for parallel iteration over matrix rows from interval [begin, end).
 
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.
 
ColumnsIndexesVectorTypegetColumnIndexes ()
 Getter of column indexes for nonconstant instances.
 
const ColumnsIndexesVectorTypegetColumnIndexes () const
 Getter of segments for non-constant instances.
 
__cuda_callable__ IndexType getColumns () const
 Returns number of matrix columns.
 
template<typename Vector >
void getCompressedRowLengths (Vector &rowLengths) const
 Computes number of non-zeros in each row.
 
ConstViewType getConstView () const
 Returns a non-modifiable view of the sparse matrix.
 
__cuda_callable__ RealType getElement (IndexType row, IndexType column) const
 Returns value of matrix element at position given by its row and column index.
 
IndexType getNonzeroElementsCount () const
 Returns number of non-zero matrix elements.
 
__cuda_callable__ RowView getRow (const IndexType &rowIdx)
 Non-constant getter of simple structure for accessing given matrix row.
 
__cuda_callable__ ConstRowView getRow (const IndexType &rowIdx) const
 Constant getter of simple structure for accessing given matrix row.
 
template<typename Vector >
void getRowCapacities (Vector &rowCapacities) const
 Compute capacities of all rows.
 
__cuda_callable__ IndexType getRowCapacity (IndexType row) const
 Returns capacity of given matrix row.
 
__cuda_callable__ IndexType getRows () const
 Returns number of matrix rows.
 
std::string getSerializationTypeVirtual () const override
 Returns string with serialization type.
 
template<typename Real2 , typename Index2 >
void getTransposition (const SparseSandboxMatrix< Real2, Device, Index2, MatrixType > &matrix, const RealType &matrixMultiplicator=1.0)
 
ValuesVectorTypegetValues ()
 Returns a reference to a vector with the matrix elements values.
 
const ValuesVectorTypegetValues () const
 Returns a constant reference to a vector with the matrix elements values.
 
ViewType getView ()
 Returns a modifiable view of the sparse matrix.
 
void load (const String &fileName)
 Method for loading the matrix from the file with given filename.
 
void load (File &file) override
 Method for loading the matrix from a file.
 
template<typename Matrix >
bool operator!= (const Matrix &matrix) const
 Comparison operator with another arbitrary matrix type.
 
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization, typename RealAllocator_ >
SparseSandboxMatrixoperator= (const DenseMatrix< Real_, Device_, Index_, Organization, RealAllocator_ > &matrix)
 Assignment of dense matrix.
 
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization, typename RealAllocator_ >
SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator > & operator= (const DenseMatrix< Real_, Device_, Index_, Organization, RealAllocator_ > &matrix)
 
template<typename RHSMatrix >
SparseSandboxMatrixoperator= (const RHSMatrix &matrix)
 Assignment of any matrix type other then this and dense.
 
template<typename RHSMatrix >
SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator > & operator= (const RHSMatrix &matrix)
 
SparseSandboxMatrixoperator= (const SparseSandboxMatrix &matrix)
 Assignment of exactly the same matrix type.
 
template<typename Device_ >
SparseSandboxMatrixoperator= (const SparseSandboxMatrix< RealType, Device_, IndexType, MatrixType, RealAllocator, IndexAllocator > &matrix)
 Assignment of exactly the same matrix type but different device.
 
template<typename Device_ >
SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator > & operator= (const SparseSandboxMatrix< RealType, Device_, IndexType, MatrixType, RealAllocator, IndexAllocator > &matrix)
 
template<typename Matrix >
bool operator== (const Matrix &matrix) const
 Comparison operator with another arbitrary matrix type.
 
void print (std::ostream &str) const
 Method for printing the matrix to output stream.
 
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal >
void reduceAllRows (Fetch &fetch, const Reduce &reduce, Keep &keep, const FetchReal &zero) const
 Method for performing general reduction on all matrix rows for constant instances.
 
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal >
void reduceRows (IndexType begin, IndexType end, Fetch &fetch, const Reduce &reduce, Keep &keep, const FetchReal &zero) const
 Method for performing general reduction on matrix rows for constant instances.
 
template<typename Fetch , typename Reduce , typename Keep , typename FetchValue >
void reduceRows (IndexType begin, IndexType end, Fetch &fetch, const Reduce &reduce, Keep &keep, const FetchValue &zero) const
 
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.
 
void save (File &file) const override
 Method for saving the matrix to a file.
 
template<typename Function >
void sequentialForAllRows (Function &function)
 This method calls sequentialForRows for all matrix rows.
 
template<typename Function >
void sequentialForAllRows (Function &function) const
 This method calls sequentialForRows for all matrix rows (for constant instances).
 
template<typename Function >
void sequentialForRows (IndexType begin, IndexType end, Function &function)
 Method for sequential iteration over all matrix rows for non-constant instances.
 
template<typename Function >
void sequentialForRows (IndexType begin, IndexType end, Function &function) const
 Method for sequential iteration over all matrix rows for constant instances.
 
void setDimensions (IndexType rows, IndexType columns)
 Set number of rows and columns of this matrix.
 
__cuda_callable__ void setElement (IndexType row, IndexType column, const RealType &value)
 Sets element at given row and column to given value.
 
void setElements (const std::initializer_list< std::tuple< IndexType, IndexType, RealType > > &data)
 This method sets the sparse matrix elements from initializer list.
 
template<typename MapIndex , typename MapValue >
void setElements (const std::map< std::pair< MapIndex, MapIndex >, MapValue > &map)
 This method sets the sparse matrix elements from std::map.
 
template<typename Matrix >
void setLike (const Matrix &matrix)
 Set the number of matrix rows and columns by the given matrix.
 
template<typename Matrix_ >
void setLike (const Matrix_ &matrix)
 
template<typename RowCapacitiesVector >
void setRowCapacities (const RowCapacitiesVector &rowCapacities)
 Allocates memory for non-zero matrix elements.
 
template<typename InVector , typename OutVector >
void vectorProduct (const InVector &inVector, OutVector &outVector, RealType matrixMultiplicator=1.0, RealType outVectorMultiplicator=0.0, IndexType begin=0, IndexType end=0) const
 Computes product of matrix and vector.
 
- Public Member Functions inherited from TNL::Object
virtual ~Object ()=default
 Destructor.
 
void load (const String &fileName)
 Method for restoring the object from a file.
 
void save (const String &fileName) const
 Method for saving the object to a file as a binary data.
 

Static Public Member Functions

static std::string getSerializationType ()
 Returns string with serialization type.
 
static constexpr bool isBinary ()
 Test of binary matrix type.
 
static constexpr bool isSymmetric ()
 Test of symmetric matrix type.
 
- Static Public Member Functions inherited from TNL::Object
static std::string getSerializationType ()
 Static serialization type getter.
 

Protected Attributes

ColumnsIndexesVectorType columnIndexes
 Vector containing the column indices of non-zero matrix elements.
 
IndexType columns
 
IndexAllocator indexAllocator
 
RowPointers rowPointers
 Container for CSR row pointers.
 
IndexType rows
 
ValuesVectorType values
 Array containing the allocated matrix elements.
 
ViewType view
 Instance of the sparse matrix view.
 

Detailed Description

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
class TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >

Template of a sparse matrix that can be used for testing of new sparse-matrix formats.

Template Parameters
Realis a type of matrix elements. If Real equals bool the matrix is treated as binary and so the matrix elements values are not stored in the memory since we need to remember only coordinates of non-zero elements( which equal one).
Deviceis a device where the matrix is allocated.
Indexis a type for indexing of the matrix elements.
MatrixTypespecifies a symmetry of matrix. See MatrixType. Symmetric matrices store only lower part of the matrix and its diagonal. The upper part is reconstructed on the fly. GeneralMatrix with no symmetry is used by default.
RealAllocatoris allocator for the matrix elements values.
IndexAllocatoris allocator for the matrix elements column indexes.

This class can be used for rapid testing and development of new formats for sparse matrices. One may profit from several TNL tools compatible with interface of this templated class like:

  1. Large set of existing unit tests.
  2. Matrix reading from MTX files - to use TNL::Matrices::MatrixReader, the following methods must be functional a. SparseSandboxMatrix::setRowCapacities b. SparseSandboxMatrix::setElement c. SparseSandboxMatrix::operator= between different devices
  3. Matrix benchmarks - the following methods must be functional a. SparseSandboxMatrix::vectorProduct - for SpMV benchmark
  4. Linear solvers
  5. Simple comparison of performance with other matrix formats

In the core of this class there is:

  1. Vector 'values(\ref SparseSandboxMatrix::values) which is used for storing of matrix elements values.
  2. VectorcolumnIndexes` (SparseSandboxMatrix::columnIndexes). This vector is used for storing of matrix elements column indexes.

This class contains fully functional implementation of CSR format and so the user have to replace just what he needs to. Once you have successfully implemented the sparse matrix format in this form, you may consider to extract it into a form of segments to make it accessible even for other algorithms then SpMV.

Parts of the code, that need to be modified are marked by SANDBOX_TODO tag. The whole implementation consits of the following classes:

  1. SparseSandboxMatrix - this class, it serves for matrix setup and performing of the main operations.
  2. SparseSandboxMatrixView - view class which is necessary mainly for passing the matrix to GPU kernels. Most methods of SparseSandboxMatrix are common with SparseSandboxMatrixView and in this case they are implemented in the view class (and there is just redirection from this class). For this reason, SparseSandboxMatrix contains instance of the view class (SparseSandboxMatrix::view) which needs to be regularly updated each time when metadata are changed. This is usually done by the means of method SparseSandboxMatrix::getView.
  3. SparseSandboxMatrixRowView - is a class for accessing particular matrix rows. It will, likely, require some changes as well.

We suggest the following way of implementation of the new sparse matrix format:

  1. Add metadata required by your format next to SparseSandboxMatrix::rowPointers but do not replace the row pointers. It will allow you to implement your new format next to the original CSR and to check/compare with the valid CSR implementation any time you get into troubles. The adventage is that all unit tests are working properly and you may just focus on modifying one method after another. The unit tests are called from src/UnitTests/Matrices/SparseMatrixTests_SandboxMatrix.h and src/UnitTests/Matrices/SparseMatrixVectorProductTests_SandboxMatrix.h
  2. Modify first the method SparseSandboxMatrix::setRowCapacities which is responsible for the setup of the format metadata.
  3. Continue with modification of constructors, view class, SparseSandboxMatrix::getView and SparseSandboxMatrix::getConstView.
  4. Next you need to modify SparseSandboxMatrix::setElement and SparseSandboxMatrix::getElement methods and assignment operator at least for copying the matrix across different devices (i.e. from CPU to GPU). It will allow you to use TNL::Matrices::MatrixReader. We recommend to have the same data layout on both CPU and GPU so that the transfer of the matrix from CPU to GPU is trivial.
  5. Finally proceed to SparseSandboxMatrix::vectorProduct to implement SpMV operation. We recommend to implement first the CPU version which is easier to debug. Next proceed to GPU version.
  6. When SpMV works it is time to delete the original CSR implementation, i.e. everything around rowPointers.
  7. Optimize your implementation to the best performance and test with tnl-benchmark-spmv - you need to include your new matrix to src/Benchmarks/SpMV/spmv.h and modify this file accordingly.
  8. If you want, you may now generalize SpMV to SparseSandboxMatrix::reduceRows method.
  9. If you have reduceRows implemented, you may use the original implementation of SpMV based just on the reduceRows method.
  10. You may implement SparseSandboxMatrix::forRows and SparseSandboxMatrix::forElements.
  11. Now you have complete implementation of new sparse matrix format. You may turn it into new type of segments (TNL::Algorithms::Segments).

During the implementation some unit tests may crash. If you do not need them at the moment, you may comment them in files src/UnitTests/Matrices/SparseMatrixTests.h and src/UnitTests/Matrices/SparseMatrixVectorProductTests.h

Member Typedef Documentation

◆ ColumnsIndexesVectorType

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
using TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::ColumnsIndexesVectorType
Initial value:
Containers::Vector< typename TNL::copy_const< Index >::template from< Real >::type, Device, Index, IndexAllocator >
Subrange< Index > splitRange(Index rangeBegin, Index rangeEnd, int rank, int num_subintervals)
A helper function which splits a one-dimensional range.
Definition BlockPartitioning.h:27

◆ ConstViewType

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
using TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::ConstViewType = SparseSandboxMatrixView< std::add_const_t< Real >, Device, Index, MatrixType >

Matrix view type for constant instances.

See SparseSandboxMatrixView.

◆ RowPointers

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
using TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::RowPointers = TNL::Containers::Vector< IndexType, DeviceType, IndexType >

Type of container for CSR row pointers.

SANDBOX_TODO: You may replace it with containers for metadata of your format.

◆ ViewType

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
using TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::ViewType = SparseSandboxMatrixView< Real, Device, Index, MatrixType >

Type of related matrix view.

See SparseSandboxMatrixView.

Constructor & Destructor Documentation

◆ SparseSandboxMatrix() [1/8]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::SparseSandboxMatrix ( const RealAllocatorType & realAllocator = RealAllocatorType(),
const IndexAllocatorType & indexAllocator = IndexAllocatorType() )

Constructor only with values and column indexes allocators.

Parameters
realAllocatoris used for allocation of matrix elements values.
indexAllocatoris used for allocation of matrix elements column indexes.

◆ SparseSandboxMatrix() [2/8]

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::SparseSandboxMatrix ( const SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator > & matrix)
default

Copy constructor.

Parameters
matrixis the source matrix

◆ SparseSandboxMatrix() [3/8]

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::SparseSandboxMatrix ( SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator > && matrix)
defaultnoexcept

Move constructor.

Parameters
matrixis the source matrix

◆ SparseSandboxMatrix() [4/8]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Index_t , std::enable_if_t< std::is_integral< Index_t >::value, int > >
TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::SparseSandboxMatrix ( Index_t rows,
Index_t columns,
const RealAllocatorType & realAllocator = RealAllocatorType(),
const IndexAllocatorType & indexAllocator = IndexAllocatorType() )

Constructor with matrix dimensions.

Parameters
rowsis number of matrix rows.
columnsis number of matrix columns.
realAllocatoris used for allocation of matrix elements values.
indexAllocatoris used for allocation of matrix elements column indexes.

◆ SparseSandboxMatrix() [5/8]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename ListIndex >
TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::SparseSandboxMatrix ( const std::initializer_list< ListIndex > & rowCapacities,
IndexType columns,
const RealAllocatorType & realAllocator = RealAllocatorType(),
const IndexAllocatorType & indexAllocator = IndexAllocatorType() )
explicit

Constructor with matrix rows capacities and number of columns.

The number of matrix rows is given by the size of rowCapacities list.

Template Parameters
ListIndexis the initializer list values type.
Parameters
rowCapacitiesis a list telling how many matrix elements must be allocated in each row.
columnsis the number of matrix columns.
realAllocatoris used for allocation of matrix elements values.
indexAllocatoris used for allocation of matrix elements column indexes.

◆ SparseSandboxMatrix() [6/8]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename RowCapacitiesVector , std::enable_if_t< TNL::IsArrayType< RowCapacitiesVector >::value, int > >
TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::SparseSandboxMatrix ( const RowCapacitiesVector & rowCapacities,
IndexType columns,
const RealAllocatorType & realAllocator = RealAllocatorType(),
const IndexAllocatorType & indexAllocator = IndexAllocatorType() )
explicit

Constructor with matrix rows capacities given as a vector and number of columns.

The number of matrix rows is given by the size of rowCapacities vector.

Template Parameters
RowCapacitiesVectoris the row capacities vector type. Usually it is some of TNL::Containers::Array, TNL::Containers::ArrayView, TNL::Containers::Vector or TNL::Containers::VectorView.
Parameters
rowCapacitiesis a vector telling how many matrix elements must be allocated in each row.
columnsis the number of matrix columns.
realAllocatoris used for allocation of matrix elements values.
indexAllocatoris used for allocation of matrix elements column indexes.

◆ SparseSandboxMatrix() [7/8]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::SparseSandboxMatrix ( IndexType rows,
IndexType columns,
const std::initializer_list< std::tuple< IndexType, IndexType, RealType > > & data,
const RealAllocatorType & realAllocator = RealAllocatorType(),
const IndexAllocatorType & indexAllocator = IndexAllocatorType() )
explicit

Constructor with matrix dimensions and data in initializer list.

The matrix elements values are given as a list data of triples: { { row1, column1, value1 }, { row2, column2, value2 }, ... }.

Parameters
rowsis number of matrix rows.
columnsis number of matrix columns.
datais a list of matrix elements values.
realAllocatoris used for allocation of matrix elements values.
indexAllocatoris used for allocation of matrix elements column indexes.

◆ SparseSandboxMatrix() [8/8]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename MapIndex , typename MapValue >
TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::SparseSandboxMatrix ( IndexType rows,
IndexType columns,
const std::map< std::pair< MapIndex, MapIndex >, MapValue > & map,
const RealAllocatorType & realAllocator = RealAllocatorType(),
const IndexAllocatorType & indexAllocator = IndexAllocatorType() )
explicit

Constructor with matrix dimensions and data in std::map.

The matrix elements values are given as a map data where keys are std::pair of matrix coordinates ( {row, column} ) and value is the matrix element value.

Template Parameters
MapIndexis a type for indexing rows and columns.
MapValueis a type for matrix elements values in the map.
Parameters
rowsis number of matrix rows.
columnsis number of matrix columns.
mapis std::map containing matrix elements.
realAllocatoris used for allocation of matrix elements values.
indexAllocatoris used for allocation of matrix elements column indexes.

Member Function Documentation

◆ addElement()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
__cuda_callable__ void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::addElement ( IndexType row,
IndexType column,
const RealType & value,
const RealType & thisElementMultiplicator )

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. SparseMatrix::getRow or SparseMatrix::forElements and SparseMatrix::forAllElements. The call may fail if the matrix row capacity is exhausted.

Parameters
rowis row index of the element.
columnis columns index of the element.
valueis the value the element will be set to.
thisElementMultiplicatoris multiplicator the original matrix element value is multiplied by before addition of given value.

◆ forAllElements() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::forAllElements ( Function && function)

Method for parallel iteration over all matrix elements for non-constant instances.

See SparseMatrix::forElements.

Template Parameters
Functionis a type of lambda function that will operate on matrix elements.
Parameters
functionis an instance of the lambda function to be called for each matrix element.

◆ forAllElements() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::forAllElements ( Function && function) const

Method for parallel iteration over all matrix elements for constant instances.

See SparseMatrix::forElements.

Template Parameters
Functionis a type of lambda function that will operate on matrix elements.
Parameters
functionis an instance of the lambda function to be called for each matrix element.

◆ forAllRows() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::forAllRows ( Function && function)

Method for parallel iteration over all matrix rows.

In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method SparseMatrix::forAllElements where more than one thread can be mapped to each row.

Template Parameters
Functionis type of the lambda function.
Parameters
functionis an instance of the lambda function to be called for each row.
auto function = [] __cuda_callable__ ( RowView& row ) { ... };
#define __cuda_callable__
Definition Macros.h:49
RowView is a simple structure for accessing rows of sparse matrix.
Definition SparseSandboxMatrixRowView.h:24

RowView represents matrix row - see TNL::Matrices::SparseMatrix::RowView.

◆ forAllRows() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::forAllRows ( Function && function) const

Method for parallel iteration over all matrix rows for constant instances.

In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method SparseMatrix::forAllElements where more than one thread can be mapped to each row.

Template Parameters
Functionis type of the lambda function.
Parameters
functionis an instance of the lambda function to be called for each row.
auto function = [] __cuda_callable__ ( const ConstRowView& row ) { ... };

ConstRowView represents matrix row - see TNL::Matrices::SparseMatrix::ConstRowView.

◆ forElements() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::forElements ( IndexType begin,
IndexType end,
Function && function )

Method for parallel iteration over all matrix elements of given rows for non-constant instances.

Template Parameters
Functionis type of lambda function that will operate on matrix elements.
Parameters
begindefines beginning of the range [begin, end) of rows to be processed.
enddefines ending of the range [begin, end) of rows to be processed.
functionis an instance of the lambda function to be called for each element of given rows.

The lambda function function should be declared like follows:

auto function = [] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, RealType& value )
{ ... }
std::remove_const_t< Real > RealType
The type of matrix elements.
Definition SparseSandboxMatrix.h:177
Index IndexType
The type used for matrix elements indexing.
Definition SparseSandboxMatrix.h:187

The localIdx parameter is a rank of the non-zero element in given row.

◆ forElements() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::forElements ( IndexType begin,
IndexType end,
Function && function ) const

Method for parallel iteration over matrix elements of given rows for constant instances.

Template Parameters
Functionis type of lambda function that will operate on matrix elements.
Parameters
begindefines beginning of the range [begin, end) of rows to be processed.
enddefines ending of the range [begin, end) of rows to be processed.
functionis an instance of the lambda function to be called for element of given rows.

The lambda function function should be declared like follows:

auto function = [] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, const RealType& value )
{ ... };

The localIdx parameter is a rank of the non-zero element in given row.

◆ forRows() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::forRows ( IndexType begin,
IndexType end,
Function && function )

Method for parallel iteration over matrix rows from interval [begin, end).

In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method SparseMatrix::forElements where more than one thread can be mapped to each row.

Template Parameters
Functionis type of the lambda function.
Parameters
begindefines beginning of the range [begin, end) of rows to be processed.
enddefines ending of the range [begin, end) of rows to be processed.
functionis an instance of the lambda function to be called for each row.
auto function = [] __cuda_callable__ ( RowView& row ) { ... };

RowView represents matrix row - see TNL::Matrices::SparseMatrix::RowView.

◆ forRows() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::forRows ( IndexType begin,
IndexType end,
Function && function ) const

Method for parallel iteration over matrix rows from interval [begin, end) for constant instances.

In each row, given lambda function is performed. Each row is processed by at most one thread unlike the method SparseMatrix::forElements where more than one thread can be mapped to each row.

Template Parameters
Functionis type of the lambda function.
Parameters
begindefines beginning of the range [begin, end) of rows to be processed.
enddefines ending of the range [begin, end) of rows to be processed.
functionis an instance of the lambda function to be called for each row.
auto function = [] __cuda_callable__ ( const ConstRowView& row ) { ... };

ConstRowView represents matrix row - see TNL::Matrices::SparseMatrix::ConstRowView.

◆ getColumnIndexes() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
auto TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getColumnIndexes ( )

Getter of column indexes for nonconstant instances.

Returns
Reference to a vector with matrix elements column indexes.

◆ getColumnIndexes() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
auto TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getColumnIndexes ( ) const

Getter of segments for non-constant instances.

Segments are a structure for addressing the matrix elements columns and values. In fact, Segments represent the sparse matrix format.

Returns
Non-constant reference to segments.

Getter of segments for constant instances.

Segments are a structure for addressing the matrix elements columns and values. In fact, Segments represent the sparse matrix format.

Returns
Constant reference to segments.

Getter of column indexes for constant instances.

Returns
Constant reference to a vector with matrix elements column indexes.

◆ getColumns()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
__cuda_callable__ Index TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getColumns ( ) const

Returns number of matrix columns.

Returns
number of matrix columns.

◆ getCompressedRowLengths()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Vector >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getCompressedRowLengths ( Vector & rowLengths) const

Computes number of non-zeros in each row.

Parameters
rowLengthsis a vector into which the number of non-zeros in each row will be stored.

◆ getConstView()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
auto TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getConstView ( ) const

Returns a non-modifiable view of the sparse matrix.

See SparseSandboxMatrixView.

Returns
sparse matrix view.

◆ getElement()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
__cuda_callable__ auto TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getElement ( IndexType row,
IndexType column ) const

Returns value of matrix element at position given by its row and column index.

This method can be called from the host system (CPU) no matter where the matrix is allocated. If the matrix is allocated on GPU this method can be called even from device kernels. If the matrix is allocated in GPU device this method is called from CPU, it transfers values of each matrix element separately and so the performance is very low. For higher performance see. SparseMatrix::getRow or SparseMatrix::forElements and SparseMatrix::forAllElements.

Parameters
rowis a row index of the matrix element.
columni a column index of the matrix element.
Returns
value of given matrix element.

◆ getNonzeroElementsCount()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
Index TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getNonzeroElementsCount ( ) const

Returns number of non-zero matrix elements.

This method really counts the non-zero matrix elements and so it returns zero for matrix having all allocated elements set to zero.

Returns
number of non-zero matrix elements.

◆ getRow() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
__cuda_callable__ auto TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getRow ( const IndexType & rowIdx)

Non-constant getter of simple structure for accessing given matrix row.

Parameters
rowIdxis matrix row index.
Returns
RowView for accessing given matrix row.

See SparseMatrixRowView.

◆ getRow() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
__cuda_callable__ auto TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getRow ( const IndexType & rowIdx) const

Constant getter of simple structure for accessing given matrix row.

Parameters
rowIdxis matrix row index.
Returns
RowView for accessing given matrix row.

See SparseMatrixRowView.

◆ getRowCapacities()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Vector >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getRowCapacities ( Vector & rowCapacities) const

Compute capacities of all rows.

The row capacities are not stored explicitly and must be computed.

Parameters
rowCapacitiesis a vector where the row capacities will be stored.

◆ getRowCapacity()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
__cuda_callable__ Index TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getRowCapacity ( IndexType row) const

Returns capacity of given matrix row.

Parameters
rowindex of matrix row.
Returns
number of matrix elements allocated for the row.

◆ getRows()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
__cuda_callable__ Index TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getRows ( ) const

Returns number of matrix rows.

Returns
number of matrix row.

◆ getSerializationType()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
std::string TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getSerializationType ( )
static

Returns string with serialization type.

The string has a form Matrices::SparseSandboxMatrix< RealType, [any_device], IndexType, General/Symmetric, Format, [any_allocator] >.

Returns
String with the serialization type.

◆ getSerializationTypeVirtual()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
std::string TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getSerializationTypeVirtual ( ) const
overridevirtual

Returns string with serialization type.

See SparseSandboxMatrix::getSerializationType.

Returns
String with the serialization type.

Reimplemented from TNL::Object.

◆ getValues() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
auto TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getValues ( )

Returns a reference to a vector with the matrix elements values.

Returns
constant reference to a vector with the matrix elements values.

◆ getValues() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
auto TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getValues ( ) const

Returns a constant reference to a vector with the matrix elements values.

Returns
constant reference to a vector with the matrix elements values.

◆ getView()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
auto TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::getView ( )

Returns a modifiable view of the sparse matrix.

See SparseSandboxMatrixView.

Returns
sparse matrix view.

◆ isBinary()

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
static constexpr bool TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::isBinary ( )
inlinestaticconstexpr

Test of binary matrix type.

Returns
true if the matrix is stored as binary and false otherwise.

◆ isSymmetric()

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
static constexpr bool TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::isSymmetric ( )
inlinestaticconstexpr

Test of symmetric matrix type.

Returns
true if the matrix is stored as symmetric and false otherwise.

◆ load() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::load ( const String & fileName)

Method for loading the matrix from the file with given filename.

Parameters
fileNameis name of the file.

◆ load() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::load ( File & file)
overridevirtual

Method for loading the matrix from a file.

Parameters
fileis the input file.

Reimplemented from TNL::Object.

◆ operator!=()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Matrix >
bool TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::operator!= ( const Matrix & matrix) const

Comparison operator with another arbitrary matrix type.

Parameters
matrixis the right-hand side matrix.
Returns
true if the RHS matrix is equal, false otherwise.

◆ operator=() [1/4]

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
template<typename Real_ , typename Device_ , typename Index_ , ElementsOrganization Organization, typename RealAllocator_ >
SparseSandboxMatrix & TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::operator= ( const DenseMatrix< Real_, Device_, Index_, Organization, RealAllocator_ > & matrix)

Assignment of dense matrix.

Parameters
matrixis input matrix for the assignment.
Returns
reference to this matrix.

◆ operator=() [2/4]

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
template<typename RHSMatrix >
SparseSandboxMatrix & TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::operator= ( const RHSMatrix & matrix)

Assignment of any matrix type other then this and dense.

Warning: Assignment of symmetric sparse matrix to general sparse matrix does not give correct result, currently. Only the diagonal and the lower part of the matrix is assigned.

Parameters
matrixis input matrix for the assignment.
Returns
reference to this matrix.

◆ operator=() [3/4]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator > & TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::operator= ( const SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator > & matrix)

Assignment of exactly the same matrix type.

Parameters
matrixis input matrix for the assignment.
Returns
reference to this matrix.

◆ operator=() [4/4]

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
template<typename Device_ >
SparseSandboxMatrix & TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::operator= ( const SparseSandboxMatrix< RealType, Device_, IndexType, MatrixType, RealAllocator, IndexAllocator > & matrix)

Assignment of exactly the same matrix type but different device.

Parameters
matrixis input matrix for the assignment.
Returns
reference to this matrix.

◆ operator==()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Matrix >
bool TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::operator== ( const Matrix & matrix) const

Comparison operator with another arbitrary matrix type.

Parameters
matrixis the right-hand side matrix.
Returns
true if the RHS matrix is equal, false otherwise.

◆ print()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::print ( std::ostream & str) const

Method for printing the matrix to output stream.

Parameters
stris the output stream.

◆ reduceAllRows()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::reduceAllRows ( Fetch & fetch,
const Reduce & reduce,
Keep & keep,
const FetchReal & zero ) const

Method for performing general reduction on all matrix rows for constant instances.

Template Parameters
Fetchis a type of lambda function for data fetch declared as fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue. The return type of this lambda can be any non void.
Reduceis a type of lambda function for reduction declared as reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue.
Keepis a type of lambda function for storing results of reduction in each row. It is declared as keep( const IndexType rowIdx, const double& value ).
FetchValueis type returned by the Fetch lambda function.
Parameters
fetchis an instance of lambda function for data fetch.
reduceis an instance of lambda function for reduction.
keepin an instance of lambda function for storing results.
zerois the identity element of given reduction operation.

◆ reduceRows()

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::reduceRows ( IndexType begin,
IndexType end,
Fetch & fetch,
const Reduce & reduce,
Keep & keep,
const FetchReal & zero ) const

Method for performing general reduction on matrix rows for constant instances.

Template Parameters
Fetchis a type of lambda function for data fetch declared as fetch( IndexType rowIdx, IndexType& columnIdx, RealType& elementValue ) -> FetchValue. The return type of this lambda can be any non void.
Reduceis a type of lambda function for reduction declared as reduce( const FetchValue& v1, const FetchValue& v2 ) -> FetchValue.
Keepis a type of lambda function for storing results of reduction in each row. It is declared as keep( const IndexType rowIdx, const double& value ).
FetchValueis type returned by the Fetch lambda function.
Parameters
begindefines beginning of the range [begin, end) of rows to be processed.
enddefines ending of the range [begin, end) of rows to be processed.
fetchis an instance of lambda function for data fetch.
reduceis an instance of lambda function for reduction.
keepin an instance of lambda function for storing results.
zerois the identity element of given reduction operation.

◆ save() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::save ( const String & fileName) const

Method for saving the matrix to the file with given filename.

Parameters
fileNameis name of the file.

◆ save() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::save ( File & file) const
overridevirtual

Method for saving the matrix to a file.

Parameters
fileis the output file.

Reimplemented from TNL::Object.

◆ sequentialForAllRows() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::sequentialForAllRows ( Function & function)

This method calls sequentialForRows for all matrix rows.

See SparseMatrix::sequentialForAllRows.

Template Parameters
Functionis a type of lambda function that will operate on matrix elements.
Parameters
functionis an instance of the lambda function to be called in each row.

◆ sequentialForAllRows() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::sequentialForAllRows ( Function & function) const

This method calls sequentialForRows for all matrix rows (for constant instances).

See SparseMatrix::sequentialForRows.

Template Parameters
Functionis a type of lambda function that will operate on matrix elements.
Parameters
functionis an instance of the lambda function to be called in each row.

◆ sequentialForRows() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::sequentialForRows ( IndexType begin,
IndexType end,
Function & function )

Method for sequential iteration over all matrix rows for non-constant instances.

Template Parameters
Functionis type of lambda function that will operate on matrix elements. It should have form like function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value ). The column index repeats twice only for compatibility with sparse matrices.
Parameters
begindefines beginning of the range [begin,end) of rows to be processed.
enddefines ending of the range [begin,end) of rows to be processed.
functionis an instance of the lambda function to be called in each row.

◆ sequentialForRows() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::sequentialForRows ( IndexType begin,
IndexType end,
Function & function ) const

Method for sequential iteration over all matrix rows for constant instances.

Template Parameters
Functionis type of lambda function that will operate on matrix elements. It should have form like function( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, const RealType& value ). The column index repeats twice only for compatibility with sparse matrices.
Parameters
begindefines beginning of the range [begin,end) of rows to be processed.
enddefines ending of the range [begin,end) of rows to be processed.
functionis an instance of the lambda function to be called in each row.

◆ setDimensions()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::setDimensions ( IndexType rows,
IndexType columns )

Set number of rows and columns of this matrix.

Parameters
rowsis the number of matrix rows.
columnsis the number of matrix columns.

◆ setElement()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
__cuda_callable__ void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::setElement ( IndexType row,
IndexType column,
const RealType & value )

Sets element at given row and column to given value.

This method can be called from the host system (CPU) no matter where the matrix is allocated. If the matrix is allocated on GPU this method can be called even from device kernels. If the matrix is allocated in GPU device this method is called from CPU, it transfers values of each matrix element separately and so the performance is very low. For higher performance see. SparseMatrix::getRow or SparseMatrix::forElements and SparseMatrix::forAllElements. The call may fail if the matrix row capacity is exhausted.

Parameters
rowis row index of the element.
columnis columns index of the element.
valueis the value the element will be set to.

◆ setElements() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::setElements ( const std::initializer_list< std::tuple< IndexType, IndexType, RealType > > & data)

This method sets the sparse matrix elements from initializer list.

The number of matrix rows and columns must be set already. The matrix elements values are given as a list data of triples: { { row1, column1, value1 }, { row2, column2, value2 }, ... }.

Parameters
datais a initializer list of initializer lists representing list of matrix rows.

◆ setElements() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename MapIndex , typename MapValue >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::setElements ( const std::map< std::pair< MapIndex, MapIndex >, MapValue > & map)

This method sets the sparse matrix elements from std::map.

The matrix elements values are given as a map data where keys are std::pair of matrix coordinates ( {row, column} ) and value is the matrix element value.

Template Parameters
MapIndexis a type for indexing rows and columns.
MapValueis a type for matrix elements values in the map.
Parameters
mapis std::map containing matrix elements.

◆ setLike()

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
template<typename Matrix >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::setLike ( const Matrix & matrix)

Set the number of matrix rows and columns by the given matrix.

Template Parameters
Matrixis matrix type. This can be any matrix having methods getRows and getColumns.
Parameters
matrixin the input matrix dimensions of which are to be adopted.

◆ setRowCapacities()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename RowCapacitiesVector >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::setRowCapacities ( const RowCapacitiesVector & rowCapacities)

Allocates memory for non-zero matrix elements.

The size of the input vector must be equal to the number of matrix rows. The number of allocated matrix elements for each matrix row depends on the sparse matrix format. Some formats may allocate more elements than required.

Template Parameters
RowCapacitiesVectoris a type of vector/array used for row capacities setting.
Parameters
rowCapacitiesis a vector telling the number of required non-zero matrix elements in each row.

◆ vectorProduct()

template<typename Real , typename Device , typename Index , typename MatrixType , typename RealAllocator , typename IndexAllocator >
template<typename InVector , typename OutVector >
void TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::vectorProduct ( const InVector & inVector,
OutVector & outVector,
RealType matrixMultiplicator = 1.0,
RealType outVectorMultiplicator = 0.0,
IndexType begin = 0,
IndexType end = 0 ) const

Computes product of matrix and vector.

More precisely, it computes:

outVector = matrixMultiplicator * ( * this ) * inVector + outVectorMultiplicator * outVector

Template Parameters
InVectoris type of input vector. It can be TNL::Containers::Vector, TNL::Containers::VectorView, TNL::Containers::Array, TNL::Containers::ArrayView, or similar container.
OutVectoris type of output vector. It can be TNL::Containers::Vector, TNL::Containers::VectorView, TNL::Containers::Array, TNL::Containers::ArrayView, or similar container.
Parameters
inVectoris input vector.
outVectoris output vector.
matrixMultiplicatoris a factor by which the matrix is multiplied. It is one by default.
outVectorMultiplicatoris a factor by which the outVector is multiplied before added to the result of matrix-vector product. It is zero by default.
beginis the beginning of the rows range for which the vector product is computed. It is zero by default.
endis the end of the rows range for which the vector product is computed. It is number if the matrix rows by default.

Member Data Documentation

◆ rowPointers

template<typename Real = double, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >>
RowPointers TNL::Matrices::Sandbox::SparseSandboxMatrix< Real, Device, Index, MatrixType, RealAllocator, IndexAllocator >::rowPointers
protected

Container for CSR row pointers.

SANDBOX_TODO: You may replace it with containers and metadata required by you format.


The documentation for this class was generated from the following files: