Template Numerical Library version\ main:4e58ea6
Loading...
Searching...
No Matches
TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView > Class Template Reference

RowView is a simple structure for accessing rows of sparse matrix. More...

#include <TNL/Matrices/SparseMatrixRowView.h>

Public Types

using ColumnsIndexesViewType = ColumnsIndexesView
 Type of container view used for storing the column indexes of the matrix elements.
 
using ConstColumnsIndexesViewType = typename ColumnsIndexesViewType::ConstViewType
 Type of constant container view used for storing the column indexes of the matrix elements.
 
using ConstIteratorType = MatrixRowViewIterator< ConstRowView >
 Type of constant iterator for the matrix row.
 
using ConstRowView = SparseMatrixRowView< SegmentViewType, ConstValuesViewType, ConstColumnsIndexesViewType >
 Type of constant sparse matrix row view.
 
using ConstValuesViewType = typename ValuesViewType::ConstViewType
 Type of constant container view used for storing the matrix elements values.
 
using GetValueConstResultType = std::conditional_t< isBinary(), bool, std::add_const_t< RealType >& >
 
using GetValueResultType = std::conditional_t< isBinary(), bool, RealType& >
 
using IndexType = typename ColumnsIndexesView::IndexType
 The type used for matrix elements indexing.
 
using IteratorType = MatrixRowViewIterator< RowView >
 Type of iterator for the matrix row.
 
using MatrixElementType = SparseMatrixElement< RealType, IndexType >
 The type of related matrix element.
 
using RealType = typename ValuesView::RealType
 The type of matrix elements.
 
using RowView = SparseMatrixRowView< SegmentViewType, ValuesViewType, ColumnsIndexesViewType >
 Type of sparse matrix row view.
 
using SegmentViewType = SegmentView
 Type representing matrix row format.
 
using ValuesViewType = ValuesView
 Type of container view used for storing the matrix elements values.
 

Public Member Functions

__cuda_callable__ SparseMatrixRowView (const SegmentViewType &segmentView, const ValuesViewType &values, const ColumnsIndexesViewType &columnIndexes)
 Constructor with segmentView, values and columnIndexes.
 
__cuda_callable__ IteratorType begin ()
 Returns iterator pointing at the beginning of the matrix row.
 
__cuda_callable__ ConstIteratorType cbegin () const
 Returns constant iterator pointing at the beginning of the matrix row.
 
__cuda_callable__ ConstIteratorType cend () const
 Returns constant iterator pointing at the end of the matrix row.
 
__cuda_callable__ IteratorType end ()
 Returns iterator pointing at the end of the matrix row.
 
__cuda_callable__ ColumnsIndexesViewType::ValueType & getColumnIndex (IndexType localIdx)
 Returns non-constants reference to a column index of an element with given rank in the row.
 
__cuda_callable__ const ColumnsIndexesViewType::ValueType & getColumnIndex (IndexType localIdx) const
 Returns constants reference to a column index of an element with given rank in the row.
 
__cuda_callable__ IndexType getGlobalIndex (IndexType localIdx) const
 Computes the global index of the matrix element with given rank in the matrix row.
 
__cuda_callable__ IndexType getRowIndex () const
 Returns the matrix row index.
 
__cuda_callable__ IndexType getSize () const
 Returns size of the matrix row, i.e. number of matrix elements in this row.
 
__cuda_callable__ auto getValue (IndexType localIdx) -> GetValueResultType
 Returns non-constants reference to value of an element with given rank in the row.
 
__cuda_callable__ auto getValue (IndexType localIdx) const -> GetValueConstResultType
 Returns constants reference to value of an element with given rank in the row.
 
template<typename _SegmentView , typename _ValuesView , typename _ColumnsIndexesView >
__cuda_callable__ bool operator== (const SparseMatrixRowView< _SegmentView, _ValuesView, _ColumnsIndexesView > &other) const
 Comparison of two matrix rows.
 
__cuda_callable__ void setColumnIndex (IndexType localIdx, const IndexType &columnIndex)
 Sets a column index of matrix element with given rank in the matrix row.
 
__cuda_callable__ void setElement (IndexType localIdx, IndexType columnIndex, const RealType &value)
 Sets both a value and a column index of matrix element with given rank in the matrix row.
 
__cuda_callable__ void setValue (IndexType localIdx, const RealType &value)
 Sets a value of matrix element with given rank in the matrix row.
 
__cuda_callable__ void sortColumnIndexes ()
 Sort the matrix row by column indexes in ascending order.
 

Static Public Member Functions

static constexpr bool isBinary ()
 Tells whether the parent matrix is a binary matrix.
 

Protected Attributes

ColumnsIndexesViewType columnIndexes
 
SegmentViewType segmentView
 
ValuesViewType values
 

Detailed Description

template<typename SegmentView, typename ValuesView, typename ColumnsIndexesView>
class TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >

RowView is a simple structure for accessing rows of sparse matrix.

Template Parameters
SegmentViewis a segment view of segments representing the matrix format.
ValuesViewis a vector view storing the matrix elements values.
ColumnsIndexesViewis a vector view storing the column indexes of the matrix element.

See SparseMatrixBase, SparseMatrix and SparseMatrixView.

Example
#include <iostream>
#include <TNL/Algorithms/parallelFor.h>
#include <TNL/Matrices/SparseMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
getRowExample()
{
/***
* Set the following matrix (dots represent zero matrix elements):
*
* / 2 . . . . \
* | 1 2 1 . . |
* | . 1 2 1. . |
* | . . 1 2 1 |
* \ . . . . 2 /
*/
const int size = 5;
TNL::Matrices::SparseMatrix< double, Device > matrix( { 1, 3, 3, 3, 1 }, size );
auto view = matrix.getView();
/***
* Set the matrix elements.
*/
auto f = [ = ] __cuda_callable__( int rowIdx ) mutable
{
auto row = view.getRow( rowIdx );
if( rowIdx == 0 )
row.setElement( 0, rowIdx, 2.0 ); // diagonal element
else if( rowIdx == size - 1 )
row.setElement( 0, rowIdx, 2.0 ); // diagonal element
else {
row.setElement( 0, rowIdx - 1, 1.0 ); // elements below the diagonal
row.setElement( 1, rowIdx, 2.0 ); // diagonal element
row.setElement( 2, rowIdx + 1, 1.0 ); // elements above the diagonal
}
};
TNL::Algorithms::parallelFor< Device >( 0, matrix.getRows(), f );
std::cout << matrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Getting matrix rows on host: " << std::endl;
getRowExample< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Getting matrix rows on CUDA device: " << std::endl;
getRowExample< TNL::Devices::Cuda >();
#endif
}
#define __cuda_callable__
Definition Macros.h:49
__cuda_callable__ ConstRowView getRow(IndexType rowIdx) const
Constant getter of simple structure for accessing given matrix row.
Definition SparseMatrixBase.hpp:130
Implementation of sparse matrix, i.e. matrix storing only non-zero elements.
Definition SparseMatrix.h:57
ViewType getView()
Returns a modifiable view of the sparse matrix.
Definition SparseMatrix.hpp:165
T endl(T... args)
std::enable_if_t< std::is_integral_v< Begin > &&std::is_integral_v< End > > parallelFor(const Begin &begin, const End &end, typename Device::LaunchConfiguration launch_config, Function f, FunctionArgs... args)
Parallel for-loop function for 1D range specified with integral values.
Definition parallelFor.h:41
Output
Getting matrix rows on host:
Row: 0 -> 0:2
Row: 1 -> 0:1 1:2 2:1
Row: 2 -> 1:1 2:2 3:1
Row: 3 -> 2:1 3:2 4:1
Row: 4 -> 4:2
Getting matrix rows on CUDA device:
Row: 0 -> 0:2
Row: 1 -> 0:1 1:2 2:1
Row: 2 -> 1:1 2:2 3:1
Row: 3 -> 2:1 3:2 4:1
Row: 4 -> 4:2

Constructor & Destructor Documentation

◆ SparseMatrixRowView()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::SparseMatrixRowView ( const SegmentViewType & segmentView,
const ValuesViewType & values,
const ColumnsIndexesViewType & columnIndexes )

Constructor with segmentView, values and columnIndexes.

Parameters
segmentViewinstance of SegmentViewType representing matrix row.
valuesis a container view for storing the matrix elements values.
columnIndexesis a container view for storing the column indexes of the matrix elements.

Member Function Documentation

◆ begin()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::begin ( )
nodiscard

Returns iterator pointing at the beginning of the matrix row.

Returns
iterator pointing at the beginning.

◆ cbegin()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::cbegin ( ) const
nodiscard

Returns constant iterator pointing at the beginning of the matrix row.

Returns
iterator pointing at the beginning.

◆ cend()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::cend ( ) const
nodiscard

Returns constant iterator pointing at the end of the matrix row.

Returns
iterator pointing at the end.

◆ end()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::end ( )
nodiscard

Returns iterator pointing at the end of the matrix row.

Returns
iterator pointing at the end.

◆ getColumnIndex() [1/2]

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::getColumnIndex ( IndexType localIdx)
nodiscard

Returns non-constants reference to a column index of an element with given rank in the row.

Parameters
localIdxis the rank of the non-zero element in given row.
Returns
non-constant reference to the matrix element column index.

◆ getColumnIndex() [2/2]

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::getColumnIndex ( IndexType localIdx) const
nodiscard

Returns constants reference to a column index of an element with given rank in the row.

Parameters
localIdxis the rank of the non-zero element in given row.
Returns
constant reference to the matrix element column index.

◆ getGlobalIndex()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::getGlobalIndex ( IndexType localIdx) const
nodiscard

Computes the global index of the matrix element with given rank in the matrix row.

Parameters
localIdxis the rank of the matrix element in the row.
Returns
global index of the matrix element.

◆ getRowIndex()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::getRowIndex ( ) const
nodiscard

Returns the matrix row index.

Returns
matrix row index.

◆ getSize()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::getSize ( ) const
nodiscard

Returns size of the matrix row, i.e. number of matrix elements in this row.

Returns
Size of the matrix row.

◆ getValue() [1/2]

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::getValue ( IndexType localIdx) -> GetValueResultType
nodiscard

Returns non-constants reference to value of an element with given rank in the row.

Parameters
localIdxis the rank of the non-zero element in given row.
Returns
non-constant reference to the matrix element value.

◆ getValue() [2/2]

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ auto TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::getValue ( IndexType localIdx) const -> GetValueConstResultType
nodiscard

Returns constants reference to value of an element with given rank in the row.

Parameters
localIdxis the rank of the non-zero element in given row.
Returns
constant reference to the matrix element value.

◆ isBinary()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
static constexpr bool TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::isBinary ( )
inlinestaticnodiscardconstexpr

Tells whether the parent matrix is a binary matrix.

Returns
true if the matrix is binary.

◆ operator==()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
template<typename _SegmentView , typename _ValuesView , typename _ColumnsIndexesView >
__cuda_callable__ bool TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::operator== ( const SparseMatrixRowView< _SegmentView, _ValuesView, _ColumnsIndexesView > & other) const
nodiscard

Comparison of two matrix rows.

The other matrix row can be from any other matrix.

Parameters
otheris another matrix row.
Returns
true if both rows are the same, false otherwise.

◆ setColumnIndex()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ void TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::setColumnIndex ( IndexType localIdx,
const IndexType & columnIndex )

Sets a column index of matrix element with given rank in the matrix row.

Parameters
localIdxis the rank of the matrix element in the row.
columnIndexis the new column index of the matrix element.

◆ setElement()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ void TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::setElement ( IndexType localIdx,
IndexType columnIndex,
const RealType & value )

Sets both a value and a column index of matrix element with given rank in the matrix row.

Parameters
localIdxis the rank of the matrix element in the row.
columnIndexis the new column index of the matrix element.
valueis the new value of the matrix element.

◆ setValue()

template<typename SegmentView , typename ValuesView , typename ColumnsIndexesView >
__cuda_callable__ void TNL::Matrices::SparseMatrixRowView< SegmentView, ValuesView, ColumnsIndexesView >::setValue ( IndexType localIdx,
const RealType & value )

Sets a value of matrix element with given rank in the matrix row.

Parameters
localIdxis the rank of the matrix element in the row.
valueis the new value of the matrix element.

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