Template Numerical Library: TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView > Class Template Reference

Template Numerical Library version\ main:c7077e4fd

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
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 (SegmentViewType segmentView, 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__ RealType & | getValue (IndexType column)
| Returns non-constants reference to an element with given column index.
__cuda_callable__ const RealType & | getValue (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

  SegmentView | is a segment view of segments representing the matrix format.
  ValuesView | is 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;
  TNL::Matrices::DenseMatrix< double, Device > matrix( size, size );
  /***
  * 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 << '\n';
  }
  int
  main( int argc, char* argv[] )
  {
  std::cout << "Getting matrix rows on host:\n";
  getRowExample< TNL::Devices::Host >();
  #ifdef __CUDACC__
  std::cout << "Getting matrix rows on CUDA device:\n";
  getRowExample< TNL::Devices::Cuda >();
  #endif
  }
  __cuda_callable__
  #define __cuda_callable__
  Definition Macros.h:49
  std::cout
  TNL::Matrices::DenseMatrix
  Implementation of dense matrix, i.e. matrix storing explicitly all of its elements including zeros.
  Definition DenseMatrix.h:31
  TNL::Algorithms::parallelFor
  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

## Constructor & Destructor Documentation

## ◆ DenseMatrixRowView()

template<typename SegmentView, typename ValuesView>

__cuda_callable__ TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::DenseMatrixRowView | ( | SegmentViewType | segmentView,
|  | ValuesViewType | values )

Constructor with segmentView and values.

Parameters

  segmentView | instance of SegmentViewType representing matrix row.
  values | is a container view for storing the matrix elements values.

## Member Function Documentation

## ◆ begin()

template<typename SegmentView, typename ValuesView>

__cuda_callable__ IteratorType 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__ ConstIteratorType 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__ ConstIteratorType 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__ IteratorType 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__ IndexType TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::getColumnIndex | ( | IndexType | localIdx | ) | const
| nodiscard

This method is only for compatibility with sparse matrix row.

Parameters

  localIdx | is 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__ IndexType 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__ IndexType 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__ RealType & TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::getValue | ( | IndexType | column | ) |
| nodiscard

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

Parameters

  column | is 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__ const RealType & TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::getValue | ( | IndexType | column | ) | const
| nodiscard

Returns constants reference to an element with given column index.

Parameters

  column | is 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

  localIdx | is here only for compatibility with the sparse matrices and it is unused.
  column | is a column index of the matrix element.
  value | is 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

  column | is a column index of the matrix element.
  value | is a value the matrix element will be set to.

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

- src/TNL/Matrices/DenseMatrixRowView.h