22namespace nda::tensor {
71 template <BlasArrayOrConj A, BlasArrayOrConjFor<A> B, BlasArrayFor<A> C>
77 static_assert(!run_on_device ||
have_cutensor,
"nda::tensor::elementwise_trinary: cuTENSOR support is required");
79 "nda::tensor::elementwise_trinary: host fallback requires identical ranks");
82 if constexpr (run_on_device) {
83 device::elementwise_trinary(alpha, a, idx_a, beta, b, idx_b, gamma, c, idx_c, c, op_AB, op_ABC);
87 c =
nda::map([alpha, beta, gamma, op_AB, op_ABC](
auto x,
auto y,
auto z) {
88 return detail::apply_binary(op_ABC, detail::apply_binary(op_AB, alpha * x, beta * y), gamma * z);
94 template <BlasArrayOrConj A, BlasArrayOrConjFor<A> B, BlasArrayFor<A> C>
95 void 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,
97 elementwise_trinary(
get_value_t<A>{1}, a, idx_a,
get_value_t<A>{1}, b, idx_b,
get_value_t<A>{0}, std::forward<C>(c), idx_c, op_AB, op_ABC);
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides a C++ interface for various cuTENSOR routines.
Provides a custom runtime error class and macros to assert conditions and throw exceptions.
mapped< F > map(F f)
Create a lazy function call expression on arrays/views.
constexpr int get_rank
Constexpr variable that specifies the rank of an nda::Array or of a contiguous 1-dimensional range.
std::decay_t< decltype(get_first_element(std::declval< A const >()))> get_value_t
Get the value type of an array/view or a scalar type.
static constexpr bool have_device_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Device.
void 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.
static constexpr bool have_cutensor
Constexpr variable that is true if nda is configured cuTENSOR support.
binary_op
Binary operations for tensor operations.
void 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.
Provides type traits for the nda library.