Template Numerical Library version\ main:f17d0c8
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, const ValuesViewType &values, const 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__ RealTypegetValue (IndexType localIdx)
 Returns value of matrix element on given subdiagonal.
 
__cuda_callable__ const RealTypegetValue (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
ValuesViewis a vector view storing the matrix elements values.
Indexeris 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 );
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 << std::endl << 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 sparse tridiagonal matrix.
Definition TridiagonalMatrix.h:56
T endl(T... args)
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
Getting matrix rows on CUDA device:
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,
const ValuesViewType & values,
const IndexerType & indexer )

Constructor with all necessary data.

Parameters
rowIdxis index of the matrix row this RowView refer to.
valuesis a vector view holding values of matrix elements.
indexeris object responsible for indexing and organization of matrix elements

Member Function Documentation

◆ begin()

template<typename ValuesView , typename Indexer >
__cuda_callable__ auto TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::begin ( )

Returns iterator pointing at the beginning of the matrix row.

Returns
iterator pointing at the beginning.

◆ cbegin()

template<typename ValuesView , typename Indexer >
__cuda_callable__ auto TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::cbegin ( ) const

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__ auto TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::cend ( ) const

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__ auto TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::end ( )

Returns iterator pointing at the end of the matrix row.

Returns
iterator pointing at the end.

◆ getColumnIndex()

template<typename ValuesView , typename Indexer >
__cuda_callable__ auto TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getColumnIndex ( IndexType localIdx) const

Computes column index of matrix element on given subdiagonal.

Parameters
localIdxis an index of the subdiagonal.
Returns
column index of matrix element on given subdiagonal.

◆ getRowIndex()

template<typename ValuesView , typename Indexer >
__cuda_callable__ auto TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getRowIndex ( ) const

Returns the matrix row index.

Returns
matrix row index.

◆ getSize()

template<typename ValuesView , typename Indexer >
__cuda_callable__ auto TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getSize ( ) const

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

Returns
number three.

◆ getValue() [1/2]

template<typename ValuesView , typename Indexer >
__cuda_callable__ auto TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getValue ( IndexType localIdx)

Returns value of matrix element on given subdiagonal.

Parameters
localIdxis an index of the subdiagonal.
Returns
non-constant reference to matrix element value.

◆ getValue() [2/2]

template<typename ValuesView , typename Indexer >
__cuda_callable__ auto TNL::Matrices::TridiagonalMatrixRowView< ValuesView, Indexer >::getValue ( IndexType localIdx) const

Returns value of matrix element on given subdiagonal.

Parameters
localIdxis 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
localIdxis an index of the matrix subdiagonal.
valueis the new value of the matrix element.

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