Skip to main content

Scalar

Trait Scalar 

pub trait Scalar:
    Clone
    + Copy
    + Zero<Output = Self>
    + One<Output = Self>
    + Add
    + Sub<Output = Self>
    + Mul
    + Div<Output = Self>
    + Neg<Output = Self>
    + Default
    + Send
    + Sync
    + BlasMul
    + 'static {
    // Required methods
    fn conj(self) -> Self;
    fn abs_sq(self) -> f64;
    fn abs(self) -> Self;
    fn from_f64(val: f64) -> Self;
    fn is_nan(self) -> bool;

    // Provided methods
    fn abs_val(self) -> 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_tcicore::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§

fn conj(self) -> Self

Complex conjugate of the value.

fn abs_sq(self) -> f64

Square of the absolute value (for complex numbers, |z|^2).

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).

fn from_f64(val: f64) -> Self

Create from f64 value.

fn is_nan(self) -> bool

Check if value is NaN.

Provided Methods§

fn abs_val(self) -> f64

Absolute value as f64.

fn epsilon() -> f64

Machine epsilon for numerical comparisons.

Returns f64::EPSILON (~2.2e-16) by default. This is the smallest value such that 1.0 + epsilon != 1.0.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl Scalar for f32

§

fn conj(self) -> f32

§

fn abs_sq(self) -> f64

§

fn abs(self) -> f32

§

fn abs_val(self) -> f64

§

fn from_f64(val: f64) -> f32

§

fn is_nan(self) -> bool

§

impl Scalar for f64

§

fn conj(self) -> f64

§

fn abs_sq(self) -> f64

§

fn abs(self) -> f64

§

fn abs_val(self) -> f64

§

fn from_f64(val: f64) -> f64

§

fn is_nan(self) -> bool

§

impl Scalar for Complex<f32>

§

fn conj(self) -> Complex<f32>

§

fn abs_sq(self) -> f64

§

fn abs(self) -> Complex<f32>

§

fn abs_val(self) -> f64

§

fn from_f64(val: f64) -> Complex<f32>

§

fn is_nan(self) -> bool

§

impl Scalar for Complex<f64>

§

fn conj(self) -> Complex<f64>

§

fn abs_sq(self) -> f64

§

fn abs(self) -> Complex<f64>

§

fn abs_val(self) -> f64

§

fn from_f64(val: f64) -> Complex<f64>

§

fn is_nan(self) -> bool

Implementors§