Template Numerical Library: TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > Class Template Reference

Template Numerical Library version\ main:0b2c40fb1

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > Class Template Reference

Implementation of sparse matrix view. More...

`#include <TNL/Matrices/SparseMatrixView.h>`

Inheritance diagram for TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >:
[legend]
Collaboration diagram for TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >:
[legend]

## Public Types
using | ConstViewType
| Matrix view type for constant instances.
template<typename Device_, typename Index_>
using | SegmentsViewTemplate = SegmentsView< Device_, Index_ >
| Templated type of segments view, i.e. sparse matrix format.
template<typename _Real = Real, typename _Device = Device, typename _Index = Index, typename _MatrixType = MatrixType, template< typename, typename > class _SegmentsView = SegmentsView, typename _ComputeReal = ComputeReal>
using | Self = SparseMatrixView< _Real, _Device, _Index, _MatrixType, _SegmentsView, _ComputeReal >
| Helper type for getting self type or its modifications.
using | ViewType
| Type of related matrix view.
Public Types inherited from TNL::Matrices::SparseMatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >, std::conditional_t< std::is_same_v< Real, bool >, int, Real > >
using | ColumnIndexesViewType
| Type of the container view for matrix element column indexes.
using | ComputeRealType
using | ConstRowView
| Type for accessing constant matrix rows.
using | DefaultSegmentsReductionKernel
| Type of the kernel used for parallel reductions on segments.
using | DeviceType
| The device where the matrix is allocated.
using | IndexType
| The type used for matrix elements indexing.
using | MatrixType
| The type of matrix - general or symmetric.
using | RealType
| The type of matrix elements.
using | RowView
| Type for accessing matrix rows.
using | SegmentsViewType
| Type of segments view used by this matrix. It represents the sparse matrix format.
Public Types inherited from TNL::Matrices::MatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >::getOrganization() >
using | ConstValuesViewType
| Type of constant vector view holding values of matrix elements.
using | DeviceType
| The device where the matrix is allocated.
using | IndexType
| The type used for matrix elements indexing.
using | RealType
| The type of matrix elements.
using | RowCapacitiesType
using | ValuesViewType
| Type of vector view holding values of matrix elements.

## Public Member Functions
__cuda_callable__ | SparseMatrixView ()=default
| Constructor with no parameters.
__cuda_callable__ | SparseMatrixView (const SparseMatrixView &matrix)=default
| Copy constructor.
__cuda_callable__ | SparseMatrixView (Index rows, Index columns, typename Base::ValuesViewType values, typename Base::ColumnIndexesViewType columnIndexes, typename Base::SegmentsViewType segments)
| Constructor with all necessary data and views.
__cuda_callable__ | SparseMatrixView (SparseMatrixView &&matrix) noexcept=default
| Move constructor.
__cuda_callable__ void | bind (SparseMatrixView &&view)
| Method for rebinding (reinitialization) using another sparse matrix view.
__cuda_callable__ void | bind (SparseMatrixView &view)
| Method for rebinding (reinitialization) using another sparse matrix view.
__cuda_callable__ ConstViewType | getConstView () const
| Returns a non-modifiable view of the sparse matrix.
__cuda_callable__ ViewType | getView ()
| Returns a modifiable view of the sparse matrix.
SparseMatrixView & | operator= (const SparseMatrixView &)=delete
| Copy-assignment operator.
Public Member Functions inherited from TNL::Matrices::SparseMatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >, std::conditional_t< std::is_same_v< Real, bool >, int, Real > >
__cuda_callable__ | SparseMatrixBase ()=default
| Constructor with no parameters.
__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__ IndexType | findElement (IndexType row, IndexType column) const
| Finds element in the matrix and returns its position in the arrays with values and columnIndexes.
void | forAllElements (Function &&function) const
| This method calls forElements for all matrix matrix elements (for constant instances).
void | forAllElementsIf (Condition &&condition, Function &&function) const
| This method calls forElementsIf for all matrix rows (for constant instances).
void | forAllRows (Function &&function)
| Method for parallel iteration over all matrix rows.
void | forElements (IndexType begin, IndexType end, Function &&function) const
| Method for iteration over all matrix elements for (constant instances).
void | forElementsIf (IndexType begin, IndexType end, Condition &&condition, Function &&function) const
| Method for iterating over all matrix elements that meet a condition based on the row index (for constant instances).
void | forRows (IndexType begin, IndexType end, Function &&function)
| Method for parallel iteration over matrix rows from interval [begin, end).
__cuda_callable__ const ColumnIndexesViewType & | getColumnIndexes () const
| Getter of column indexes for constant instances.
void | getCompressedRowLengths (Vector &rowLengths) const
| Computes number of non-zeros in each row.
__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__ ConstRowView | getRow (IndexType rowIdx) const
| Constant getter of simple structure for accessing given matrix row.
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__ SegmentsViewType & | getSegments ()
| Getter of segments for non-constant instances.
bool | operator!= (const Matrix &matrix) const
| Comparison operator with another arbitrary matrix type.
SparseMatrixBase & | operator= (const SparseMatrixBase &)=delete
| Copy-assignment operator.
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.
void | reduceAllRows (Fetch &&fetch, const Reduce &reduce, Keep &&keep, const FetchValue &identity, const Algorithms::Segments::LaunchConfiguration &launchConfig=Algorithms::Segments::LaunchConfiguration{}) const
| Method for performing general reduction on all matrix rows for constant instances.
void | reduceRows (IndexType begin, IndexType end, Fetch &&fetch, const Reduce &reduce, Keep &&keep, const FetchValue &identity, const Algorithms::Segments::LaunchConfiguration &launchConfig=Algorithms::Segments::LaunchConfiguration{}) const
| Method for performing general reduction on matrix rows for constant instances.
void | sequentialForAllRows (Function &&function) const
| This method calls sequentialForRows for all matrix rows (for constant instances).
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.
void | sortColumnIndexes ()
| Sort matrix elements in each row by column indexes in ascending order.
void | transposedVectorProduct (const InVector &inVector, OutVector &outVector, std::conditional_t< std::is_same_v< Real, bool >, int, Real > matrixMultiplicator=1.0, std::conditional_t< std::is_same_v< Real, bool >, int, Real > outVectorMultiplicator=0.0, int begin=0, int end=0) const
| Computes product of transposed matrix and vector.
void | vectorProduct (const InVector &inVector, OutVector &outVector, ComputeRealType matrixMultiplicator=1.0, ComputeRealType outVectorMultiplicator=0.0, IndexType begin=0, IndexType end=0, const Algorithms::Segments::LaunchConfiguration &launchConfig=Algorithms::Segments::LaunchConfiguration{}) const
| Computes product of matrix and vector.
Public Member Functions inherited from TNL::Matrices::MatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >::getOrganization() >
__cuda_callable__ | MatrixBase ()=default
| Basic constructor with no parameters.
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__ const ValuesViewType & | getValues () const
| Returns a constant reference to a vector with the matrix elements values.
__cuda_callable__ MatrixBase & | operator= (const MatrixBase &)=delete
| Copy-assignment operator.

## Additional Inherited Members
Static Public Member Functions inherited from TNL::Matrices::SparseMatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >, std::conditional_t< std::is_same_v< Real, bool >, int, Real > >
static std::string | getSerializationType ()
| Returns string with serialization type.
Static Public Member Functions inherited from TNL::Matrices::MatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >::getOrganization() >
static constexpr ElementsOrganization | getOrganization ()
| Matrix elements organization getter.
static constexpr bool | isBinary ()
| Test of binary matrix type.
static constexpr bool | isSymmetric ()
| Test of symmetric matrix type.
Protected Member Functions inherited from TNL::Matrices::SparseMatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >, std::conditional_t< std::is_same_v< Real, bool >, int, Real > >
__cuda_callable__ void | bind (IndexType rows, IndexType columns, typename Base::ValuesViewType values, ColumnIndexesViewType columnIndexes, SegmentsViewType segments)
| Re-initializes the internal attributes of the base class.
Protected Member Functions inherited from TNL::Matrices::MatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >::getOrganization() >
__cuda_callable__ void | bind (IndexType rows, IndexType columns, ValuesViewType values)
| Re-initializes the internal attributes of the base class.
Protected Attributes inherited from TNL::Matrices::SparseMatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >, std::conditional_t< std::is_same_v< Real, bool >, int, Real > >
ColumnIndexesViewType | columnIndexes
SegmentsViewType | segments
Protected Attributes inherited from TNL::Matrices::MatrixBase< Real, Devices::Host, int, GeneralMatrix, std::conditional_t< std::is_const_v< Real >, Algorithms::Segments::CSRView< Devices::Host, int >::ConstViewType, Algorithms::Segments::CSRView< Devices::Host, int > >::getOrganization() >
IndexType | columns
IndexType | rows
ValuesViewType | values

## Detailed Description

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>
class TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >

Implementation of sparse matrix view.

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

Template Parameters

  Real | is 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).
  Device | is a device where the matrix is allocated.
  Index | is a type for indexing of the matrix elements.
  MatrixType | specifies 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.
  Segments | is 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.
  ComputeReal | is the same as Real mostly but for binary matrices it is set to Index type. This can be changed by the user, of course.

## Member Typedef Documentation

## ◆ ConstViewType

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

using TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::ConstViewType

Initial value:
SparseMatrixView<
std::add_const_t< Real >,
Device,
Index,
MatrixType,
SegmentsView,
ComputeReal >
TNL::Matrices::SparseMatrixBase< double, Devices::Host, int, GeneralMatrix, Algorithms::Segments::CSR< Devices::Host, int, typename Allocators::Default< Devices::Host >::template Allocator< int > >::ViewType, std::conditional_t< std::is_same_v< double, bool >, int, double > >::MatrixType
GeneralMatrix MatrixType
Definition SparseMatrixBase.h:91
TNL::Matrices::SparseMatrixView
Implementation of sparse matrix view.
Definition SparseMatrixView.h:59

Matrix view type for constant instances.

## ◆ ViewType

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

using TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::ViewType

Initial value:
SparseMatrixView<
Real,
Device,
Index,
MatrixType,
SegmentsView,
ComputeReal >

Type of related matrix view.

## Constructor & Destructor Documentation

## ◆ SparseMatrixView() [1/3]

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

__cuda_callable__ TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::SparseMatrixView | ( | Index | rows,
|  | Index | columns,
|  | typename Base::ValuesViewType | values,
|  | typename Base::ColumnIndexesViewType | columnIndexes,
|  | typename Base::SegmentsViewType | segments )

Constructor with all necessary data and views.

Parameters

  rows | is a number of matrix rows.
  columns | is a number of matrix columns.
  values | is a vector view with matrix elements values.
  columnIndexes | is a vector view with matrix elements column indexes.
  segments | is a segments view representing the sparse matrix format.

## ◆ SparseMatrixView() [2/3]

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

__cuda_callable__ TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::SparseMatrixView | ( | const SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > & | matrix | ) |
| default

Copy constructor.

Parameters

  matrix | is an input sparse matrix view.

## ◆ SparseMatrixView() [3/3]

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

__cuda_callable__ TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::SparseMatrixView | ( | SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > && | matrix | ) |
| defaultnoexcept

Move constructor.

Parameters

  matrix | is an input sparse matrix view.

## Member Function Documentation

## ◆ bind() [1/2]

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

__cuda_callable__ void TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::bind | ( | SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > && | view | ) |

Method for rebinding (reinitialization) using another sparse matrix view.

Parameters

  view | The sparse matrix view to be bound.

## ◆ bind() [2/2]

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

__cuda_callable__ void TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::bind | ( | SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > & | view | ) |

Method for rebinding (reinitialization) using another sparse matrix view.

Parameters

  view | The sparse matrix view to be bound.

## ◆ getConstView()

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

__cuda_callable__ ConstViewType TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::getConstView | ( |  | ) | const
| nodiscard

Returns a non-modifiable view of the sparse matrix.

Returns
  sparse matrix view.

## ◆ getView()

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

__cuda_callable__ ViewType TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::getView | ( |  | ) |
| nodiscard

Returns a modifiable view of the sparse matrix.

Returns
  sparse matrix view.

## ◆ operator=()

template<typename Real, typename Device = Devices::Host, typename Index = int, typename MatrixType = GeneralMatrix, template< typename Device_, typename Index_ > class SegmentsView = Algorithms::Segments::CSRView, typename ComputeReal = std::conditional_t< std::is_same_v< Real, bool >, Index, Real >>

SparseMatrixView & TNL::Matrices::SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal >::operator= | ( | const SparseMatrixView< Real, Device, Index, MatrixType, SegmentsView, ComputeReal > & |  | ) |
| delete

Copy-assignment operator.

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

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

- src/TNL/Matrices/SparseMatrixView.h