Skip to main content

ScalarValue

Enum ScalarValue 

Source
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

Source

pub fn real(self) -> f64

Real part as f64; 0.0 imaginary means the value equals this.

Source

pub fn imag(self) -> f64

Imaginary part as f64; 0.0 for the non-complex variants.

Source

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.

Source

pub fn is_complex(self) -> bool

Whether this is one of the complex variants.

Source

pub fn is_zero(self) -> bool

Exact comparison against zero of the variant’s own payload type.

Source

pub fn into_complex(self) -> Complex64

Value widened to Complex64 with a zero imaginary part when real.

Trait Implementations§

Source§

impl Clone for ScalarValue

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ScalarValue

Source§

impl Debug for ScalarValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Complex<f32>> for ScalarValue

Source§

fn from(value: Complex32) -> Self

Converts to this type from the input type.
Source§

impl From<Complex<f64>> for ScalarValue

Source§

fn from(value: Complex64) -> Self

Converts to this type from the input type.
Source§

impl From<ScalarValue> for BackendScalar

Source§

fn from(value: ScalarValue) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for ScalarValue

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for ScalarValue

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ScalarValue

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ScalarValue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Boilerplate for T
where T: Copy + Send + Sync + Debug + PartialEq + 'static,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V