Template Numerical Library: TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization > Class Template Reference

Template Numerical Library version\ main:16b9213d5

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
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 >:
[legend]
Collaboration diagram for TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >:
[legend]

## 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.
using | SegmentsType
| Segments type used for indexing in the dense matrix.
using | SegmentsViewType
| View type of the segments used for indexing in the dense matrix.
using | SegmentViewType
| Type of segment view used for accessing matrix rows.
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.
template<int tileDim = 16>
void | getInPlaceTransposition (Real matrixMultiplicator=1.0)
| Performs an in-place transposition of this matrix.
__cuda_callable__ ViewType | getView ()
| Returns a modifiable dense matrix view.
DenseMatrixView & | operator= (const DenseMatrixView &)=delete
| Copy-assignment operator.
DenseMatrixView & | operator= (DenseMatrixView &&)=delete
| Move-assignment operator.
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__ 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, TransposeState transpose=TransposeState::None)
| Computes matrix addition.
void | forAllElements (Function &&function) const
| This method calls forElements for all matrix rows.
void | forAllElementsIf (Condition &&condition, Function &&function) const
| This method calls forElementsIf for all matrix rows (for constant instances).
void | forAllRows (Function &&function)
| Method for parallel iteration over all matrix rows.
void | forElements (IndexType begin, IndexType end, Function &&function) const
| Method for iteration over all matrix rows for constant instances.
void | forElementsIf (IndexType begin, IndexType end, Condition &&condition, Function &&function) const
| Method for iterating over all matrix elements that meet a condition based on the row index (for constant instances).
void | forRows (IndexType begin, IndexType end, Function &&function)
| Method for parallel iteration over matrix rows from interval [begin, end).
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.
IndexType | getNonzeroElementsCount () const
| Computes a current number of nonzero matrix elements.
__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.
SegmentsViewType & | getSegments ()
| Getter of segments for non-constant instances.
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.
DenseMatrixBase & | operator= (const DenseMatrixBase &)=delete
| Copy-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 | sequentialForAllRows (Function &&function) const
| This method calls sequentialForRows for all matrix rows (for 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.
IndexType | getAllocatedElementsCount () const
| Tells the number of allocated matrix elements.
__cuda_callable__ IndexType | getColumns () const
| Returns number of matrix columns.
__cuda_callable__ IndexType | getRows () const
| Returns number of matrix rows.
__cuda_callable__ const ValuesViewType & | getValues () const
| Returns a constant reference to a vector with the matrix elements values.
__cuda_callable__ MatrixBase & | operator= (const MatrixBase &)=delete
| Copy-assignment operator.

## 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
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

  Real | is a type of matrix elements.
  Device | is a device where the matrix is allocated.
  Index | is a type for indexing of the matrix elements.
  MatrixElementsOrganization | tells 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 = 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 | ( | Index | rows,
|  | Index | columns,
|  | typename Base::ValuesViewType | values )

Constructor with matrix dimensions and values.

Organization of matrix elements values in

Parameters

  rows | number of matrix rows.
  columns | number of matrix columns.
  values | is 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()
  {
  TNL::Containers::Vector< double, Device > values{
  // 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
  */
  TNL::Matrices::DenseMatrixView< double, Device, int, TNL::Algorithms::Segments::RowMajorOrder > rowMajorMatrix(
  3, 4, values.getView() );
  std::cout << "Row major order matrix:\n";
  std::cout << rowMajorMatrix << '\n';
  /***
  * Create dense matrix view with column major order
  */
  TNL::Matrices::DenseMatrixView< double, Device, int, TNL::Algorithms::Segments::RowMajorOrder > columnMajorMatrix(
  4, 3, values.getView() );
  std::cout << "Column major order matrix:\n";
  std::cout << columnMajorMatrix << '\n';
  }
  int
  main( int argc, char* argv[] )
  {
  std::cout << "Creating matrix view on host:\n";
  createMatrixView< TNL::Devices::Host >();
  #ifdef __CUDACC__
  std::cout << "Creating matrix view on CUDA device:\n";
  createMatrixView< TNL::Devices::Cuda >();
  #endif
  }
  std::cout
  TNL::Containers::Vector
  Vector extends Array with algebraic operations.
  Definition Vector.h:37
  TNL::Containers::Vector::getView
  ViewType getView(IndexType begin=0, IndexType end=0)
  Returns a modifiable view of the vector.
  TNL::Matrices::DenseMatrixView
  Implementation of dense matrix view.
  Definition DenseMatrixView.h:32

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

## ◆ 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

  matrix | is 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

  matrix | is the source matrix view.

## Member Function Documentation

## ◆ bind() [1/2]

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

__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

  view | The dense matrix view to be bound.

## ◆ bind() [2/2]

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

__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

  view | The dense matrix view to be bound.

## ◆ getConstView()

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

__cuda_callable__ ConstViewType TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::getConstView | ( |  | ) | const
| nodiscard

Returns a non-modifiable dense matrix view.

Returns
  dense matrix view.

## ◆ getInPlaceTransposition()

template<typename Real = double, typename Device = Devices::Host, typename Index = int, ElementsOrganization Organization = Algorithms::Segments::DefaultElementsOrganization< Device >::getOrganization()>
template<int tileDim = 16>

void TNL::Matrices::DenseMatrixView< Real, Device, Index, Organization >::getInPlaceTransposition | ( | Real | matrixMultiplicator = 1.0 | ) |

Performs an in-place transposition of this matrix.

This method transposes this matrix in place, modifying the original matrix. The operation can optionally scale the matrix by a specified factor.

Template Parameters

  tileDim | Tile dimension for GPU computation optimization. Default is 16.

Parameters

  matrixMultiplicator | A scalar value by which the matrix is scaled during the transposition. Default is 1.0.

Example
  #include <iostream>
  #include <TNL/Matrices/DenseMatrix.h>
  #include <TNL/Devices/Host.h>
  template< typename Device >
  void
  getInPlaceTranspositionExample()
  {
  // clang-format off
  TNL::Matrices::DenseMatrix< double, Device > matrix{
  { 1, 2, 3, 4 },
  { 6, 7, 8, 9 },
  { 10, 11, 12, 13 },
  { 14, 15, 16, 17 }
  };
  // clang-format on
  std::cout << "Dense matrix:\n" << matrix << '\n';
  matrix.getInPlaceTransposition();
  std::cout << "Transposed dense matrix:\n" << matrix << '\n';
  }
  int
  main( int argc, char* argv[] )
  {
  std::cout << "Creating matrix on CPU ...\n";
  getInPlaceTranspositionExample< TNL::Devices::Host >();
  #ifdef __CUDACC__
  std::cout << "Creating matrix on CUDA GPU ...\n";
  getInPlaceTranspositionExample< TNL::Devices::Cuda >();
  #endif
  }
  TNL::Matrices::DenseMatrix
  Implementation of dense matrix, i.e. matrix storing explicitly all of its elements including zeros.
  Definition DenseMatrix.h:31
  TNL::Matrices::DenseMatrix::getInPlaceTransposition
  void getInPlaceTransposition(Real matrixMultiplicator=1.0)
  Performs an in-place transposition of this matrix.

Output
  Creating matrix on CPU ...
  Dense matrix:
  Row: 0 -> 0:1 1:2 2:3 3:4
  Row: 1 -> 0:6 1:7 2:8 3:9
  Row: 2 -> 0:10 1:11 2:12 3:13
  Row: 3 -> 0:14 1:15 2:16 3:17
  Transposed dense matrix:
  Row: 0 -> 0:1 1:6 2:10 3:14
  Row: 1 -> 0:2 1:7 2:11 3:15
  Row: 2 -> 0:3 1:8 2:12 3:16
  Row: 3 -> 0:4 1:9 2:13 3:17

## ◆ getView()

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

__cuda_callable__ ViewType 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.

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

- src/TNL/Matrices/DenseMatrixView.h