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

Implementation of sparse sandbox matrix view. More...

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

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

Public Types

using ColumnsIndexesViewType
 
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 IndexType = Index
 The type used for matrix elements indexing.
 
using RealType = Real
 The type of matrix elements.
 
using RowCapacitiesView = Containers::VectorView< Index, Device, Index >
 
using RowPointersView
 Type of container view 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>
using Self = SparseSandboxMatrixView< _Real, _Device, _Index, _MatrixType >
 Helper type for getting self type or its modifications.
 
using ValuesViewType = typename BaseType::ValuesViewType
 
using ViewType = SparseSandboxMatrixView< Real, Device, Index, MatrixType >
 Templated type of segments view, i.e. sparse matrix format.
 
- Public Types inherited from TNL::Matrices::MatrixBase< Real, Device, Index, MatrixType, Organization >
using ConstValuesViewType = typename ValuesViewType::ConstViewType
 Type of constant vector view holding values of matrix elements.
 
using DeviceType = Device
 The device where the matrix is allocated.
 
using IndexType = Index
 The type used for matrix elements indexing.
 
using RealType = std::remove_const_t< Real >
 The type of matrix elements.
 
using RowCapacitiesType = Containers::Vector< Index, Device, Index >
 
using ValuesViewType = Containers::VectorView< Real, Device, Index >
 Type of vector view holding values of matrix elements.
 

Public Member Functions

__cuda_callable__ SparseSandboxMatrixView ()
 Constructor with no parameters.
 
__cuda_callable__ SparseSandboxMatrixView (const SparseSandboxMatrixView &matrix)=default
 Copy constructor.
 
__cuda_callable__ SparseSandboxMatrixView (IndexType rows, IndexType columns, const ValuesViewType &values, const ColumnsIndexesViewType &columnIndexes, const RowPointersView &rowPointers)
 Constructor with all necessary data and views.
 
__cuda_callable__ SparseSandboxMatrixView (SparseSandboxMatrixView &&matrix) noexcept=default
 Move constructor.
 
__cuda_callable__ void addElement (IndexType row, IndexType column, const RealType &value, const RealType &thisElementMultiplicator=1.0)
 Add element at given row and column to given value.
 
__cuda_callable__ void bind (SparseSandboxMatrixView &&view)
 Method for rebinding (reinitialization) using another matrix view.
 
__cuda_callable__ void bind (SparseSandboxMatrixView &view)
 Method for rebinding (reinitialization) using another matrix view.
 
template<typename Function >
void forAllElements (Function &function)
 This method calls forElements for all matrix rows.
 
template<typename Function >
void forAllElements (Function &function) const
 This method calls forElements for all matrix rows (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 iteration over all matrix rows for non-constant instances.
 
template<typename Function >
void forElements (IndexType begin, IndexType end, Function &function) const
 Method for iteration over all matrix 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.
 
ColumnsIndexesViewTypegetColumnIndexes ()
 Getter of column indexes for nonconstant instances.
 
const ColumnsIndexesViewTypegetColumnIndexes () const
 Getter of segments for non-constant instances.
 
template<typename Vector >
void getCompressedRowLengths (Vector &rowLengths) const
 Computes number of non-zeros in each row.
 
__cuda_callable__ 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 override
 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.
 
std::string getSerializationTypeVirtual () const
 Returns string with serialization type.
 
__cuda_callable__ ViewType getView ()
 Returns a modifiable view of the sparse matrix.
 
template<typename Matrix >
bool operator!= (const Matrix &matrix) const
 Comparison operator with another arbitrary matrix type.
 
SparseSandboxMatrixViewoperator= (const SparseSandboxMatrixView &)=delete
 Copy-assignment operator.
 
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
 
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.
 
__cuda_callable__ void setElement (IndexType row, IndexType column, const RealType &value)
 Sets element at given row and column to given value.
 
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::Matrices::MatrixBase< Real, Device, Index, MatrixType, Organization >
__cuda_callable__ MatrixBase ()=default
 Basic constructor with no parameters.
 
__cuda_callable__ MatrixBase (const MatrixBase &view)=default
 Shallow copy constructor.
 
__cuda_callable__ MatrixBase (IndexType rows, IndexType columns, ValuesViewType values)
 Constructor with matrix dimensions and matrix elements values.
 
__cuda_callable__ MatrixBase (MatrixBase &&view) noexcept=default
 Move constructor.
 
IndexType getAllocatedElementsCount () const
 Tells the number of allocated matrix elements.
 
__cuda_callable__ IndexType getColumns () const
 Returns number of matrix columns.
 
__cuda_callable__ IndexType getRows () const
 Returns number of matrix rows.
 
__cuda_callable__ ValuesViewTypegetValues ()
 Returns a reference to a vector with the matrix elements values.
 
__cuda_callable__ const ValuesViewTypegetValues () const
 Returns a constant reference to a vector with the matrix elements values.
 
template<typename Matrix >
bool operator!= (const Matrix &matrix) const
 Comparison operator with another arbitrary matrix view type.
 
template<typename MatrixT >
bool operator!= (const MatrixT &matrix) const
 
__cuda_callable__ MatrixBaseoperator= (const MatrixBase &)=delete
 Copy-assignment operator.
 
__cuda_callable__ MatrixBaseoperator= (MatrixBase &&)=delete
 Move-assignment operator.
 
template<typename Matrix >
bool operator== (const Matrix &matrix) const
 Comparison operator with another arbitrary matrix view type.
 
template<typename MatrixT >
bool operator== (const MatrixT &matrix) const
 

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::Matrices::MatrixBase< Real, Device, Index, MatrixType, Organization >
static constexpr ElementsOrganization getOrganization ()
 Matrix elements organization getter.
 
static constexpr bool isBinary ()
 Test of binary matrix type.
 
static constexpr bool isMatrix ()
 Test of matrix type.
 
static constexpr bool isSymmetric ()
 Test of symmetric matrix type.
 

Protected Attributes

ColumnsIndexesViewType columnIndexes
 
RowPointersView rowPointers
 
- Protected Attributes inherited from TNL::Matrices::MatrixBase< Real, Device, Index, MatrixType, Organization >
IndexType columns = 0
 
IndexType rows = 0
 
ValuesViewType values
 

Additional Inherited Members

- Protected Member Functions inherited from TNL::Matrices::MatrixBase< Real, Device, Index, MatrixType, Organization >
__cuda_callable__ void bind (IndexType rows, IndexType columns, ValuesViewType values)
 Re-initializes the internal attributes of the base class.
 

Detailed Description

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
class TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >

Implementation of sparse sandbox matrix view.

It serves as an accessor to SparseSandboxMatrix for example when passing the matrix to lambda functions. SparseSandboxMatrix view can be also created in CUDA kernels.

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.
Segmentsis a structure representing the sparse matrix format. Depending on the pattern of the non-zero elements different matrix formats can perform differently especially on GPUs. By default Algorithms::Segments::CSR format is used. See also Algorithms::Segments::Ellpack, Algorithms::Segments::SlicedEllpack, Algorithms::Segments::ChunkedEllpack, and Algorithms::Segments::BiEllpack.
ComputeRealis the same as Real mostly but for binary matrices it is set to Index type. This can be changed bu the user, of course.

Member Typedef Documentation

◆ ColumnsIndexesViewType

template<typename Real , typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
using TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::ColumnsIndexesViewType
Initial value:
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

◆ RowPointersView

template<typename Real , typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
using TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::RowPointersView
Initial value:
VectorView extends ArrayView with algebraic operations.
Definition VectorView.h:24
Device DeviceType
The device where the matrix is allocated.
Definition SparseSandboxMatrixView.h:96
Index IndexType
The type used for matrix elements indexing.
Definition SparseSandboxMatrixView.h:101

Type of container view for CSR row pointers.

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

◆ ViewType

template<typename Real , typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
using TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::ViewType = SparseSandboxMatrixView< Real, Device, Index, MatrixType >

Templated type of segments view, i.e. sparse matrix format.

Type of segments view used by this matrix. It represents the sparse matrix format.

Type of related matrix view.

Constructor & Destructor Documentation

◆ SparseSandboxMatrixView() [1/3]

template<typename Real , typename Device , typename Index , typename MatrixType >
__cuda_callable__ TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::SparseSandboxMatrixView ( IndexType rows,
IndexType columns,
const ValuesViewType & values,
const ColumnsIndexesViewType & columnIndexes,
const RowPointersView & rowPointers )

Constructor with all necessary data and views.

Parameters
rowsis a number of matrix rows.
columnsis a number of matrix columns.
valuesis a vector view with matrix elements values.
columnIndexesis a vector view with matrix elements column indexes.
rowPointersis a container view with row pointers.

SANDBOX_TODO: Replace rowPointers with metadata by your needs.

◆ SparseSandboxMatrixView() [2/3]

template<typename Real , typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
__cuda_callable__ TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::SparseSandboxMatrixView ( const SparseSandboxMatrixView< Real, Device, Index, MatrixType > & matrix)
default

Copy constructor.

Parameters
matrixis an input sparse matrix view.

◆ SparseSandboxMatrixView() [3/3]

template<typename Real , typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
__cuda_callable__ TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::SparseSandboxMatrixView ( SparseSandboxMatrixView< Real, Device, Index, MatrixType > && matrix)
defaultnoexcept

Move constructor.

Parameters
matrixis an input sparse matrix view.

Member Function Documentation

◆ addElement()

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

Add element at given row and column to given value.

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

◆ bind() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType >
__cuda_callable__ void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::bind ( SparseSandboxMatrixView< Real, Device, Index, MatrixType > && view)

Method for rebinding (reinitialization) using another matrix view.

Parameters
viewThe matrix view to be bound.

◆ bind() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType >
__cuda_callable__ void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::bind ( SparseSandboxMatrixView< Real, Device, Index, MatrixType > & view)

Method for rebinding (reinitialization) using another matrix view.

Parameters
viewThe matrix view to be bound.

◆ forAllElements() [1/2]

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

This method calls forElements for all matrix rows.

See SparseSandboxMatrix::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 in each row.

◆ forAllElements() [2/2]

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

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

See SparseSandboxMatrix::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 in each row.

◆ forAllRows() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 SparseSandboxMatrixView::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 ) mutable { ... };
#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 RowView.

◆ forAllRows() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 SparseSandboxMatrixView::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 ConstRowView.

◆ forElements() [1/2]

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

Method for 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 localIdx, IndexType columnIdx, RealType& value ). The localIdx parameter is a rank of the non-zero element in given row.
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.

◆ forElements() [2/2]

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

Method for 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 localIdx, IndexType columnIdx, const RealType& value ). The localIdx parameter is a rank of the non-zero element in given row.
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.

◆ forRows() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 SparseSandboxMatrixView::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 ) mutable { ... };

RowView represents matrix row - see RowView.

◆ forRows() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 SparseSandboxMatrixView::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 ConstRowView.

◆ getColumnIndexes() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType >
auto TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 >
auto TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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.

◆ getCompressedRowLengths()

template<typename Real , typename Device , typename Index , typename MatrixType >
template<typename Vector >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 >
__cuda_callable__ auto TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::getConstView ( ) const

Returns a non-modifiable view of the sparse matrix.

Returns
sparse matrix view.

◆ getElement()

template<typename Real , typename Device , typename Index , typename MatrixType >
__cuda_callable__ auto TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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. SparseSandboxMatrix::getRow or SparseSandboxMatrix::forElements and SparseSandboxMatrix::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 >
Index TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::getNonzeroElementsCount ( ) const
overridevirtual

Returns number of non-zero matrix elements.

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

Returns
number of non-zero matrix elements.

Reimplemented from TNL::Matrices::MatrixBase< Real, Device, Index, MatrixType, Organization >.

◆ getRow() [1/2]

template<typename Real , typename Device , typename Index , typename MatrixType >
__cuda_callable__ auto TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 SparseSandboxMatrixRowView.

◆ getRow() [2/2]

template<typename Real , typename Device , typename Index , typename MatrixType >
__cuda_callable__ auto TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 SparseSandboxMatrixRowView.

◆ getRowCapacities()

template<typename Real , typename Device , typename Index , typename MatrixType >
template<typename Vector >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 >
__cuda_callable__ Index TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::getRowCapacity ( IndexType row) const

Returns capacity of given matrix row.

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

◆ getSerializationType()

template<typename Real , typename Device , typename Index , typename MatrixType >
std::string TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 >
std::string TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::getSerializationTypeVirtual ( ) const

Returns string with serialization type.

See SparseSandboxMatrix::getSerializationType.

Returns
String with the serialization type.

◆ getView()

template<typename Real , typename Device , typename Index , typename MatrixType >
__cuda_callable__ auto TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::getView ( )

Returns a modifiable view of the sparse matrix.

Returns
sparse matrix view.

◆ isBinary()

template<typename Real , typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
static constexpr bool TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::isBinary ( )
inlinestaticconstexpr

Test of binary matrix type.

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

◆ isSymmetric()

template<typename Real , typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
static constexpr bool TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::isSymmetric ( )
inlinestaticconstexpr

Test of symmetric matrix type.

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

◆ operator!=()

template<typename Real , typename Device , typename Index , typename MatrixType >
template<typename Matrix >
bool TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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=()

template<typename Real , typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
SparseSandboxMatrixView & TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::operator= ( const SparseSandboxMatrixView< Real, Device, Index, MatrixType > & )
delete

Copy-assignment operator.

It is a deleted function, because matrix assignment in general requires reallocation.

◆ operator==()

template<typename Real , typename Device , typename Index , typename MatrixType >
template<typename Matrix >
bool TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 >
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 , typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix>
template<typename Fetch , typename Reduce , typename Keep , typename FetchReal >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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.

◆ sequentialForAllRows() [1/2]

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

This method calls sequentialForRows for all matrix rows.

See SparseSandboxMatrixView::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 >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::sequentialForAllRows ( Function & function) const

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

See SparseSandboxMatrixView::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 >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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 >
template<typename Function >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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.

◆ setElement()

template<typename Real , typename Device , typename Index , typename MatrixType >
__cuda_callable__ void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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. SparseSandboxMatrix::getRow or SparseSandboxMatrix::forElements and SparseSandboxMatrix::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.

◆ vectorProduct()

template<typename Real , typename Device , typename Index , typename MatrixType >
template<typename InVector , typename OutVector >
void TNL::Matrices::Sandbox::SparseSandboxMatrixView< Real, Device, Index, MatrixType >::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.

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