|
Stratax 0.4.0rc1
|
Element-wise arithmetic, scalar promotion, and compound assignment. More...
#include <stratax/core/dtypes/Concepts.hpp>#include <stratax/exceptions/Exceptions.hpp>#include <stratax/ops/Broadcasting.hpp>#include <stratax/ops/detail/Compound.hpp>#include <stratax/core/validation/NumericValidation.hpp>#include <functional>

Go to the source code of this file.
Functions | |
| template<Array L, Array R, typename Op > requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| auto | binary_op (const L &lhs, const R &rhs, Op op, bool check_zero_divisor=false) |
| Applies an arithmetic callable to two broadcast-compatible arrays. | |
| template<Array A, Numeric Scalar, typename Op > | |
| auto | binary_scalar_op (const A &lhs, const Scalar &rhs, Op op, bool check_zero_divisor=false) |
Applies an arithmetic callable to an array and a right scalar. The returned array preserves the container family and shape of lhs. Its dtype is selected by the array/scalar promotion rules. | |
| template<Numeric Scalar, Array A, typename Op > | |
| auto | binary_scalar_op (const Scalar &lhs, const A &rhs, Op op, bool check_zero_divisor=false) |
Applies an arithmetic callable to a left scalar and an array. The returned array preserves the container family and shape of rhs. Its dtype is selected by the array/scalar promotion rules. | |
| template<Array L, Array R, typename Op > requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| L & | compound_op (L &lhs, const R &rhs, Op op, bool check_zero_divisor=false) |
| Applies an arithmetic callable in place using array broadcasting. | |
| template<Array A, Numeric S, typename Op > | |
| A & | compound_scalar_op (A &lhs, const S &rhs, Op op, bool check_zero_divisor=false) |
| Applies an arithmetic callable in place with a right scalar. | |
| template<Array L, Array R> requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| auto | operator+ (const L &lhs, const R &rhs) |
| Adds two broadcast-compatible arrays. | |
| template<Array L, Array R> requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| auto | operator- (const L &lhs, const R &rhs) |
| Subtracts two broadcast-compatible arrays. | |
| template<Array L, Array R> requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| auto | operator* (const L &lhs, const R &rhs) |
| Multiplies two broadcast-compatible arrays element-wise. | |
| template<Array L, Array R> requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| auto | operator/ (const L &lhs, const R &rhs) |
| Divides two broadcast-compatible arrays element-wise. | |
| template<Array A, Numeric Scalar> requires Numeric<typename A::value_type> | |
| auto | operator+ (const A &lhs, const Scalar &rhs) |
| Adds a scalar to every array element. | |
| template<Array A, Numeric Scalar> requires Numeric<typename A::value_type> | |
| auto | operator- (const A &lhs, const Scalar &rhs) |
| Subtracts a scalar from every array element. | |
| template<Array A, Numeric Scalar> requires Numeric<typename A::value_type> | |
| auto | operator* (const A &lhs, const Scalar &rhs) |
| Multiplies every array element by a scalar. | |
| template<Array A, Numeric Scalar> requires Numeric<typename A::value_type> | |
| auto | operator/ (const A &lhs, const Scalar &rhs) |
| Divides every array element by a scalar. | |
| template<Numeric Scalar, Array A> requires Numeric<typename A::value_type> | |
| auto | operator+ (const Scalar &lhs, const A &rhs) |
| Adds a scalar to every array element. | |
| template<Numeric Scalar, Array A> | |
| auto | operator- (const Scalar &lhs, const A &rhs) |
| Subtracts every array element from a scalar. | |
| template<Numeric Scalar, Array A> requires Numeric<typename A::value_type> | |
| auto | operator* (const Scalar &lhs, const A &rhs) |
| Multiplies every array element by a scalar. | |
| template<Numeric Scalar, Array A> requires Numeric<typename A::value_type> | |
| auto | operator/ (const Scalar &lhs, const A &rhs) |
| Divides a scalar by every array element. | |
| template<Array L, Array R> requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| L & | operator+= (L &lhs, const R &rhs) |
| Adds a broadcast-compatible array in place. | |
| template<Array L, Array R> requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| L & | operator-= (L &lhs, const R &rhs) |
| Subtracts a broadcast-compatible array in place. | |
| template<Array L, Array R> requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| L & | operator*= (L &lhs, const R &rhs) |
| Multiplies by a broadcast-compatible array in place. | |
| template<Array L, Array R> requires ( Numeric<typename L::value_type> && Numeric<typename R::value_type> ) | |
| L & | operator/= (L &lhs, const R &rhs) |
| Divides by a broadcast-compatible array in place. | |
| template<Array A, Numeric S> requires Numeric<typename A::value_type> | |
| A & | operator+= (A &lhs, const S &rhs) |
| Adds a scalar to every element in place. | |
| template<Array A, Numeric S> requires Numeric<typename A::value_type> | |
| A & | operator-= (A &lhs, const S &rhs) |
| Subtracts a scalar from every element in place. | |
| template<Array A, Numeric S> requires Numeric<typename A::value_type> | |
| A & | operator*= (A &lhs, const S &rhs) |
| Multiplies every element by a scalar in place. | |
| template<Array A, Numeric S> requires Numeric<typename A::value_type> | |
| A & | operator/= (A &lhs, const S &rhs) |
| Divides every element by a scalar in place. | |
| template<Array A> requires Numeric<typename A::value_type> | |
| A | operator- (const A &arr) |
| Returns an owning element-wise negation with the input shape and dtype. | |
| template<Array A> requires Numeric<typename A::value_type> | |
| A | operator+ (const A &arr) |
| Returns a copy of the array object with unchanged values. | |
Element-wise arithmetic, scalar promotion, and compound assignment.
Operations that allocate results require owning-container result trait specializations. Element operators receive the original operand types; the result is converted afterward. Native C++ arithmetic and conversion rules apply, including representability requirements. Division rejects zero and signed expression-type minimum divided by minus one. Compound operations use the operands' initial values, including overlapping views; repeated destination offsets receive the last logical write. Operations involving views stage O(n) results. Allocation failures propagate.
Definition in file Arithmetic.hpp.
| auto binary_op | ( | const L & | lhs, |
| const R & | rhs, | ||
| Op | op, | ||
| bool | check_zero_divisor = false |
||
| ) |
Applies an arithmetic callable to two broadcast-compatible arrays.
Matching container kinds are preserved; mixed kinds produce Tensor. The result uses the promoted dtype of the two operands, has their common broadcasted shape, and owns independent storage. When check_zero_divisor is true, each used broadcasted right-hand value is checked before invoking op.
| L | Left owning Stratax array type. |
| R | Right owning Stratax array type; it may differ from L. |
| Op | Binary arithmetic callable. |
| lhs | Left array operand. |
| rhs | Right array operand. |
| op | Callable invoked for every broadcasted element pair. |
| check_zero_divisor | Whether zero right-hand values are rejected. |
| Exceptions::BroadcastError | If shapes are incompatible or an empty operand would supply values to a nonempty result. |
| Exceptions::ZeroDivisionError | If divisor checking is enabled and a broadcasted right-hand element equals zero. |
| Exceptions::OverflowError | If divisor checking is enabled and signed division is not representable. |
| Any | exception propagated by allocation or op. |
n is result size and r is result rank. Definition at line 53 of file Arithmetic.hpp.
| auto binary_scalar_op | ( | const A & | lhs, |
| const Scalar & | rhs, | ||
| Op | op, | ||
| bool | check_zero_divisor = false |
||
| ) |
Applies an arithmetic callable to an array and a right scalar. The returned array preserves the container family and shape of lhs. Its dtype is selected by the array/scalar promotion rules.
| A | Stratax array and result type. |
| Scalar | Numeric scalar type. |
| Op | Binary arithmetic callable. |
| lhs | Array supplying each left argument. |
| rhs | Scalar supplied as every right argument. |
| op | Callable invoked for each array element. |
| check_zero_divisor | Whether a zero rhs is rejected. |
lhs, and promoted dtype. | Exceptions::ZeroDivisionError | If divisor checking is enabled and rhs equals zero, including when lhs is empty. |
| Exceptions::OverflowError | If divisor checking is enabled and signed division is not representable. |
| Any | exception propagated by allocation or op. |
Definition at line 100 of file Arithmetic.hpp.
| auto binary_scalar_op | ( | const Scalar & | lhs, |
| const A & | rhs, | ||
| Op | op, | ||
| bool | check_zero_divisor = false |
||
| ) |
Applies an arithmetic callable to a left scalar and an array. The returned array preserves the container family and shape of rhs. Its dtype is selected by the array/scalar promotion rules.
| Scalar | Numeric scalar type. |
| A | Stratax array and result type. |
| Op | Binary arithmetic callable. |
| lhs | Scalar supplied as every left argument. |
| rhs | Array supplying each right argument. |
| op | Callable invoked for each array element. |
| check_zero_divisor | Whether zero elements of rhs are rejected. |
rhs, and promoted dtype. | Exceptions::ZeroDivisionError | If divisor checking is enabled and an element of rhs equals zero. |
| Exceptions::OverflowError | If divisor checking is enabled and signed division is not representable. |
| Any | exception propagated by allocation or op. |
Definition at line 138 of file Arithmetic.hpp.
| L & compound_op | ( | L & | lhs, |
| const R & | rhs, | ||
| Op | op, | ||
| bool | check_zero_divisor = false |
||
| ) |
Applies an arithmetic callable in place using array broadcasting.
The right operand may broadcast to the existing shape of lhs, but the operation never resizes or reshapes lhs. Callable results are converted to L::value_type before assignment. All built-in validation precedes writes. Operands are read as they were before mutation; if destination elements alias, the last logical write wins. Non-owning operands require O(n) staging storage. A throwing callable may leave partial writes when both operands own storage.
| L | Mutable left Stratax array type. |
| R | Right Stratax array type. |
| Op | Binary arithmetic callable. |
| lhs | Array modified in place. |
| rhs | Array broadcast over lhs. |
| op | Callable invoked for every used element pair. |
| check_zero_divisor | Whether used zero values from rhs are rejected. |
lhs. | Exceptions::BroadcastError | If the shapes are incompatible or their broadcasted shape differs from the existing shape of lhs. |
| Exceptions::ZeroDivisionError | If divisor checking is enabled and a used right-hand element is zero. |
| Exceptions::OverflowError | If divisor checking is enabled and signed division is not representable. |
| Any | exception propagated by allocation or op. |
n is lhs.size() and r is its rank. Definition at line 185 of file Arithmetic.hpp.
| A & compound_scalar_op | ( | A & | lhs, |
| const S & | rhs, | ||
| Op | op, | ||
| bool | check_zero_divisor = false |
||
| ) |
Applies an arithmetic callable in place with a right scalar.
Callable results are converted to A::value_type before assignment. The scalar is copied first, even when it references a destination element. Views stage O(n) results; repeated destination offsets use the last result. A throwing callable may leave partial writes for owning destinations.
| A | Mutable Stratax array type. |
| S | Numeric scalar type. |
| Op | Binary arithmetic callable. |
| lhs | Array modified in place. |
| rhs | Scalar supplied as every right argument. |
| op | Callable invoked for each element. |
| check_zero_divisor | Whether a zero rhs is rejected. |
lhs. | Exceptions::ZeroDivisionError | If divisor checking is enabled and rhs is zero, including when lhs is empty. |
| Exceptions::OverflowError | If divisor checking is enabled and signed division is not representable. |
| Any | exception propagated by allocation or op. |
Definition at line 246 of file Arithmetic.hpp.
| auto operator* | ( | const A & | lhs, |
| const Scalar & | rhs | ||
| ) |
Multiplies every array element by a scalar.
Definition at line 335 of file Arithmetic.hpp.
| auto operator* | ( | const L & | lhs, |
| const R & | rhs | ||
| ) |
Multiplies two broadcast-compatible arrays element-wise.
| Exceptions::BroadcastError | If shapes are incompatible or an empty operand would supply values to a nonempty result. |
Definition at line 300 of file Arithmetic.hpp.
| auto operator* | ( | const Scalar & | lhs, |
| const A & | rhs | ||
| ) |
Multiplies every array element by a scalar.
Definition at line 366 of file Arithmetic.hpp.
| A & operator*= | ( | A & | lhs, |
| const S & | rhs | ||
| ) |
Multiplies every element by a scalar in place.
lhs. Definition at line 442 of file Arithmetic.hpp.
| L & operator*= | ( | L & | lhs, |
| const R & | rhs | ||
| ) |
Multiplies by a broadcast-compatible array in place.
lhs; its shape is unchanged. | Exceptions::BroadcastError | If broadcasting is impossible or would change the shape of lhs. |
Definition at line 407 of file Arithmetic.hpp.
Returns a copy of the array object with unchanged values.
Definition at line 473 of file Arithmetic.hpp.
| auto operator+ | ( | const A & | lhs, |
| const Scalar & | rhs | ||
| ) |
Adds a scalar to every array element.
Definition at line 319 of file Arithmetic.hpp.
| auto operator+ | ( | const L & | lhs, |
| const R & | rhs | ||
| ) |
Adds two broadcast-compatible arrays.
| Exceptions::BroadcastError | If shapes are incompatible or an empty operand would supply values to a nonempty result. |
Definition at line 278 of file Arithmetic.hpp.
| auto operator+ | ( | const Scalar & | lhs, |
| const A & | rhs | ||
| ) |
Adds a scalar to every array element.
Definition at line 351 of file Arithmetic.hpp.
| A & operator+= | ( | A & | lhs, |
| const S & | rhs | ||
| ) |
Adds a scalar to every element in place.
lhs. Definition at line 426 of file Arithmetic.hpp.
| L & operator+= | ( | L & | lhs, |
| const R & | rhs | ||
| ) |
Adds a broadcast-compatible array in place.
lhs; its shape is unchanged. | Exceptions::BroadcastError | If broadcasting is impossible or would change the shape of lhs. |
Definition at line 385 of file Arithmetic.hpp.
Returns an owning element-wise negation with the input shape and dtype.
| A | Owning numeric array whose value type can be list-initialized from -1. |
Definition at line 462 of file Arithmetic.hpp.
| auto operator- | ( | const A & | lhs, |
| const Scalar & | rhs | ||
| ) |
Subtracts a scalar from every array element.
Definition at line 327 of file Arithmetic.hpp.
| auto operator- | ( | const L & | lhs, |
| const R & | rhs | ||
| ) |
Subtracts two broadcast-compatible arrays.
lhs - rhs result. | Exceptions::BroadcastError | If shapes are incompatible or an empty operand would supply values to a nonempty result. |
Definition at line 289 of file Arithmetic.hpp.
Subtracts every array element from a scalar.
lhs - rhs[i] result. Definition at line 358 of file Arithmetic.hpp.
| A & operator-= | ( | A & | lhs, |
| const S & | rhs | ||
| ) |
Subtracts a scalar from every element in place.
lhs. Definition at line 434 of file Arithmetic.hpp.
| L & operator-= | ( | L & | lhs, |
| const R & | rhs | ||
| ) |
Subtracts a broadcast-compatible array in place.
lhs; its shape is unchanged. | Exceptions::BroadcastError | If broadcasting is impossible or would change the shape of lhs. |
Definition at line 396 of file Arithmetic.hpp.
| auto operator/ | ( | const A & | lhs, |
| const Scalar & | rhs | ||
| ) |
Divides every array element by a scalar.
| Exceptions::ZeroDivisionError | If rhs is zero. |
| Exceptions::OverflowError | If native signed division is not representable. |
Definition at line 343 of file Arithmetic.hpp.
| auto operator/ | ( | const L & | lhs, |
| const R & | rhs | ||
| ) |
Divides two broadcast-compatible arrays element-wise.
| Exceptions::BroadcastError | If shapes are incompatible or an empty operand would supply values to a nonempty result. |
| Exceptions::ZeroDivisionError | If a used divisor element is zero. |
| Exceptions::OverflowError | If native signed division is not representable. |
Definition at line 311 of file Arithmetic.hpp.
| auto operator/ | ( | const Scalar & | lhs, |
| const A & | rhs | ||
| ) |
Divides a scalar by every array element.
lhs / rhs[i] result. | Exceptions::ZeroDivisionError | If any divisor element is zero. |
| Exceptions::OverflowError | If native signed division is not representable. |
Definition at line 374 of file Arithmetic.hpp.
| A & operator/= | ( | A & | lhs, |
| const S & | rhs | ||
| ) |
Divides every element by a scalar in place.
lhs. | Exceptions::ZeroDivisionError | If rhs is zero, including for an empty array. |
| Exceptions::OverflowError | If native signed division is not representable. |
Definition at line 450 of file Arithmetic.hpp.
| L & operator/= | ( | L & | lhs, |
| const R & | rhs | ||
| ) |
Divides by a broadcast-compatible array in place.
lhs; its shape is unchanged. | Exceptions::BroadcastError | If broadcasting is impossible or would change the shape of lhs. |
| Exceptions::ZeroDivisionError | If a used divisor is zero. |
| Exceptions::OverflowError | If native signed division is not representable. |
Definition at line 418 of file Arithmetic.hpp.