pub trait Element:
Copy
+ Clone
+ Send
+ Sync
+ Pod
+ Zeroable
+ 'static
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self>
+ PartialOrd {
const DTYPE: DType;
// Required methods
fn to_f64(self) -> f64;
fn from_f64(v: f64) -> Self;
fn zero() -> Self;
fn one() -> Self;
// Provided methods
fn to_f32(self) -> f32 { ... }
fn from_f32(v: f32) -> Self { ... }
}Expand description
Trait for types that can be elements of a tensor
This trait connects Rust’s type system to numr’s runtime dtype system. It’s implemented for all primitive numeric types.
§Bounds
Copy + Clone + Send + Sync + 'static- Basic trait requirementsPod + Zeroable- Safe memory transmutation (bytemuck)Add + Sub + Mul + Div- Arithmetic operations (Output = Self)PartialOrd- Comparison for min/max operations
Note: Neg is NOT required since unsigned types don’t support it.
Negation is handled via to_f64/from_f64 conversion in kernels.
Required Associated Constants§
Required Methods§
Sourcefn to_f64(self) -> f64
fn to_f64(self) -> f64
Convert to f64 for generic numeric operations
§Complex Number Behavior
For complex types (Complex64, Complex128), this returns the magnitude (|z|), not the real part. This is consistent with:
- PartialOrd using magnitude for comparison
- The need for a single scalar representation
If you need the real part, access .re directly on the complex type.
Provided Methods§
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.