Template Numerical Library version\ main:94209208
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 >
static auto TNL::Matrices::LambdaMatrixFactory< Real, Device, Index >::create ( IndexType rows,
IndexType columns,
MatrixElementsLambda & matrixElementsLambda,
CompressedRowLengthsLambda & compressedRowLengthsLambda ) -> LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index >
inlinestatic

Creates lambda matrix with given dimensions and lambda functions.

Parameters
rowsis number of matrix rows.
columnsis number of matrix columns.
matrixElementsLambdais a lambda function evaluating matrix elements.
compressedRowLengthsLambdais 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 =
const int rows, const int columns, const int rowIdx, const int localIdx, int& columnIdx, double& value )
{
columnIdx = rowIdx;
value = 1.0;
};
auto matrixElements2 =
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.
*/
matrixElements1, compressedRowLengths ) );
MatrixType m1( size, size, matrixElements1, compressedRowLengths );
/***
* Matrix construction using 'auto'.
*/
auto m2 =
m2.setDimensions( size, size );
std::cout << "The first lambda matrix: " << std::endl << m1 << std::endl;
std::cout << "The second lambda matrix: " << std::endl << m2 << std::endl;
}
#define __cuda_callable__
Definition Macros.h:49
T endl(T... args)
static auto create(MatrixElementsLambda &matrixElementsLambda, CompressedRowLengthsLambda &compressedRowLengthsLambda) -> LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index >
Creates lambda matrix with given lambda functions.
Definition LambdaMatrix.h:571
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 >
static auto TNL::Matrices::LambdaMatrixFactory< Real, Device, Index >::create ( MatrixElementsLambda & matrixElementsLambda,
CompressedRowLengthsLambda & compressedRowLengthsLambda ) -> LambdaMatrix< MatrixElementsLambda, CompressedRowLengthsLambda, Real, Device, Index >
inlinestatic

Creates lambda matrix with given lambda functions.

Parameters
matrixElementsLambdais a lambda function evaluating matrix elements.
compressedRowLengthsLambdais 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 =
const int rows, const int columns, const int rowIdx, const int localIdx, int& columnIdx, double& value )
{
columnIdx = rowIdx;
value = 1.0;
};
auto matrixElements2 =
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.
*/
matrixElements1, compressedRowLengths ) );
MatrixType m1( size, size, matrixElements1, compressedRowLengths );
/***
* Matrix construction using 'auto'.
*/
auto m2 =
m2.setDimensions( size, size );
std::cout << "The first lambda matrix: " << std::endl << m1 << std::endl;
std::cout << "The second lambda matrix: " << std::endl << m2 << std::endl;
}
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: