Template Numerical Library: TNL::Matrices::LambdaMatrixFactory< Real, Device, Index > Struct Template Reference

Template Numerical Library version\ main:c7077e4fd

Loading...
Searching...
No Matches
Public Types | Static Public Member Functions | List of all members
TNL::Matrices::LambdaMatrixFactory< Real, Device, Index > Struct Template Reference

Helper class for creating instances of LambdaMatrix. More...

`#include <TNL/Matrices/LambdaMatrix.h>`

## Public Types
using | IndexType = Index
using | RealType = Real

## Static Public Member Functions
template<typename MatrixElementsLambda, typename CompressedRowLengthsLambda>
static auto | create (IndexType rows, IndexType columns, MatrixElementsLambda &matrixElementsLambda, CompressedRowLengthsLambda &compressedRowLengthsLambda) -> LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index >
| Creates lambda matrix with given dimensions and lambda functions.
template<typename MatrixElementsLambda, typename CompressedRowLengthsLambda>
static auto | create (MatrixElementsLambda &matrixElementsLambda, CompressedRowLengthsLambda &compressedRowLengthsLambda) -> LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index >
| Creates lambda matrix with given lambda functions.

## Detailed Description

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
struct TNL::Matrices::LambdaMatrixFactory< Real, Device, Index >

Helper class for creating instances of LambdaMatrix.

See LambdaMatrix.

Parameters

  matrixElementsLambda |
  compressedRowLengthsLambda |

## Member Function Documentation

## ◆ create() [1/2]

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
template<typename MatrixElementsLambda, typename CompressedRowLengthsLambda>

auto TNL::Matrices::LambdaMatrixFactory< Real, Device, Index >::create | ( | IndexType | rows,
|  | IndexType | columns,
|  | MatrixElementsLambda & | matrixElementsLambda,
|  | CompressedRowLengthsLambda & | compressedRowLengthsLambda ) -> LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index >
| inlinestaticnodiscard

Creates lambda matrix with given dimensions and lambda functions.

Parameters

  rows | is number of matrix rows.
  columns | is number of matrix columns.
  matrixElementsLambda | is a lambda function evaluating matrix elements.
  compressedRowLengthsLambda | is a lambda function returning number of non-zero matrix elements in given row.

Returns
  instance of LambdaMatrix.

Example
  #include <iostream>
  #include <TNL/Matrices/LambdaMatrix.h>
  int
  main( int argc, char* argv[] )
  {
  /***
  * Lambda functions defining the matrix.
  */
  auto compressedRowLengths = [ = ] __cuda_callable__( const int rows, const int columns, const int rowIdx ) -> int
  {
  return 1;
  };
  auto matrixElements1 =
  [ = ] __cuda_callable__(
  const int rows, const int columns, const int rowIdx, const int localIdx, int& columnIdx, double& value )
  {
  columnIdx = rowIdx;
  value = 1.0;
  };
  auto matrixElements2 =
  [ = ] __cuda_callable__(
  const int rows, const int columns, const int rowIdx, const int localIdx, int& columnIdx, double& value )
  {
  columnIdx = rowIdx;
  value = rowIdx;
  };
  const int size = 5;
  /***
  * Matrix construction with explicit type definition.
  */
  using MatrixType = decltype( TNL::Matrices::LambdaMatrixFactory< double, TNL::Devices::Host, int >::create(
  matrixElements1, compressedRowLengths ) );
  MatrixType m1( size, size, matrixElements1, compressedRowLengths );
  /***
  * Matrix construction using 'auto'.
  */
  auto m2 =
  TNL::Matrices::LambdaMatrixFactory< double, TNL::Devices::Host, int >::create( matrixElements2, compressedRowLengths );
  m2.setDimensions( size, size );
  std::cout << "The first lambda matrix:\n" << m1 << '\n';
  std::cout << "The second lambda matrix:\n" << m2 << '\n';
  }
  __cuda_callable__
  #define __cuda_callable__
  Definition Macros.h:49
  std::cout
  TNL::Matrices::LambdaMatrixFactory::create
  static auto create(MatrixElementsLambda &matrixElementsLambda, CompressedRowLengthsLambda &compressedRowLengthsLambda) -> LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index >
  Creates lambda matrix with given lambda functions.
  Definition LambdaMatrix.h:576

Output
  The first lambda matrix:
  Row: 0 -> 0:1
  Row: 1 -> 1:1
  Row: 2 -> 2:1
  Row: 3 -> 3:1
  Row: 4 -> 4:1
  The second lambda matrix:
  Row: 0 ->
  Row: 1 -> 1:1
  Row: 2 -> 2:2
  Row: 3 -> 3:3
  Row: 4 -> 4:4

## ◆ create() [2/2]

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
template<typename MatrixElementsLambda, typename CompressedRowLengthsLambda>

auto TNL::Matrices::LambdaMatrixFactory< Real, Device, Index >::create | ( | MatrixElementsLambda & | matrixElementsLambda,
|  | CompressedRowLengthsLambda & | compressedRowLengthsLambda ) -> LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index >
| inlinestaticnodiscard

Creates lambda matrix with given lambda functions.

Parameters

  matrixElementsLambda | is a lambda function evaluating matrix elements.
  compressedRowLengthsLambda | is a lambda function returning number of non-zero matrix elements in given row.

Returns
  instance of LambdaMatrix.

Example
  #include <iostream>
  #include <TNL/Matrices/LambdaMatrix.h>
  int
  main( int argc, char* argv[] )
  {
  /***
  * Lambda functions defining the matrix.
  */
  auto compressedRowLengths = [ = ] __cuda_callable__( const int rows, const int columns, const int rowIdx ) -> int
  {
  return 1;
  };
  auto matrixElements1 =
  [ = ] __cuda_callable__(
  const int rows, const int columns, const int rowIdx, const int localIdx, int& columnIdx, double& value )
  {
  columnIdx = rowIdx;
  value = 1.0;
  };
  auto matrixElements2 =
  [ = ] __cuda_callable__(
  const int rows, const int columns, const int rowIdx, const int localIdx, int& columnIdx, double& value )
  {
  columnIdx = rowIdx;
  value = rowIdx;
  };
  const int size = 5;
  /***
  * Matrix construction with explicit type definition.
  */
  using MatrixType = decltype( TNL::Matrices::LambdaMatrixFactory< double, TNL::Devices::Host, int >::create(
  matrixElements1, compressedRowLengths ) );
  MatrixType m1( size, size, matrixElements1, compressedRowLengths );
  /***
  * Matrix construction using 'auto'.
  */
  auto m2 =
  TNL::Matrices::LambdaMatrixFactory< double, TNL::Devices::Host, int >::create( matrixElements2, compressedRowLengths );
  m2.setDimensions( size, size );
  std::cout << "The first lambda matrix:\n" << m1 << '\n';
  std::cout << "The second lambda matrix:\n" << m2 << '\n';
  }

Output
  The first lambda matrix:
  Row: 0 -> 0:1
  Row: 1 -> 1:1
  Row: 2 -> 2:1
  Row: 3 -> 3:1
  Row: 4 -> 4:1
  The second lambda matrix:
  Row: 0 ->
  Row: 1 -> 1:1
  Row: 2 -> 2:2
  Row: 3 -> 3:3
  Row: 4 -> 4:4

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

- src/TNL/Matrices/LambdaMatrix.h