Template Numerical Library: TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer > Class Template Reference

Template Numerical Library version\ main:16b9213d5

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer > Class Template Reference

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

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

## Public Types
using | ConstIteratorType = MatrixRowViewIterator< ConstRowView >
| Type of constant iterator for the matrix row.
using | ConstRowView = TridiagonalMatrixRowView< ConstValuesViewType, IndexerType >
| 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 | IndexerType = Indexer
| Type of object responsible for indexing and organization of matrix elements.
using | IndexType = typename ValuesView::IndexType
| The type used for matrix elements indexing.
using | IteratorType = MatrixRowViewIterator< RowView >
| Type of iterator for the matrix row.
using | MatrixElementType = MultidiagonalMatrixElement< RealType, IndexType >
| The type of related matrix element.
using | RealType = typename ValuesView::RealType
| The type of matrix elements.
using | RowView = TridiagonalMatrixRowView< ValuesViewType, IndexerType >
| Type of constant sparse matrix row view.
using | ValuesViewType = ValuesView
| Type of container view used for storing the matrix elements values.

## Public Member Functions
__cuda_callable__ | TridiagonalMatrixRowView (IndexType rowIdx, ValuesViewType values, IndexerType indexer)
| Constructor with all necessary data.
__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
| Computes column index of matrix element on given subdiagonal.
__cuda_callable__ IndexType | getRowIndex () const
| Returns the matrix row index.
__cuda_callable__ IndexType | getSize () const
| Returns number of diagonals of the tridiagonal matrix which is three.
__cuda_callable__ RealType & | getValue (IndexType localIdx)
| Returns value of matrix element on given subdiagonal.
__cuda_callable__ const RealType & | getValue (IndexType localIdx) const
| Returns value of matrix element on given subdiagonal.
__cuda_callable__ void | setElement (IndexType localIdx, const RealType &value)
| Changes value of matrix element on given subdiagonal.

## Protected Attributes
Indexer | indexer
IndexType | rowIdx
ValuesViewType | values

## Detailed Description

template<typename ValuesView, typename Indexer>
class TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >

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

Template Parameters

  ValuesView | is a vector view storing the matrix elements values.
  Indexer | is type of object responsible for indexing and organization of matrix elements.

See TridiagonalMatrix and TridiagonalMatrixView.

Example
  #include <iostream>
  #include <TNL/Algorithms/parallelFor.h>
  #include <TNL/Matrices/TridiagonalMatrix.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 and zeros are
  * padding zeros for memory alignment):
  *
  * 0 / 2 -1 . . . \ -> { 0, 0, 1 }
  * | -1 2 -1 . . | -> { 0, 2, 1 }
  * | . -1 2 -1. . | -> { 3, 2, 1 }
  * | . . -1 2 -1 | -> { 3, 2, 1 }
  * \ . . . -1 2 / -> { 3, 2, 1 }
  *
  */
  const int matrixSize( 5 );
  using MatrixType = TNL::Matrices::TridiagonalMatrix< double, Device >;
  MatrixType matrix(
  matrixSize, // number of matrix rows
  matrixSize // number of matrix columns
  );
  auto view = matrix.getView();
  auto f = [ = ] __cuda_callable__( int rowIdx ) mutable
  {
  auto row = view.getRow( rowIdx );
  if( rowIdx > 0 )
  row.setElement( 0, -1.0 ); // elements below the diagonal
  row.setElement( 1, 2.0 ); // elements on the diagonal
  if( rowIdx < matrixSize - 1 ) // elements above the diagonal
  row.setElement( 2, -1.0 );
  };
  /***
  * Set the matrix elements.
  */
  TNL::Algorithms::parallelFor< Device >( 0, view.getRows(), f );
  std::cout << '\n' << 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::TridiagonalMatrix
  Implementation of sparse tridiagonal matrix.
  Definition TridiagonalMatrix.h:56
  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
  TNL::Matrices::MatrixType
  Structure for specifying type of sparse matrix.
  Definition MatrixType.h:17

Output
  Getting matrix rows on host:
  Row: 0 -> 0:2 1:-1
  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 -> 3:-1 4:2

## Constructor & Destructor Documentation

## ◆ TridiagonalMatrixRowView()

template<typename ValuesView, typename Indexer>

__cuda_callable__ TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::TridiagonalMatrixRowView | ( | IndexType | rowIdx,
|  | ValuesViewType | values,
|  | IndexerType | indexer )

Constructor with all necessary data.

Parameters

  rowIdx | is index of the matrix row this RowView refer to.
  values | is a vector view holding values of matrix elements.
  indexer | is object responsible for indexing and organization of matrix elements

## Member Function Documentation

## ◆ begin()

template<typename ValuesView, typename Indexer>

__cuda_callable__ IteratorType TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::begin | ( |  | ) |
| nodiscard

Returns iterator pointing at the beginning of the matrix row.

Returns
  iterator pointing at the beginning.

## ◆ cbegin()

template<typename ValuesView, typename Indexer>

__cuda_callable__ ConstIteratorType TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::cbegin | ( |  | ) | const
| nodiscard

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

Returns
  iterator pointing at the beginning.

## ◆ cend()

template<typename ValuesView, typename Indexer>

__cuda_callable__ ConstIteratorType TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::cend | ( |  | ) | const
| nodiscard

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

Returns
  iterator pointing at the end.

## ◆ end()

template<typename ValuesView, typename Indexer>

__cuda_callable__ IteratorType TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::end | ( |  | ) |
| nodiscard

Returns iterator pointing at the end of the matrix row.

Returns
  iterator pointing at the end.

## ◆ getColumnIndex()

template<typename ValuesView, typename Indexer>

__cuda_callable__ IndexType TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getColumnIndex | ( | IndexType | localIdx | ) | const
| nodiscard

Computes column index of matrix element on given subdiagonal.

Parameters

  localIdx | is an index of the subdiagonal.

Returns
  column index of matrix element on given subdiagonal.

## ◆ getRowIndex()

template<typename ValuesView, typename Indexer>

__cuda_callable__ IndexType TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getRowIndex | ( |  | ) | const
| nodiscard

Returns the matrix row index.

Returns
  matrix row index.

## ◆ getSize()

template<typename ValuesView, typename Indexer>

__cuda_callable__ IndexType TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getSize | ( |  | ) | const
| nodiscard

Returns number of diagonals of the tridiagonal matrix which is three.

Returns
  number three.

## ◆ getValue() [1/2]

template<typename ValuesView, typename Indexer>

__cuda_callable__ RealType & TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getValue | ( | IndexType | localIdx | ) |
| nodiscard

Returns value of matrix element on given subdiagonal.

Parameters

  localIdx | is an index of the subdiagonal.

Returns
  non-constant reference to matrix element value.

## ◆ getValue() [2/2]

template<typename ValuesView, typename Indexer>

__cuda_callable__ const RealType & TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getValue | ( | IndexType | localIdx | ) | const
| nodiscard

Returns value of matrix element on given subdiagonal.

Parameters

  localIdx | is an index of the subdiagonal.

Returns
  constant reference to matrix element value.

## ◆ setElement()

template<typename ValuesView, typename Indexer>

__cuda_callable__ void TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::setElement | ( | IndexType | localIdx,
|  | const RealType & | value )

Changes value of matrix element on given subdiagonal.

Parameters

  localIdx | is an index of the matrix subdiagonal.
  value | is the new value of the matrix element.

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

- src/TNL/Matrices/TridiagonalMatrixRowView.h