pub enum DType {
F32,
F16,
BF16,
F64,
I8,
I16,
I32,
I64,
U8,
U32,
Bool,
C64,
}Expand description
Scalar element type. Matches hardware-supported types.
Variants§
F32
F16
BF16
F64
I8
I16
I32
I64
U8
U32
Bool
C64
Complex with f32 real and f32 imaginary components, stored
interleaved as [re, im, re, im, ...]. 8 bytes per complex
element. Element-wise ops (Add/Sub/Mul/Conj) follow the
standard complex algebra. Reverse-mode AD on this dtype is
not yet wired — Wirtinger conventions (∂/∂z vs ∂/∂z̄)
belong to a separate pass that knows to emit conjugate-aware
VJPs. The forward path is sufficient for AC analysis and
FFT-based workflows that don’t need to differentiate through
complex math (and in fact, FFT today already encodes complex
as 2N-real-block; this dtype is the natural successor).
Implementations§
Source§impl DType
impl DType
Sourcepub const fn size_bytes(self) -> usize
pub const fn size_bytes(self) -> usize
Size in bytes of one element.
pub const fn is_float(self) -> bool
Sourcepub const fn is_complex(self) -> bool
pub const fn is_complex(self) -> bool
True for complex-valued dtypes. Complex elementwise ops follow standard complex algebra, distinct from the float real/imag components (e.g. complex multiply ≠ paired-real multiply).
pub const fn is_int(self) -> bool
Sourcepub const fn promotion_rank(self) -> u8
pub const fn promotion_rank(self) -> u8
Promotion rank — higher means “wider, more expressive”. The
promoted dtype of a binary op is max(rank(lhs), rank(rhs)).
Borrowed from MAX’s dtype_promotion.py pattern (#55 in
PLAN.md): one module owns the table; ops query it instead of
re-implementing ad-hoc rules.
Ranks (low → high): 0 = Bool, 1 = U8/I8, 2 = I16/BF16, 3 = F16, 4 = U32/I32, 5 = I64, 6 = F32, 7 = F64. Floats outrank ints of the same width (matches PyTorch / NumPy). BF16 promotes to F32 against F16 since BF16 has wider range but F16 has more mantissa.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DType
impl<'de> Deserialize<'de> for DType
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<DType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<DType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for DType
impl Serialize for DType
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for DType
impl Eq for DType
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 UnsafeUnpin for DType
impl UnwindSafe for DType
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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