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.