TRIQS/nda 2.0.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Tensor utilities

Detailed Description

Supporting types and helpers used by the tensor operations.

Classes

struct  nda::tensor::tensor_view< T >
 A type-erased, non-owning view of an nda::MemoryArray or a conjugate lazy expression. More...

Typedefs

template<typename T>
using nda::tensor::const_tensor_view = tensor_view<const T>
 Alias for a tensor_view with const value type.
template<BlasArrayOrConj A>
using nda::tensor::data_ptr_t = decltype(get_array(std::declval<A>()).data())
 Data pointer type of an nda::blas_lapack::BlasArrayOrConj.

Enumerations

enum class  nda::tensor::binary_op : std::uint8_t
 Binary operations for tensor operations. More...
enum class  nda::tensor::unary_op : std::uint8_t
 Unary element-wise operations for tensor operations. More...

Functions

template<int R>
requires (R >= 0 && R <= 26)
std::string_view nda::tensor::default_index ()
 Generate a default index string ("abc...") of a given length.
void nda::tensor::require_equal_indices (std::string_view idx_a, std::string_view idx_b, int rank, std::string_view op_name)
 Check if two index strings are equal and have a specified length.

Variables

static constexpr bool nda::tensor::have_cutensor = false
 Constexpr variable that is true if nda is configured cuTENSOR support.
static constexpr bool nda::tensor::have_tblis = false
 Constexpr variable that is true if nda is configured with TBLIS support.

Enumeration Type Documentation

◆ binary_op

enum class nda::tensor::binary_op : std::uint8_t
strong

#include <nda/tensor/tools.hpp>

Binary operations for tensor operations.

The binary operations are mapped to TBLIS and cuTENSOR as follows:

  • binary_op::SUM -> REDUCE_SUM or CUTENSOR_OP_ADD
  • binary_op::PROD -> CUTENSOR_OP_MUL (N/A in TBLIS)
  • binary_op::SUM_ABS -> REDUCE_SUM_ABS (N/A in cuTENSOR)
  • binary_op::MAX -> REDUCE_MAX / CUTENSOR_OP_MAX
  • binary_op::MAX_ABS -> REDUCE_MAX_ABS (N/A in cuTENSOR)
  • binary_op::MIN -> REDUCE_MIN / CUTENSOR_OP_MIN
  • binary_op::MIN_ABS -> REDUCE_MIN_ABS (N/A in cuTENSOR)
  • binary_op::NORM_2 -> REDUCE_NORM_2 (N/A in cuTENSOR)

Definition at line 67 of file tools.hpp.

◆ unary_op

enum class nda::tensor::unary_op : std::uint8_t
strong

#include <nda/tensor/tools.hpp>

Unary element-wise operations for tensor operations.

The unary operations are mapped to cuTENSOR's element-wise operators (cutensorOperator_t) as follows:

  • unary_op::IDENTITY -> CUTENSOR_OP_IDENTITY (elements are not changed)
  • unary_op::SQRT -> CUTENSOR_OP_SQRT (square root)
  • unary_op::RELU -> CUTENSOR_OP_RELU (rectified linear unit)
  • unary_op::CONJ -> CUTENSOR_OP_CONJ (complex conjugate)
  • unary_op::RCP -> CUTENSOR_OP_RCP (reciprocal)
  • unary_op::SIGMOID -> CUTENSOR_OP_SIGMOID (y = 1/(1+exp(-x)))
  • unary_op::TANH -> CUTENSOR_OP_TANH (y = tanh(x))
  • unary_op::EXP -> CUTENSOR_OP_EXP (exponentiation)
  • unary_op::LOG -> CUTENSOR_OP_LOG (log base e)
  • unary_op::ABS -> CUTENSOR_OP_ABS (absolute value)
  • unary_op::NEG -> CUTENSOR_OP_NEG (negation)
  • unary_op::SIN -> CUTENSOR_OP_SIN (sine)
  • unary_op::COS -> CUTENSOR_OP_COS (cosine)
  • unary_op::TAN -> CUTENSOR_OP_TAN (tangent)
  • unary_op::SINH -> CUTENSOR_OP_SINH (hyperbolic sine)
  • unary_op::COSH -> CUTENSOR_OP_COSH (hyperbolic cosine)
  • unary_op::ASIN -> CUTENSOR_OP_ASIN (inverse sine)
  • unary_op::ACOS -> CUTENSOR_OP_ACOS (inverse cosine)
  • unary_op::ATAN -> CUTENSOR_OP_ATAN (inverse tangent)
  • unary_op::ASINH -> CUTENSOR_OP_ASINH (inverse hyperbolic sine)
  • unary_op::ACOSH -> CUTENSOR_OP_ACOSH (inverse hyperbolic cosine)
  • unary_op::ATANH -> CUTENSOR_OP_ATANH (inverse hyperbolic tangent)
  • unary_op::CEIL -> CUTENSOR_OP_CEIL (ceiling)
  • unary_op::FLOOR -> CUTENSOR_OP_FLOOR (floor)
  • unary_op::MISH -> CUTENSOR_OP_MISH (mish, y = x*tanh(softplus(x)))
  • unary_op::SWISH -> CUTENSOR_OP_SWISH (swish, y = x*sigmoid(x))
  • unary_op::SOFT_PLUS -> CUTENSOR_OP_SOFT_PLUS (softplus, y = log(exp(x)+1))
  • unary_op::SOFT_SIGN -> CUTENSOR_OP_SOFT_SIGN (softsign, y = x/(abs(x)+1))

Definition at line 103 of file tools.hpp.

Function Documentation

◆ default_index()

template<int R>
requires (R >= 0 && R <= 26)
std::string_view nda::tensor::default_index ( )

#include <nda/tensor/tools.hpp>

Generate a default index string ("abc...") of a given length.

Used by tensor operations that don't require user-specified indices (e.g., scale, set, full reduce). The maximum supported length is 26 (one character per letter).

Template Parameters
RLength of the index string (must be in [0, 26]).
Returns
The default index string of length R.

Definition at line 265 of file tools.hpp.

◆ require_equal_indices()

void nda::tensor::require_equal_indices ( std::string_view idx_a,
std::string_view idx_b,
int rank,
std::string_view op_name )
inline

#include <nda/tensor/tools.hpp>

Check if two index strings are equal and have a specified length.

Used by nda fallback branches that cannot permute axes and therefore require identical index strings. Also enforces that the strings have length equal to the tensor rank.

Parameters
idx_aFirst index string.
idx_bSecond index string.
rankExpected length of both index strings (the tensor rank).
op_nameName of the calling tensor operation, for the error message (e.g. "add").

Definition at line 247 of file tools.hpp.