|
TRIQS/nda 2.0.0
Multi-dimensional array library for C++
|
User-facing tensor operations dispatched to cuTENSOR, TBLIS, or the nda fallback.
Every function in this group lives in the nda::tensor namespace and follows the same dispatch rules outlined in Tensor support. The available operations are:
Backend coverage and the existence of an nda fallback differ between operations; the per-function page is authoritative on which dispatch paths and which nda::tensor::binary_op and nda::tensor::unary_op are supported.
Functions | |
| template<BlasArrayOrConj A, BlasArrayFor< A > B> | |
| void | nda::tensor::add (A const &a, B &&b) |
| Convenience overload of nda::tensor::add with nda::tensor::default_index strings, \( \alpha = 1 \) and \( \beta = 0 \). | |
| template<BlasArrayOrConj A, BlasArrayFor< A > B> | |
| void | nda::tensor::add (A const &a, std::string_view idx_a, B &&b, std::string_view idx_b) |
| Convenience overload of nda::tensor::add with \( \alpha = 1 \) and \( \beta = 0 \). | |
| template<BlasArrayOrConj A, BlasArrayOrConjFor< A > B, BlasArrayFor< A > C> | |
| void | nda::tensor::add (A const &a, std::string_view idx_a, B const &b, std::string_view idx_b, C &&c, std::string_view idx_c) |
| Convenience overload of out-of-place nda::tensor::add with \( \alpha = 1 \) and \( \beta = 1 \). | |
| template<BlasArrayOrConj A, BlasArrayFor< A > B> | |
| void | nda::tensor::add (get_value_t< A > alpha, A const &a, get_value_t< A > beta, B &&b) |
| Convenience overload of nda::tensor::add with nda::tensor::default_index strings. | |
| template<BlasArrayOrConj A, BlasArrayFor< A > B> | |
| void | nda::tensor::add (get_value_t< A > alpha, A const &a, std::string_view idx_a, get_value_t< A > beta, B &&b, std::string_view idx_b) |
| Tensor addition with cuTENSOR/TBLIS/nda dispatch. | |
| template<BlasArrayOrConj A, BlasArrayOrConjFor< A > B, BlasArrayFor< A > C> | |
| void | nda::tensor::add (get_value_t< A > alpha, A const &a, std::string_view idx_a, get_value_t< A > beta, B const &b, std::string_view idx_b, C &&c, std::string_view idx_c) |
| Out-of-place tensor addition with cuTENSOR/TBLIS/nda dispatch. | |
|
template<MemoryArray A, MemoryArray B> requires (have_same_value_type_v<A, B>) | |
| void | nda::tensor::assign (A const &a, B &&b) |
| Convenience overload of nda::tensor::assign with nda::tensor::default_index strings. | |
| template<MemoryArray A, MemoryArray B> requires (have_same_value_type_v<A, B>) | |
| void | nda::tensor::assign (A const &a, std::string_view idx_a, B &&b, std::string_view idx_b) |
| Tensor assignment with cuTENSOR/TBLIS/nda dispatch. | |
| template<BlasArrayOrConj A, BlasArrayOrConjFor< A > B, BlasArrayFor< A > C> | |
| void | nda::tensor::contract (A const &a, std::string_view idx_a, B const &b, std::string_view idx_b, C &&c, std::string_view idx_c) |
| Convenience overload of nda::tensor::contract with \( \alpha = 1 \) and \( \beta = 0 \). | |
| template<BlasArrayOrConj A, BlasArrayOrConjFor< A > B, BlasArrayFor< A > C> | |
| void | nda::tensor::contract (get_value_t< A > alpha, A const &a, std::string_view idx_a, B const &b, std::string_view idx_b, get_value_t< A > beta, C &&c, std::string_view idx_c) |
| Tensor contraction with cuTENSOR/TBLIS dispatch. | |
| template<BlasArrayOrConj A, BlasArrayOrConjFor< A, get_rank< A > > B> | |
| get_value_t< A > | nda::tensor::dot (A const &a, B const &b) |
| Convenience overload of nda::tensor::dot with nda::tensor::default_index strings. | |
| template<BlasArrayOrConj A, BlasArrayOrConjFor< A > B> | |
| get_value_t< A > | nda::tensor::dot (A const &a, std::string_view idx_a, B const &b, std::string_view idx_b) |
| Full tensor dot product with cuTENSOR/TBLIS/nda dispatch. | |
| template<BlasArrayOrConj A, BlasArrayFor< A > B> | |
| void | nda::tensor::elementwise (A const &a, B &&b, binary_op op=binary_op::SUM) |
| Convenience overload of nda::tensor::elementwise with nda::tensor::default_index strings, \( \alpha = 1 \) and \( \beta = 0 \). | |
| template<BlasArrayOrConj A, BlasArrayFor< A > B> | |
| void | nda::tensor::elementwise (A const &a, std::string_view idx_a, B &&b, std::string_view idx_b, binary_op op=binary_op::SUM) |
| Convenience overload of nda::tensor::elementwise with \( \alpha = 1 \) and \( \beta = 0 \). | |
| template<BlasArrayOrConj A, BlasArrayFor< A > B> | |
| void | nda::tensor::elementwise (get_value_t< A > alpha, A const &a, get_value_t< A > beta, B &&b, binary_op op=binary_op::SUM) |
| Convenience overload of nda::tensor::elementwise with nda::tensor::default_index strings. | |
| template<BlasArrayOrConj A, BlasArrayFor< A > B> | |
| void | nda::tensor::elementwise (get_value_t< A > alpha, A const &a, std::string_view idx_a, get_value_t< A > beta, B &&b, std::string_view idx_b, binary_op op=binary_op::SUM) |
| In-place elementwise binary tensor operation with cuTENSOR/nda dispatch. | |
| template<BlasArrayOrConj A, BlasArrayOrConjFor< A > B, BlasArrayFor< A > C> | |
| void | nda::tensor::elementwise_trinary (A const &a, std::string_view idx_a, B const &b, std::string_view idx_b, C &&c, std::string_view idx_c, binary_op op_AB=binary_op::SUM, binary_op op_ABC=binary_op::SUM) |
| Convenience overload of nda::tensor::elementwise_trinary with \( \alpha = \beta = 1 \) and \( \gamma = 0 \). | |
| template<BlasArrayOrConj A, BlasArrayOrConjFor< A > B, BlasArrayFor< A > C> | |
| void | nda::tensor::elementwise_trinary (get_value_t< A > alpha, A const &a, std::string_view idx_a, get_value_t< A > beta, B const &b, std::string_view idx_b, get_value_t< A > gamma, C &&c, std::string_view idx_c, binary_op op_AB=binary_op::SUM, binary_op op_ABC=binary_op::SUM) |
| In-place elementwise trinary tensor operation with cuTENSOR/nda dispatch. | |
| template<BlasArrayOrConj A> | |
| get_value_t< A > | nda::tensor::reduce (A const &a, binary_op op_reduce=binary_op::SUM) |
| Full tensor reduction with cuTENSOR/TBLIS/nda dispatch. | |
| template<BlasArray A> | |
| void | nda::tensor::scale (get_value_t< A > alpha, A &&a, unary_op op=unary_op::IDENTITY) |
| In-place tensor scaling with cuTENSOR/TBLIS/nda dispatch and optional element-wise unary operation. | |
| template<BlasArray A> | |
| void | nda::tensor::set (get_value_t< A > alpha, A &&a) |
| In-place tensor constant fill with cuTENSOR/TBLIS/nda dispatch. | |
| void nda::tensor::add | ( | get_value_t< A > | alpha, |
| A const & | a, | ||
| std::string_view | idx_a, | ||
| get_value_t< A > | beta, | ||
| B && | b, | ||
| std::string_view | idx_b ) |
#include <nda/tensor/add.hpp>
Tensor addition with cuTENSOR/TBLIS/nda dispatch.
This function performs a general tensor addition of the form
\[ B_{\text{idx}_B} \leftarrow \alpha \, A_{\text{idx}_A} + \beta \, B_{\text{idx}_B} \;, \]
where \( \alpha \) and \( \beta \) are scalars, and \( A \) and \( B \) are tensors of arbitrary (possibly different) rank. The index strings specify the einsum-style mapping between dimensions of \( A \) and \( B \); indices present in one tensor but absent from the other drive broadcast/reduction on the backend.
The nda host fallback requires identical ranks and identical index strings. For the other backend paths, all inputs are forwarded as-is.
| A | nda::blas_lapack::BlasArrayOrConj type. |
| B | nda::blas_lapack::BlasArrayFor type. |
| alpha | Input scalar \( \alpha \). |
| a | Input tensor \( A \). |
| idx_a | Index string \( \text{idx}_A \) for tensor \( A \). |
| beta | Input scalar \( \beta \). |
| b | Input/Output tensor \( B \). |
| idx_b | Index string \( \text{idx}_B \) for tensor \( B \). |
| void nda::tensor::add | ( | get_value_t< A > | alpha, |
| A const & | a, | ||
| std::string_view | idx_a, | ||
| get_value_t< A > | beta, | ||
| B const & | b, | ||
| std::string_view | idx_b, | ||
| C && | c, | ||
| std::string_view | idx_c ) |
#include <nda/tensor/add.hpp>
Out-of-place tensor addition with cuTENSOR/TBLIS/nda dispatch.
This function performs a general out-of-place tensor addition of the form
\[ C_{\text{idx}_C} \leftarrow \alpha \, A_{\text{idx}_A} + \beta \, B_{\text{idx}_B} \;, \]
where \( \alpha \) and \( \beta \) are scalars, and \( A \), \( B \) and \( C \) are tensors of arbitrary (possibly different) rank. The result is written into the separate output tensor \( C \) (any prior contents of \( C \) are overwritten). The index strings specify the einsum-style mapping between operand dimensions; indices present in some operands but absent from others drive broadcast/reduction on the backend.
The nda host fallback requires identical ranks and identical index strings. For the other backend paths, all inputs are forwarded as-is.
| A | nda::blas_lapack::BlasArrayOrConj type. |
| B | nda::blas_lapack::BlasArrayOrConjFor type. |
| C | nda::blas_lapack::BlasArrayFor type. |
| alpha | Input scalar \( \alpha \). |
| a | Input tensor \( A \). |
| idx_a | Index string \( \text{idx}_A \) for tensor \( A \). |
| beta | Input scalar \( \beta \). |
| b | Input tensor \( B \). |
| idx_b | Index string \( \text{idx}_B \) for tensor \( B \). |
| c | Output tensor \( C \). |
| idx_c | Index string \( \text{idx}_C \) for tensor \( C \). |
| void nda::tensor::assign | ( | A const & | a, |
| std::string_view | idx_a, | ||
| B && | b, | ||
| std::string_view | idx_b ) |
#include <nda/tensor/assign.hpp>
Tensor assignment with cuTENSOR/TBLIS/nda dispatch.
This function performs the assignment
\[ B_{\text{idx}_B} \leftarrow A_{\text{idx}_A} \;, \]
where \( A \) and \( B \) are tensors of arbitrary (possibly different) rank. The index strings specify the einsum-style mapping between dimensions of \( A \) and \( B \), allowing for permutations of axes; when ranks differ, indices present in one tensor but absent from the other drive broadcast/reduction on the backend.
The nda host fallback and the cross-memory copy require identical ranks and identical index strings. The cross-memory copy descends the leading axis until reaching a slice that nda can handle directly (rank-1, contiguous, or strided-1d). For the cuTENSOR and TBLIS dispatch paths, all inputs are forwarded as-is to the backend.
| A | nda::MemoryArray type. |
| B | nda::MemoryArray type with the same value type as \( A \) (rank may differ from A). |
| a | Input tensor \( A \). |
| idx_a | Index string \( \text{idx}_A \) for tensor \( A \). |
| b | Output tensor \( B \). |
| idx_b | Index string \( \text{idx}_B \) for tensor \( B \). |
Definition at line 102 of file assign.hpp.
| void nda::tensor::contract | ( | get_value_t< A > | alpha, |
| A const & | a, | ||
| std::string_view | idx_a, | ||
| B const & | b, | ||
| std::string_view | idx_b, | ||
| get_value_t< A > | beta, | ||
| C && | c, | ||
| std::string_view | idx_c ) |
#include <nda/tensor/contract.hpp>
Tensor contraction with cuTENSOR/TBLIS dispatch.
This function performs a general tensor contraction of the form
\[ C_{\text{idx}_C} \leftarrow \alpha \, A_{\text{idx}_A} \cdot B_{\text{idx}_B} + \beta \, C_{\text{idx}_C} \;, \]
where \( \alpha \) and \( \beta \) are scalars, and \( A \), \( B \) and \( C \) are tensors of arbitrary rank. The contraction pattern is specified via index strings (Einstein notation), where repeated indices between \( A \) and \( B \) are summed over.
Index strings are forwarded as-is to the backend library (cuTENSOR or TBLIS) without any checks. It's the user's responsibility to ensure that they are valid and consistent with the shapes of the input tensors.
| A | nda::blas_lapack::BlasArrayOrConj type. |
| B | nda::blas_lapack::BlasArrayOrConjFor type. |
| C | nda::blas_lapack::BlasArrayFor type. |
| alpha | Input scalar \( \alpha \). |
| a | Input tensor \( A \). |
| idx_a | Index string \( \text{idx}_A \) for tensor \( A \). |
| b | Input tensor \( B \). |
| idx_b | Index string \( \text{idx}_B \) for tensor \( B \). |
| beta | Input scalar \( \beta \). |
| c | Input/Output tensor \( C \). |
| idx_c | Index string \( \text{idx}_C \) for tensor \( C \). |
Definition at line 66 of file contract.hpp.
| get_value_t< A > nda::tensor::dot | ( | A const & | a, |
| std::string_view | idx_a, | ||
| B const & | b, | ||
| std::string_view | idx_b ) |
#include <nda/tensor/dot.hpp>
Full tensor dot product with cuTENSOR/TBLIS/nda dispatch.
This function computes the full tensor dot product
\[ z \leftarrow \sum_{\text{idx}_A = \text{idx}_B} A_{\text{idx}_A} \cdot B_{\text{idx}_B} \;, \]
where \( z \) is a scalar of the same value type as \( A \) and \( B \). The tensors may have arbitrary (possibly different) rank. The index strings define the einsum-style pairing of dimensions.
For the cuTENSOR and TBLIS dispatch paths, index strings are forwarded as-is to the backend library without any checks. It's the user's responsibility to ensure that they are valid and consistent with the shapes of the input tensors.
| A | nda::blas_lapack::BlasArrayOrConj type. |
| B | nda::blas_lapack::BlasArrayOrConjFor type. |
| a | Input tensor \( A \). |
| idx_a | Index string \( \text{idx}_A \) for tensor \( A \). |
| b | Input tensor \( B \). |
| idx_b | Index string \( \text{idx}_B \) for tensor \( B \). |
| void nda::tensor::elementwise | ( | get_value_t< A > | alpha, |
| A const & | a, | ||
| std::string_view | idx_a, | ||
| get_value_t< A > | beta, | ||
| B && | b, | ||
| std::string_view | idx_b, | ||
| binary_op | op = binary_op::SUM ) |
#include <nda/tensor/elementwise.hpp>
In-place elementwise binary tensor operation with cuTENSOR/nda dispatch.
This function performs an in-place elementwise binary operation of the form
\[ B_{\text{idx}_B} \leftarrow \text{op}\bigl(\alpha \, A_{\text{idx}_A}, \, \beta \, B_{\text{idx}_B}\bigr) \;, \]
where \( \alpha \) and \( \beta \) are scalars, \( A \) and \( B \) are tensors, and \( \text{op} \) is a binary operation (see nda::tensor::binary_op). The index strings specify how the dimensions of \( A \) map to those of \( B \) (Einstein notation); when ranks differ on the cuTENSOR path, indices present in one tensor but absent from the other drive broadcast/reduction on the backend.
The supported binary operations depend on the library backend. The nda host fallback requires identical ranks and identical index strings and supports all nda::tensor::binary_op values.
| A | nda::blas_lapack::BlasArrayOrConj type. |
| B | nda::blas_lapack::BlasArrayFor type. |
| alpha | Input scalar \( \alpha \). |
| a | Input tensor \( A \). |
| idx_a | Index string \( \text{idx}_A \) for tensor \( A \). |
| beta | Input scalar \( \beta \). |
| b | Input/Output tensor \( B \). |
| idx_b | Index string \( \text{idx}_B \) for tensor \( B \). |
| op | Binary operation (default: binary_op::SUM). |
Definition at line 64 of file elementwise.hpp.
| void nda::tensor::elementwise_trinary | ( | get_value_t< A > | alpha, |
| A const & | a, | ||
| std::string_view | idx_a, | ||
| get_value_t< A > | beta, | ||
| B const & | b, | ||
| std::string_view | idx_b, | ||
| get_value_t< A > | gamma, | ||
| C && | c, | ||
| std::string_view | idx_c, | ||
| binary_op | op_AB = binary_op::SUM, | ||
| binary_op | op_ABC = binary_op::SUM ) |
#include <nda/tensor/elementwise_trinary.hpp>
In-place elementwise trinary tensor operation with cuTENSOR/nda dispatch.
This function performs an in-place elementwise trinary operation of the form
\[ C_{\text{idx}_C} \leftarrow \text{op}_{ABC} \bigl( \text{op}_{AB} \bigl( \alpha \, A_{\text{idx}_A}, \, \beta \, B_{\text{idx}_B} \bigr), \, \gamma \, C_{\text{idx}_C} \bigr) \;, \]
where \( \alpha \), \( \beta \) and \( \gamma \) are scalars, \( A \), \( B \) and \( C \) are tensors of arbitrary (possibly different) ranks, and \( \text{op}_{ABC} \) and \( \text{op}_{AB} \) are binary operations (see nda::tensor::binary_op). The index strings determine the einsum-style mapping between operands; indices absent from one operand drive broadcast/reduction on the backend.
The supported binary operations depend on the library backend. The nda host fallback requires identical ranks and identical index strings and supports all nda::tensor::binary_op values for both op_AB and op_ABC.
| A | nda::blas_lapack::BlasArrayOrConj type. |
| B | nda::blas_lapack::BlasArrayOrConjFor type. |
| C | nda::blas_lapack::BlasArrayFor type. |
| alpha | Input scalar \( \alpha \). |
| a | Input tensor \( A \). |
| idx_a | Index string \( \text{idx}_A \) for tensor \( A \). |
| beta | Input scalar \( \beta \). |
| b | Input tensor \( B \). |
| idx_b | Index string \( \text{idx}_B \) for tensor \( B \). |
| gamma | Input scalar \( \gamma \). |
| c | Input/Output tensor \( C \). |
| idx_c | Index string \( \text{idx}_C \) for tensor \( C \). |
| op_AB | Binary operation between \( A \) and \( B \) (default: binary_op::SUM). |
| op_ABC | Binary operation between the result of \( \text{op}_{AB} \) and \( C \) (default: binary_op::SUM). |
Definition at line 72 of file elementwise_trinary.hpp.
| get_value_t< A > nda::tensor::reduce | ( | A const & | a, |
| binary_op | op_reduce = binary_op::SUM ) |
#include <nda/tensor/reduce.hpp>
Full tensor reduction with cuTENSOR/TBLIS/nda dispatch.
This function applies a binary reduction operation (sum, max, min, ...) over all elements of a tensor and returns the resulting scalar
\[ z \leftarrow \text{op}_{\text{red}}(A) \;, \]
where \( A \) is a tensor of arbitrary rank and \( \text{op}_{\text{red}} \) is a binary reduction operation (see nda::tensor::binary_op).
The supported binary operations depend on the library backend. The nda fallback supports all nda::tensor::binary_op values.
| A | nda::blas_lapack::BlasArrayOrConj type. |
| a | Input tensor \( A \). |
| op_reduce | Binary reduction operation (default: binary_op::SUM). |
Definition at line 67 of file reduce.hpp.
| void nda::tensor::scale | ( | get_value_t< A > | alpha, |
| A && | a, | ||
| unary_op | op = unary_op::IDENTITY ) |
#include <nda/tensor/scale.hpp>
In-place tensor scaling with cuTENSOR/TBLIS/nda dispatch and optional element-wise unary operation.
This function performs an in-place scaling of the form
\[ A \leftarrow \alpha \, \text{op}(A) \;, \]
where \( \alpha \) is a scalar, \( A \) is a tensor of arbitrary rank, and op is an element-wise unary operation (see nda::tensor::unary_op).
The nda fallback supports unary_op::IDENTITY, unary_op::CONJ, unary_op::SQRT, unary_op::ABS, unary_op::EXP, unary_op::LOG, and unary_op::RCP. Other operations raise NDA_RUNTIME_ERROR.
| A | nda::blas_lapack::BlasArray type. |
| alpha | Input scalar \( \alpha \). |
| a | Input/Output tensor \( A \). |
| op | Unary operation to apply element-wise (default: nda::tensor::unary_op::IDENTITY). |
| void nda::tensor::set | ( | get_value_t< A > | alpha, |
| A && | a ) |
#include <nda/tensor/set.hpp>
In-place tensor constant fill with cuTENSOR/TBLIS/nda dispatch.
This function sets every element of a tensor to a constant value
\[ A \leftarrow \alpha \;, \]
where \( \alpha \) is a scalar and \( A \) is a tensor of arbitrary rank.
| A | nda::blas_lapack::BlasArray type. |
| alpha | Input scalar \( \alpha \). |
| a | Output tensor \( A \). |