pub trait ScalarArithmetic: Scalar {
// Required methods
fn scalar_zero() -> Self;
fn scalar_one() -> Self;
fn scalar_add(self, rhs: Self) -> Self;
fn scalar_sub(self, rhs: Self) -> Self;
fn scalar_mul(self, rhs: Self) -> Self;
}Expand description
Arithmetic a scalar supports under its own rules.
The operations use the scalar’s own semantics, so an integer implementation
wraps exactly as the existing integer kernels do. Complex scalars qualify as
ScalarDomain::Field. bool does not implement this trait: it is a
storable scalar without arithmetic.
§Examples
use tenferro_tensor_core::ScalarArithmetic;
assert_eq!(<f64 as ScalarArithmetic>::scalar_add(1.0, 2.0), 3.0);
assert_eq!(<i32 as ScalarArithmetic>::scalar_add(i32::MAX, 1), i32::MIN);Required Methods§
Sourcefn scalar_zero() -> Self
fn scalar_zero() -> Self
Additive identity.
§Examples
use tenferro_tensor_core::ScalarArithmetic;
assert_eq!(<f64 as ScalarArithmetic>::scalar_zero(), 0.0);Sourcefn scalar_one() -> Self
fn scalar_one() -> Self
Multiplicative identity.
§Examples
use tenferro_tensor_core::ScalarArithmetic;
assert_eq!(<f64 as ScalarArithmetic>::scalar_one(), 1.0);Sourcefn scalar_add(self, rhs: Self) -> Self
fn scalar_add(self, rhs: Self) -> Self
Sum under this scalar’s own semantics.
§Examples
use tenferro_tensor_core::ScalarArithmetic;
assert_eq!(<f64 as ScalarArithmetic>::scalar_add(1.0, 2.0), 3.0);Sourcefn scalar_sub(self, rhs: Self) -> Self
fn scalar_sub(self, rhs: Self) -> Self
Difference under this scalar’s own semantics.
§Examples
use tenferro_tensor_core::ScalarArithmetic;
assert_eq!(<f64 as ScalarArithmetic>::scalar_sub(1.0, 2.0), -1.0);Sourcefn scalar_mul(self, rhs: Self) -> Self
fn scalar_mul(self, rhs: Self) -> Self
Product under this scalar’s own semantics.
§Examples
use tenferro_tensor_core::ScalarArithmetic;
assert_eq!(<f64 as ScalarArithmetic>::scalar_mul(3.0, 4.0), 12.0);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".