Template Numerical Library version main:e6bb26f
Public Types | Public Member Functions | Protected Attributes | List of all members
TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView_ > Class Template Reference

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

#include <TNL/Matrices/MultidiagonalMatrixRowView.h>

Public Types

using ConstDiagonalsOffsetsView = typename DiagonalsOffsetsView::ConstViewType
 Type of constant container view used for storing the column indexes of the matrix elements.
 
using ConstIndexerViewType = typename IndexerType::ConstType
 Type of constant indexer view.
 
using ConstRowView = MultidiagonalMatrixRowView< ConstValuesViewType, ConstIndexerViewType, ConstDiagonalsOffsetsView >
 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 DiagonalsOffsetsView = DiagonalsOffsetsView_
 Type of a container view holding offsets of diagonals of multidiagonal matrix.
 
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 = MultidiagonalMatrixRowView< ValuesViewType, IndexerType, DiagonalsOffsetsView >
 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__ MultidiagonalMatrixRowView (IndexType rowIdx, const DiagonalsOffsetsView &diagonalsOffsets, const ValuesViewType &values, const IndexerType &indexer)
 Constructor with all necessary data. More...
 
__cuda_callable__ IteratorType begin ()
 Returns iterator pointing at the beginning of the matrix row. More...
 
__cuda_callable__ const IteratorType cbegin () const
 Returns constant iterator pointing at the beginning of the matrix row. More...
 
__cuda_callable__ const IteratorType cend () const
 Returns constant iterator pointing at the end of the matrix row. More...
 
__cuda_callable__ IteratorType end ()
 Returns iterator pointing at the end of the matrix row. More...
 
__cuda_callable__ const IndexType getColumnIndex (IndexType localIdx) const
 Computes column index of matrix element on given subdiagonal. More...
 
__cuda_callable__ const IndexTypegetRowIndex () const
 Returns the matrix row index. More...
 
__cuda_callable__ IndexType getSize () const
 Returns number of diagonals of the multidiagonal matrix. More...
 
__cuda_callable__ RealTypegetValue (IndexType localIdx)
 Returns value of matrix element on given subdiagonal. More...
 
__cuda_callable__ const RealTypegetValue (IndexType localIdx) const
 Returns value of matrix element on given subdiagonal. More...
 
__cuda_callable__ void setElement (IndexType localIdx, const RealType &value)
 Changes value of matrix element on given subdiagonal. More...
 

Protected Attributes

DiagonalsOffsetsView diagonalsOffsets
 
Indexer indexer
 
IndexType rowIdx
 
ValuesViewType values
 

Detailed Description

template<typename ValuesView, typename Indexer, typename DiagonalsOffsetsView_>
class TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView_ >

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

Template Parameters
ValuesViewis a vector view storing the matrix elements values.
Indexeris type of object responsible for indexing and organization of matrix elements.
DiagonalsOffsetsView_is a container view holding offsets of diagonals of multidiagonal matrix.

See MultidiagonalMatrix and MultidiagonalMatrixView.

Example
#include <iostream>
#include <TNL/Algorithms/ParallelFor.h>
#include <TNL/Matrices/MultidiagonalMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
#include <TNL/Pointers/SharedPointer.h>
template< typename Device >
void getRowExample()
{
const int matrixSize( 5 );
auto diagonalsOffsets = { -1, 0, 1 }; // Variadic templates in SharedPointer
// constructor do not recognize initializer
// list so we give it a hint.
matrixSize, // number of matrix rows
matrixSize, // number of matrix columns
diagonalsOffsets );
auto f = [=] __cuda_callable__ ( int rowIdx ) mutable {
//auto row = matrix->getRow( rowIdx );
// For some reason the previous line of code is not accepted by nvcc 10.1
// so we replace it with the following two lines.
auto ref = matrix.modifyData();
auto row = ref.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 );
};
/***
* For the case when Device is CUDA device we need to synchronize smart
* pointers. To avoid this you may use MultidiagonalMatrixView. See
* MultidiagonalMatrixView::getRow example for details.
*/
TNL::Pointers::synchronizeSmartPointersOnDevice< Device >();
/***
* Set the matrix elements.
*/
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 HAVE_CUDA
// It seems that nvcc 10.1 does not handle lambda functions properly.
// It is hard to make nvcc to compile this example and it does not work
// properly. We will try it with later version of CUDA.
//std::cout << "Getting matrix rows on CUDA device: " << std::endl;
//getRowExample< TNL::Devices::Cuda >();
#endif
}
#define __cuda_callable__
Definition: CudaCallable.h:22
Implementation of sparse multidiagonal matrix.
Definition: MultidiagonalMatrix.h:71
Cross-device shared smart pointer.
Definition: SharedPointer.h:49
T endl(T... args)
T ref(T... args)
static void exec(Index start, Index end, Function f, FunctionArgs... args)
Static method for the execution of the loop.
Definition: ParallelFor.h:87
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
Example
#include <iostream>
#include <TNL/Algorithms/ParallelFor.h>
#include <TNL/Matrices/MultidiagonalMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void getRowExample()
{
const int matrixSize( 5 );
MatrixType matrix(
matrixSize, // number of matrix rows
matrixSize, // number of matrix columns
{ -1, 0, 1 } );
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.
*/
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 HAVE_CUDA
std::cout << "Getting matrix rows on CUDA device: " << std::endl;
getRowExample< TNL::Devices::Cuda >();
#endif
}
ViewType getView() const
Returns a modifiable view of the multidiagonal matrix.
Definition: MultidiagonalMatrix.hpp:83
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

◆ MultidiagonalMatrixRowView()

template<typename ValuesView , typename Indexer , typename DiagonalsOffsetsView >
__cuda_callable__ TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::MultidiagonalMatrixRowView ( IndexType  rowIdx,
const DiagonalsOffsetsView diagonalsOffsets,
const ValuesViewType values,
const IndexerType indexer 
)

Constructor with all necessary data.

Parameters
rowIdxis index of the matrix row this RowView refer to.
diagonalsOffsetsis a vector view holding offsets of matrix diagonals,
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 , typename DiagonalsOffsetsView >
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::begin

Returns iterator pointing at the beginning of the matrix row.

Returns
iterator pointing at the beginning.

◆ cbegin()

template<typename ValuesView , typename Indexer , typename DiagonalsOffsetsView >
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::cbegin

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

Returns
iterator pointing at the beginning.

◆ cend()

template<typename ValuesView , typename Indexer , typename DiagonalsOffsetsView >
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::cend

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

Returns
iterator pointing at the end.

◆ end()

template<typename ValuesView , typename Indexer , typename DiagonalsOffsetsView >
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::end

Returns iterator pointing at the end of the matrix row.

Returns
iterator pointing at the end.

◆ getColumnIndex()

template<typename ValuesView , typename Indexer , typename DiagonalsOffsetsView >
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::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 , typename DiagonalsOffsetsView >
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::getRowIndex

Returns the matrix row index.

Returns
matrix row index.

◆ getSize()

template<typename ValuesView , typename Indexer , typename DiagonalsOffsetsView >
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::getSize

Returns number of diagonals of the multidiagonal matrix.

Returns
number of diagonals of the multidiagonal matrix.

◆ getValue() [1/2]

template<typename ValuesView , typename Indexer , typename DiagonalsOffsetsView >
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::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 , typename DiagonalsOffsetsView >
__cuda_callable__ auto TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::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 , typename DiagonalsOffsetsView >
__cuda_callable__ void TNL::Matrices::MultidiagonalMatrixRowView< ValuesView, Indexer, DiagonalsOffsetsView >::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: