pub trait Scalar:
Clone
+ Copy
+ Zero
+ One
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self>
+ Neg<Output = Self>
+ Default
+ Send
+ Sync
+ MatrixScalar
+ 'static {
// Required methods
fn conj(self) -> Self;
fn abs_sq(self) -> f64;
fn abs(self) -> Self;
fn from_f64(val: f64) -> Self;
fn div_real(self, divisor: f64) -> Self;
fn is_nan(self) -> bool;
// Provided methods
fn abs_val(self) -> f64 { ... }
fn min_positive() -> f64 { ... }
fn epsilon() -> f64 { ... }
}Expand description
Common scalar trait for matrix and tensor operations.
Defines the minimal requirements for scalar types used in matrix cross
interpolation and tensor train operations. Implemented for f64, f32,
Complex64, and Complex32.
§Examples
use tensor4all_core::Scalar;
// f64
let x = 3.0_f64;
assert_eq!(x.abs_sq(), 9.0);
assert_eq!(x.conj(), 3.0);
// Complex64
use num_complex::Complex64;
let z = Complex64::new(3.0, 4.0);
assert!((z.abs_sq() - 25.0).abs() < 1e-10);
assert_eq!(z.conj(), Complex64::new(3.0, -4.0));
// Construction from f64
let val = f64::from_f64(2.5);
assert_eq!(val, 2.5);Required Methods§
Sourcefn abs(self) -> Self
fn abs(self) -> Self
Absolute value as Self type.
For real types, this returns the absolute value. For complex types, this returns a real-valued complex (re=|z|, im=0).
Sourcefn div_real(self, divisor: f64) -> Self
fn div_real(self, divisor: f64) -> Self
Divide by a real scalar without forming a complex squared norm.
The divisor is converted to the underlying real component precision. IEEE division semantics apply for zero or non-finite divisors.
§Examples
use tensor4all_core::Scalar;
use num_complex::Complex64;
let value = Complex64::new(1e200, 5e199).div_real(1e200);
assert_eq!(value, Complex64::new(1.0, 0.5));Provided Methods§
Sourcefn min_positive() -> f64
fn min_positive() -> f64
Smallest positive normal value of the underlying real component type.
This bounds squared-magnitude arithmetic; subnormal values remain valid
inputs. Returns f64::MIN_POSITIVE by default.
§Examples
use tensor4all_core::Scalar;
assert_eq!(f32::min_positive(), f32::MIN_POSITIVE as f64);
assert_eq!(f64::min_positive(), f64::MIN_POSITIVE);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".