Template Numerical Library version\ main:c173bea
Loading...
Searching...
No Matches
TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView > Class Template Reference

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

#include <TNL/Matrices/DenseMatrixRowView.h>

Public Types

using ConstIteratorType = MatrixRowViewIterator< ConstRowView >
 Type of constant iterator for the matrix row.
 
using ConstRowView = DenseMatrixRowView< SegmentView, ConstValuesViewType >
 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 IndexType = typename SegmentView::IndexType
 The type used for matrix elements indexing.
 
using IteratorType = MatrixRowViewIterator< RowView >
 Type of iterator for the matrix row.
 
using MatrixElementType = DenseMatrixElement< RealType, IndexType >
 The type of related matrix element.
 
using RealType = typename ValuesView::RealType
 The type of matrix elements.
 
using RowView = DenseMatrixRowView< SegmentView, ValuesViewType >
 Type of dense matrix row view.
 
using SegmentViewType = SegmentView
 Type representing matrix row format.
 
using ValuesViewType = ValuesView
 Type of container view used for storing matrix elements values.
 

Public Member Functions

__cuda_callable__ DenseMatrixRowView (const SegmentViewType &segmentView, const ValuesViewType &values)
 Constructor with segmentView and values.
 
__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__ IndexType getColumnIndex (IndexType localIdx) const
 This method is only for compatibility with sparse 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__ RealTypegetValue (IndexType column)
 Returns non-constants reference to an element with given column index.
 
__cuda_callable__ const RealTypegetValue (IndexType column) const
 Returns constants reference to an element with given column index.
 
__cuda_callable__ void setElement (IndexType localIdx, IndexType column, const RealType &value)
 Sets value of matrix element with given column index.
 
__cuda_callable__ void setValue (IndexType column, const RealType &value)
 Sets value of matrix element with given column index.
 

Protected Attributes

SegmentViewType segmentView
 
ValuesViewType values
 

Detailed Description

template<typename SegmentView, typename ValuesView>
class TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >

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

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

See DenseMatrix and DenseMatrixView.

Example
#include <iostream>
#include <TNL/Algorithms/parallelFor.h>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
getRowExample()
{
const int size = 5;
/***
* Create dense matrix view which can be captured by the following lambda
* function.
*/
auto matrixView = matrix.getView();
auto f = [ = ] __cuda_callable__( int rowIdx ) mutable
{
auto row = matrixView.getRow( rowIdx );
if( rowIdx > 0 )
row.setValue( rowIdx - 1, -1.0 );
row.setValue( rowIdx, rowIdx + 1.0 );
if( rowIdx < size - 1 )
row.setValue( rowIdx + 1, -1.0 );
};
/***
* Set the matrix elements.
*/
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
Implementation of dense matrix, i.e. matrix storing explicitly all of its elements including zeros.
Definition DenseMatrix.h:31
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:1 1:-1 2:0 3:0 4:0
Row: 1 -> 0:-1 1:2 2:-1 3:0 4:0
Row: 2 -> 0:0 1:-1 2:3 3:-1 4:0
Row: 3 -> 0:0 1:0 2:-1 3:4 4:-1
Row: 4 -> 0:0 1:0 2:0 3:-1 4:5
Getting matrix rows on CUDA device:
Row: 0 -> 0:1 1:-1 2:0 3:0 4:0
Row: 1 -> 0:-1 1:2 2:-1 3:0 4:0
Row: 2 -> 0:0 1:-1 2:3 3:-1 4:0
Row: 3 -> 0:0 1:0 2:-1 3:4 4:-1
Row: 4 -> 0:0 1:0 2:0 3:-1 4:5

Constructor & Destructor Documentation

◆ DenseMatrixRowView()

template<typename SegmentView , typename ValuesView >
__cuda_callable__ TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::DenseMatrixRowView ( const SegmentViewType & segmentView,
const ValuesViewType & values )

Constructor with segmentView and values.

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

Member Function Documentation

◆ begin()

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

Returns iterator pointing at the beginning of the matrix row.

Returns
iterator pointing at the beginning.

◆ cbegin()

template<typename SegmentView , typename ValuesView >
__cuda_callable__ auto TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::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 >
__cuda_callable__ auto TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::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 >
__cuda_callable__ auto TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::end ( )
nodiscard

Returns iterator pointing at the end of the matrix row.

Returns
iterator pointing at the end.

◆ getColumnIndex()

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

This method is only for compatibility with sparse matrix row.

Parameters
localIdxis the rank of the matrix element in given row.
Returns
the value of localIdx as column index.

◆ getRowIndex()

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

Returns the matrix row index.

Returns
matrix row index.

◆ getSize()

template<typename SegmentView , typename ValuesView >
__cuda_callable__ auto TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::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 >
__cuda_callable__ auto TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::getValue ( IndexType column)
nodiscard

Returns non-constants reference to an element with given column index.

Parameters
columnis a column index of the matrix element.
Returns
non-constant reference to the matrix element.

◆ getValue() [2/2]

template<typename SegmentView , typename ValuesView >
__cuda_callable__ auto TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::getValue ( IndexType column) const
nodiscard

Returns constants reference to an element with given column index.

Parameters
columnis column index of the matrix element.
Returns
constant reference to the matrix element.

◆ setElement()

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

Sets value of matrix element with given column index.

Parameters
localIdxis here only for compatibility with the sparse matrices and it is unused.
columnis a column index of the matrix element.
valueis a value the matrix element will be set to.

◆ setValue()

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

Sets value of matrix element with given column index.

Parameters
columnis a column index of the matrix element.
valueis a value the matrix element will be set to.

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