22namespace nda::tensor {
63 template <BlasArrayOrConj A, BlasArrayFor<A> B>
68 static_assert(!run_on_device ||
have_cutensor,
"nda::tensor::elementwise: cuTENSOR support is required");
69 static_assert(run_on_device ||
get_rank<A> ==
get_rank<B>,
"nda::tensor::elementwise: host fallback requires identical ranks");
72 if constexpr (run_on_device) {
73 device::elementwise_binary(alpha, a, idx_a, beta, b, idx_b, b, op);
76 b =
nda::map([alpha, beta, op](
auto x,
auto y) {
return detail::apply_binary(op, alpha * x, beta * y); })(a, b);
81 template <BlasArrayOrConj A, BlasArrayFor<A> B>
82 void elementwise(A
const &a, std::string_view idx_a, B &&b, std::string_view idx_b,
binary_op op = binary_op::SUM) {
87 template <BlasArrayOrConj A, BlasArrayFor<A> B>
96 template <BlasArrayOrConj A, BlasArrayFor<A> B>
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(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.
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.
std::string_view default_index()
Generate a default index string ("abc...") of a given length.
Provides type traits for the nda library.