#[repr(u8)]pub enum DataType {
Show 27 variants
Undefined = 0,
Float32 = 1,
Uint8 = 2,
Int8 = 3,
Uint16 = 4,
Int16 = 5,
Int32 = 6,
Int64 = 7,
String = 8,
Bool = 9,
Float16 = 10,
Float64 = 11,
Uint32 = 12,
Uint64 = 13,
Complex64 = 14,
Complex128 = 15,
BFloat16 = 16,
Float8E4M3FN = 17,
Float8E4M3FNUZ = 18,
Float8E5M2 = 19,
Float8E5M2FNUZ = 20,
Uint4 = 21,
Int4 = 22,
Float4E2M1 = 23,
Float8E8M0 = 24,
Uint2 = 25,
Int2 = 26,
}Expand description
Supported tensor element types.
The discriminant values match ONNX TensorProto.DataType so that the
loader can cast the protobuf integer directly (see DataType::from_onnx).
Variants§
Undefined = 0
Float32 = 1
Uint8 = 2
Int8 = 3
Uint16 = 4
Int16 = 5
Int32 = 6
Int64 = 7
String = 8
Bool = 9
Float16 = 10
Float64 = 11
Uint32 = 12
Uint64 = 13
Complex64 = 14
Complex128 = 15
BFloat16 = 16
Float8E4M3FN = 17
Float8E4M3FNUZ = 18
Float8E5M2 = 19
Float8E5M2FNUZ = 20
Uint4 = 21
Int4 = 22
Float4E2M1 = 23
Float8E8M0 = 24
Uint2 = 25
Int2 = 26
Implementations§
Source§impl DataType
impl DataType
Sourcepub fn byte_size(self) -> usize
pub fn byte_size(self) -> usize
Byte size per element. Sub-byte (packed) and variable-width types
return 0; use DataType::bit_size for those.
Sourcepub fn bit_size(self) -> usize
pub fn bit_size(self) -> usize
Bit size per element. Sub-byte types return their true width (e.g. 4).
Sourcepub fn is_complex(self) -> bool
pub fn is_complex(self) -> bool
Whether elements contain real and imaginary floating-point components.
Sourcepub fn is_sub_byte(self) -> bool
pub fn is_sub_byte(self) -> bool
Whether elements are packed multiple-per-byte.
Sourcepub fn storage_bytes(self, count: usize) -> usize
pub fn storage_bytes(self, count: usize) -> usize
Number of bytes needed to store count elements, accounting for
sub-byte packing.
Panics on usize overflow of the count * byte_size product. Callers
that size heap allocations from an untrusted shape MUST use
DataType::checked_storage_bytes instead so a crafted static shape
cannot wrap the multiply and under-allocate.
Sourcepub fn checked_storage_bytes(self, count: usize) -> Option<usize>
pub fn checked_storage_bytes(self, count: usize) -> Option<usize>
Number of bytes needed to store count elements, returning None when
the count * byte_size product overflows usize.
This is the overflow-safe counterpart of DataType::storage_bytes:
even though an element count may fit in usize, the element-count →
bytes multiply can still wrap for a fixed-width dtype (e.g. 2^61
elements of an 8-byte type). Allocation sites route through this so a
wrapped product becomes a clean error instead of a 1-byte allocation
followed by an out-of-bounds access.