Template Numerical Library version main:e6bb26f
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 ConstValuesViewType = typename ValuesViewType::ConstViewType
 Type of constant container view used for storing the matrix elements values.
 
using ConstView = DenseMatrixRowView< SegmentView, ConstValuesViewType >
 Type of constant sparse matrix row view.
 
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. 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__ IndexType getColumnIndex (IndexType localIdx) const
 This method is only for compatibility with sparse matrix row. More...
 
__cuda_callable__ const IndexTypegetRowIndex () const
 Returns the matrix row index. More...
 
__cuda_callable__ IndexType getSize () const
 Returns size of the matrix row, i.e. number of matrix elements in this row. More...
 
__cuda_callable__ RealTypegetValue (IndexType column)
 Returns non-constants reference to an element with given column index. More...
 
__cuda_callable__ const RealTypegetValue (IndexType column) const
 Returns constants reference to an element with given column index. More...
 
__cuda_callable__ void setElement (IndexType localIdx, IndexType column, const RealType &value)
 Sets value of matrix element with given column index. More...
 
__cuda_callable__ void setValue (IndexType column, const RealType &value)
 Sets value of matrix element with given column index. More...
 

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>
#include <TNL/Pointers/SharedPointer.h>
template< typename Device >
void getRowExample()
{
auto f = [=] __cuda_callable__ ( int rowIdx ) mutable {
auto row = matrix->getRow( rowIdx );
row.setValue( rowIdx, 10 * ( rowIdx + 1 ) );
};
/***
* For the case when Device is CUDA device we need to synchronize smart
* pointers. To avoid this you may use DenseMatrixView. See
* DenseMatrixView::getRow example for details.
*/
TNL::Pointers::synchronizeSmartPointersOnDevice< Device >();
/***
* Set the matrix elements.
*/
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 HAVE_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 dense matrix, i.e. matrix storing explicitly all of its elements including zeros.
Definition: DenseMatrix.h:35
Cross-device shared smart pointer.
Definition: SharedPointer.h:49
T endl(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:
1
Getting matrix rows on CUDA device:
1
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.
*/
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 HAVE_CUDA
std::cout << "Getting matrix rows on CUDA device: " << std::endl;
getRowExample< TNL::Devices::Cuda >();
#endif
}
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

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

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

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

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

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

Returns the matrix row index.

Returns
matrix row index.

◆ getSize()

template<typename SegmentView , typename ValuesView >
__cuda_callable__ auto TNL::Matrices::DenseMatrixRowView< SegmentView, ValuesView >::getSize

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)

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

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: