Template Numerical Library version\ main:df396df
Loading...
Searching...
No Matches
TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization > Class Template Reference

Implementation of dense matrix view. More...

#include <TNL/Matrices/DenseMatrixView.h>

Inheritance diagram for TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >:
Collaboration diagram for TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >:

Public Types

using ConstViewType = DenseMatrixView< std::add_const_t< Real >, Device, Index, Organization >
 Matrix view type for constant instances.
 
template<typename _Real = Real, typename _Device = Device, typename _Index = Index>
using Self = DenseMatrixView< _Real, _Device, _Index >
 Helper type for getting self type or its modifications.
 
using ViewType = DenseMatrixView< Real, Device, Index, Organization >
 Matrix view type.
 
- Public Types inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
using ConstRowView
 Type for accessing immutable matrix row.
 
using DeviceType
 The device where the matrix is allocated.
 
using IndexType
 The type used for matrix elements indexing.
 
using RealType
 The type of matrix elements.
 
using RowView
 Type for accessing matrix row.
 
- Public Types inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
using ConstValuesViewType
 Type of constant vector view holding values of matrix elements.
 
using DeviceType
 The device where the matrix is allocated.
 
using IndexType
 The type used for matrix elements indexing.
 
using RealType
 The type of matrix elements.
 
using RowCapacitiesType
 
using ValuesViewType
 Type of vector view holding values of matrix elements.
 

Public Member Functions

__cuda_callable__ DenseMatrixView ()=default
 Constructor without parameters.
 
__cuda_callable__ DenseMatrixView (const DenseMatrixView &matrix)=default
 Copy constructor.
 
__cuda_callable__ DenseMatrixView (DenseMatrixView &&matrix) noexcept=default
 Move constructor.
 
__cuda_callable__ DenseMatrixView (Index rows, Index columns, typename Base::ValuesViewType values)
 Constructor with matrix dimensions and values.
 
__cuda_callable__ void bind (DenseMatrixView &&view)
 Method for rebinding (reinitialization) using another dense matrix view.
 
__cuda_callable__ void bind (DenseMatrixView &view)
 Method for rebinding (reinitialization) using another dense matrix view.
 
__cuda_callable__ ConstViewType getConstView () const
 Returns a non-modifiable dense matrix view.
 
__cuda_callable__ ViewType getView ()
 Returns a modifiable dense matrix view.
 
DenseMatrixViewoperator= (const DenseMatrixView &)=delete
 Copy-assignment operator.
 
DenseMatrixViewoperator= (DenseMatrixView &&)=delete
 Move-assignment operator.
 
void save (File &file) const
 Method for saving the matrix view to a file.
 
- Public Member Functions inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
__cuda_callable__ DenseMatrixBase ()=default
 Constructor without parameters.
 
__cuda_callable__ DenseMatrixBase (const DenseMatrixBase &matrix)=default
 Copy constructor.
 
__cuda_callable__ DenseMatrixBase (DenseMatrixBase &&matrix) noexcept=default
 Move constructor.
 
__cuda_callable__ DenseMatrixBase (IndexType rows, IndexType columns, typename Base::ValuesViewType values)
 Constructor with matrix dimensions and values.
 
__cuda_callable__ void addElement (IndexType row, IndexType column, const RealType &value, const RealType &thisElementMultiplicator=1.0)
 Add element at given row and column to given value.
 
void addMatrix (const Matrix &matrix, const RealType &matrixMultiplicator=1.0, const RealType &thisMatrixMultiplicator=1.0)
 
void forAllElements (Function &&function)
 This method calls forElements for all matrix rows.
 
void forAllElements (Function &&function) const
 This method calls forElements for all matrix rows.
 
void forAllRows (Function &&function)
 Method for parallel iteration over all matrix rows.
 
void forAllRows (Function &&function) const
 Method for parallel iteration over all matrix rows for constant instances.
 
void forElements (IndexType begin, IndexType end, Function &&function)
 Method for iteration over all matrix rows for non-constant instances.
 
void forElements (IndexType begin, IndexType end, Function &&function) const
 Method for iteration over all matrix rows for constant instances.
 
void forRows (IndexType begin, IndexType end, Function &&function)
 Method for parallel iteration over matrix rows from interval [begin, end).
 
void forRows (IndexType begin, IndexType end, Function &&function) const
 Method for parallel iteration over matrix rows from interval [begin, end) for constant instances.
 
void getCompressedRowLengths (Vector &rowLengths) const
 Computes number of non-zeros in each row.
 
__cuda_callable__ double getElement (IndexType row, IndexType column) const
 Returns value of matrix element at position given by its row and column index.
 
__cuda_callable__ RowView getRow (IndexType rowIdx)
 Non-constant getter of simple structure for accessing given matrix row.
 
__cuda_callable__ ConstRowView getRow (IndexType rowIdx) const
 Constant getter of simple structure for accessing given matrix row.
 
void getRowCapacities (Vector &rowCapacities) const
 Compute capacities of all rows.
 
__cuda_callable__ IndexType getRowCapacity (IndexType row) const
 Returns capacity of given matrix row.
 
bool operator!= (const DenseMatrixBase< Real_, Device_, Index_, Organization > &matrix) const
 Comparison operator with another dense matrix view.
 
__cuda_callable__ double & operator() (IndexType row, IndexType column)
 Returns non-constant reference to element at row row and column column.
 
__cuda_callable__ const double & operator() (IndexType row, IndexType column) const
 Returns constant reference to element at row row and column column.
 
DenseMatrixBaseoperator= (const DenseMatrixBase &)=delete
 Copy-assignment operator.
 
DenseMatrixBaseoperator= (DenseMatrixBase &&)=delete
 Move-assignment operator.
 
bool operator== (const DenseMatrixBase< Real_, Device_, Index_, Organization > &matrix) const
 Comparison operator with another dense matrix view.
 
void print (std::ostream &str) const
 Method for printing the matrix to output stream.
 
void reduceAllRows (Fetch &&fetch, const Reduce &reduce, Keep &&keep, const FetchReal &identity) const
 Method for performing general reduction on ALL matrix rows for constant instances.
 
void reduceRows (IndexType begin, IndexType end, Fetch &&fetch, const Reduce &reduce, Keep &&keep, const FetchReal &identity) const
 Method for performing general reduction on matrix rows for constant instances.
 
void reduceRows (IndexType begin, IndexType end, Fetch &&fetch, const Reduce &reduce, Keep &&keep, const FetchValue &identity) const
 
void sequentialForAllRows (Function &&function)
 This method calls sequentialForRows for all matrix rows.
 
void sequentialForAllRows (Function &&function) const
 This method calls sequentialForRows for all matrix rows (for constant instances).
 
void sequentialForRows (IndexType begin, IndexType end, Function &&function)
 Method for sequential iteration over all matrix rows for non-constant instances.
 
void sequentialForRows (IndexType begin, IndexType end, Function &&function) const
 Method for sequential iteration over all matrix rows for constant instances.
 
__cuda_callable__ void setElement (IndexType row, IndexType column, const RealType &value)
 Sets element at given row and column to given value.
 
void setValue (const RealType &v)
 Sets all matrix elements to value v.
 
void vectorProduct (const InVector &inVector, OutVector &outVector, const RealType &matrixMultiplicator=1.0, const RealType &outVectorMultiplicator=0.0, IndexType begin=0, IndexType end=0) const
 Computes product of matrix and vector.
 
- Public Member Functions inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
__cuda_callable__ MatrixBase ()=default
 Basic constructor with no parameters.
 
__cuda_callable__ MatrixBase (const MatrixBase &view)=default
 Shallow copy constructor.
 
__cuda_callable__ MatrixBase (IndexType rows, IndexType columns, ValuesViewType values)
 Constructor with matrix dimensions and matrix elements values.
 
__cuda_callable__ MatrixBase (MatrixBase &&view) noexcept=default
 Move constructor.
 
IndexType getAllocatedElementsCount () const
 Tells the number of allocated matrix elements.
 
__cuda_callable__ IndexType getColumns () const
 Returns number of matrix columns.
 
virtual IndexType getNonzeroElementsCount () const
 Computes a current number of nonzero matrix elements.
 
__cuda_callable__ IndexType getRows () const
 Returns number of matrix rows.
 
__cuda_callable__ ValuesViewTypegetValues ()
 Returns a reference to a vector with the matrix elements values.
 
__cuda_callable__ const ValuesViewTypegetValues () const
 Returns a constant reference to a vector with the matrix elements values.
 
bool operator!= (const Matrix &matrix) const
 Comparison operator with another arbitrary matrix view type.
 
bool operator!= (const MatrixT &matrix) const
 
__cuda_callable__ MatrixBaseoperator= (const MatrixBase &)=delete
 Copy-assignment operator.
 
__cuda_callable__ MatrixBaseoperator= (MatrixBase &&)=delete
 Move-assignment operator.
 
bool operator== (const Matrix &matrix) const
 Comparison operator with another arbitrary matrix view type.
 
bool operator== (const MatrixT &matrix) const
 

Additional Inherited Members

- Static Public Member Functions inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
static std::string getSerializationType ()
 Returns string with serialization type.
 
- Static Public Member Functions inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
static constexpr ElementsOrganization getOrganization ()
 Matrix elements organization getter.
 
static constexpr bool isBinary ()
 Test of binary matrix type.
 
static constexpr bool isSymmetric ()
 Test of symmetric matrix type.
 
- Protected Types inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
using Base
 
using SegmentsReductionKernel
 
using SegmentsType
 
using SegmentsViewType
 
using SegmentViewType
 
- Protected Member Functions inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
__cuda_callable__ void bind (IndexType rows, IndexType columns, typename Base::ValuesViewType values, SegmentsViewType segments)
 Re-initializes the internal attributes of the base class.
 
__cuda_callable__ IndexType getElementIndex (IndexType row, IndexType column) const
 
- Protected Member Functions inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
__cuda_callable__ void bind (IndexType rows, IndexType columns, ValuesViewType values)
 Re-initializes the internal attributes of the base class.
 
- Protected Attributes inherited from TNL::Matrices::DenseMatrixBase< double, Devices::Host, int, Algorithms::Segments::DefaultElementsOrganization< Devices::Host >::getOrganization() >
SegmentsViewType segments
 
- Protected Attributes inherited from TNL::Matrices::MatrixBase< double, Devices::Host, int, GeneralMatrix, Organization >
IndexType columns
 
IndexType rows
 
ValuesViewType values
 

Detailed Description

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization()>
class TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >

Implementation of dense matrix view.

It serves as an accessor to DenseMatrix for example when passing the matrix to lambda functions. DenseMatrix view can be also created in CUDA kernels.

Template Parameters
Realis a type of matrix elements.
Deviceis a device where the matrix is allocated.
Indexis a type for indexing of the matrix elements.
MatrixElementsOrganizationtells the ordering of matrix elements in memory. It is either TNL::Algorithms::Segments::RowMajorOrder or TNL::Algorithms::Segments::ColumnMajorOrder.

See DenseMatrix.

Member Typedef Documentation

◆ ConstViewType

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization()>
using TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::ConstViewType = DenseMatrixView< std::add_const_t< Real >, Device, Index, Organization >

Matrix view type for constant instances.

See DenseMatrixView.

◆ ViewType

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization()>
using TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::ViewType = DenseMatrixView< Real, Device, Index, Organization >

Matrix view type.

See DenseMatrixView.

Constructor & Destructor Documentation

◆ DenseMatrixView() [1/3]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
__cuda_callable__ TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::DenseMatrixView ( Index rows,
Index columns,
typename Base::ValuesViewType values )

Constructor with matrix dimensions and values.

Organization of matrix elements values in

Parameters
rowsnumber of matrix rows.
columnsnumber of matrix columns.
valuesis vector view with matrix elements values.
Example
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
createMatrixView()
{
// clang-format off
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12
// clang-format on
};
/***
* Create dense matrix view with row major order
*/
3, 4, values.getView() );
std::cout << "Row major order matrix:" << std::endl;
std::cout << rowMajorMatrix << std::endl;
/***
* Create dense matrix view with column major order
*/
4, 3, values.getView() );
std::cout << "Column major order matrix:" << std::endl;
std::cout << columnMajorMatrix << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Creating matrix view on host: " << std::endl;
createMatrixView< TNL::Devices::Host >();
#ifdef __CUDACC__
std::cout << "Creating matrix view on CUDA device: " << std::endl;
createMatrixView< TNL::Devices::Cuda >();
#endif
}
Vector extends Array with algebraic operations.
Definition Vector.h:36
Implementation of dense matrix view.
Definition DenseMatrixView.h:31
T endl(T... args)
Output
Creating matrix view on host:
Row major order matrix:
Row: 0 -> 0:1 1:2 2:3 3:4
Row: 1 -> 0:5 1:6 2:7 3:8
Row: 2 -> 0:9 1:10 2:11 3:12
Column major order matrix:
Row: 0 -> 0:1 1:2 2:3
Row: 1 -> 0:4 1:5 2:6
Row: 2 -> 0:7 1:8 2:9
Row: 3 -> 0:10 1:11 2:12
Creating matrix view on CUDA device:
Row major order matrix:
Row: 0 -> 0:1 1:2 2:3 3:4
Row: 1 -> 0:5 1:6 2:7 3:8
Row: 2 -> 0:9 1:10 2:11 3:12
Column major order matrix:
Row: 0 -> 0:1 1:2 2:3
Row: 1 -> 0:4 1:5 2:6
Row: 2 -> 0:7 1:8 2:9
Row: 3 -> 0:10 1:11 2:12

◆ DenseMatrixView() [2/3]

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization()>
__cuda_callable__ TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::DenseMatrixView ( const DenseMatrixView< Real, Device, Index, Organization > & matrix)
default

Copy constructor.

Parameters
matrixis the source matrix view.

◆ DenseMatrixView() [3/3]

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization()>
__cuda_callable__ TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::DenseMatrixView ( DenseMatrixView< Real, Device, Index, Organization > && matrix)
defaultnoexcept

Move constructor.

Parameters
matrixis the source matrix view.

Member Function Documentation

◆ bind() [1/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
__cuda_callable__ void TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::bind ( DenseMatrixView< Real, Device, Index, Organization > && view)

Method for rebinding (reinitialization) using another dense matrix view.

Parameters
viewThe dense matrix view to be bound.

◆ bind() [2/2]

template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
__cuda_callable__ void TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::bind ( DenseMatrixView< Real, Device, Index, Organization > & view)

Method for rebinding (reinitialization) using another dense matrix view.

Parameters
viewThe dense matrix view to be bound.

◆ getConstView()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
__cuda_callable__ auto TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::getConstView ( ) const
nodiscard

Returns a non-modifiable dense matrix view.

Returns
dense matrix view.

◆ getView()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
__cuda_callable__ auto TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::getView ( )
nodiscard

Returns a modifiable dense matrix view.

Returns
dense matrix view.

◆ operator=()

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization()>
DenseMatrixView & TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::operator= ( const DenseMatrixView< Real, Device, Index, Organization > & )
delete

Copy-assignment operator.

It is a deleted function, because matrix assignment in general requires reallocation.

◆ save()

template<typename Real , typename Device , typename Index , ElementsOrganization Organization>
void TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::save ( File & file) const

Method for saving the matrix view to a file.

The ouput file can be loaded by DenseMatrix.

Parameters
fileis the file where the matrix will be saved.

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