pub enum ScalarValue {
F32(f32),
F64(f64),
I32(i32),
I64(i64),
Bool(bool),
C32(Complex32),
C64(Complex64),
}Expand description
Dynamic scalar value shared by every tensor4all scalar wrapper.
This is the single definition of the dynamic scalar value: BackendScalar
here and tensor4all_core::AnyScalar both hold one and delegate their value
accessors (real, imag, abs,
is_complex, is_zero,
into_complex) to it, so the two wrappers cannot
disagree on a value. It is public because the core scalar wrapper lives in a
downstream crate; the wrappers, not this enum, are the user-facing API.
The variants are exactly the scalar payloads this backend can hold: the four
floating types (ScalarTensorElement) and the three non-floating kinds a
rank-0 native tensor can carry. tensor4all_core only ever constructs the
floating variants, because it reads values from IdxTensor, whose element
types are ScalarTensorElement.
Variants§
F32(f32)
32-bit floating point.
F64(f64)
64-bit floating point.
I32(i32)
32-bit signed integer.
I64(i64)
64-bit signed integer.
Bool(bool)
Boolean.
C32(Complex32)
32-bit complex floating point.
C64(Complex64)
64-bit complex floating point.
Implementations§
Source§impl ScalarValue
impl ScalarValue
Sourcepub fn abs(self) -> f64
pub fn abs(self) -> f64
Magnitude as f64.
Integer and boolean kinds widen with as/From conversions, so an
integer above 2^53 rounds to the nearest f64 before the absolute value
is taken (never negated, so i32::MIN and i64::MIN stay correct).
Both complex kinds widen their parts to f64 first and then use
f64::hypot, so a c32 magnitude is not rounded through an f32
intermediate. Any NaN part yields NaN.
Sourcepub fn is_complex(self) -> bool
pub fn is_complex(self) -> bool
Whether this is one of the complex variants.
Sourcepub fn into_complex(self) -> Complex64
pub fn into_complex(self) -> Complex64
Value widened to Complex64 with a zero imaginary part when real.
Trait Implementations§
Source§impl Clone for ScalarValue
impl Clone for ScalarValue
impl Copy for ScalarValue
Source§impl Debug for ScalarValue
impl Debug for ScalarValue
Source§impl From<ScalarValue> for BackendScalar
impl From<ScalarValue> for BackendScalar
Source§fn from(value: ScalarValue) -> Self
fn from(value: ScalarValue) -> Self
Source§impl From<f32> for ScalarValue
impl From<f32> for ScalarValue
Source§impl From<f64> for ScalarValue
impl From<f64> for ScalarValue
Source§impl PartialEq for ScalarValue
impl PartialEq for ScalarValue
impl StructuralPartialEq for ScalarValue
Auto Trait Implementations§
impl Freeze for ScalarValue
impl RefUnwindSafe for ScalarValue
impl Send for ScalarValue
impl Sync for ScalarValue
impl Unpin for ScalarValue
impl UnsafeUnpin for ScalarValue
impl UnwindSafe for ScalarValue
Blanket Implementations§
impl<T> Boilerplate for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more