DType

Enum DType 

Source
pub enum DType {
    Float32,
    Float16,
    Float64,
    Int8,
    Int16,
    Int32,
    Int64,
    Uint8,
    Uint16,
    Uint32,
    Uint64,
    Bool,
}
Expand description

Numerical data type for array contents.

Corresponds to jax-js DType enum. Supports basic types that can be efficiently worked with on the web.

Variants§

§

Float32

32-bit floating point

§

Float16

16-bit floating point (stored as u16 bits)

§

Float64

64-bit floating point

§

Int8

8-bit signed integer

§

Int16

16-bit signed integer

§

Int32

32-bit signed integer

§

Int64

64-bit signed integer

§

Uint8

8-bit unsigned integer

§

Uint16

16-bit unsigned integer

§

Uint32

32-bit unsigned integer

§

Uint64

64-bit unsigned integer

§

Bool

Boolean (stored as 1-byte value)

Implementations§

Source§

impl DType

Source

pub const fn byte_width(self) -> usize

Returns the byte width of this dtype.

Source

pub const fn is_float(self) -> bool

Returns true if this is a floating-point dtype.

Source

pub const fn is_int(self) -> bool

Returns true if this is an integer dtype.

Source

pub const fn is_signed(self) -> bool

Returns true if this is a signed integer dtype.

Source

pub const fn is_unsigned(self) -> bool

Returns true if this is an unsigned integer dtype.

Source

pub fn promote(dtype1: DType, dtype2: DType) -> DType

Promotes two dtypes according to JAX’s type promotion rules.

Type lattice: bool -> uint8 -> uint16 -> uint32 -> int8 -> int16 -> int32 -> float16 -> float32 -> float64

§Examples
assert_eq!(DType::promote(DType::Bool, DType::Int32), DType::Int32);
assert_eq!(DType::promote(DType::Uint32, DType::Int32), DType::Int32);
assert_eq!(DType::promote(DType::Int32, DType::Float16), DType::Float16);
assert_eq!(DType::promote(DType::Float16, DType::Float32), DType::Float32);
Source

pub fn cast_from_f32(self, value: f32) -> f32

Cast a float32 value to this dtype (returns as f32 for storage).

Source§

impl DType

Source

pub fn from_str(s: &str) -> Option<DType>

Parse a string into a DType.

Trait Implementations§

Source§

impl Clone for DType

Source§

fn clone(&self) -> DType

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DType

Source§

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

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

impl Display for DType

Source§

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

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

impl Hash for DType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DType

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for DType

Source§

impl Eq for DType

Source§

impl StructuralPartialEq for DType

Auto Trait Implementations§

§

impl Freeze for DType

§

impl RefUnwindSafe for DType

§

impl Send for DType

§

impl Sync for DType

§

impl Unpin for DType

§

impl UnwindSafe for DType

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
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
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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,