Skip to main content

DataType

Enum DataType 

Source
#[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

Source

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.

Source

pub fn bit_size(self) -> usize

Bit size per element. Sub-byte types return their true width (e.g. 4).

Source

pub fn is_float(self) -> bool

Whether this is a floating-point type (any precision).

Source

pub fn is_int(self) -> bool

Whether this is a signed or unsigned integer type (excludes Bool).

Source

pub fn is_complex(self) -> bool

Whether elements contain real and imaginary floating-point components.

Source

pub fn is_sub_byte(self) -> bool

Whether elements are packed multiple-per-byte.

Source

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.

Source

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.

Source

pub fn from_onnx(raw: i32) -> Option<Self>

Convert from the raw ONNX TensorProto.DataType integer.

Returns None for UNDEFINED (0) and any out-of-range or future value the runtime does not model. The discriminants below mirror the vendored onnx.proto3 TensorProto.DataType enum verbatim.

Source

pub fn to_onnx(self) -> i32

The raw ONNX TensorProto.DataType integer for this type.

Trait Implementations§

Source§

impl Clone for DataType

Source§

fn clone(&self) -> DataType

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 DataType

Source§

impl Debug for DataType

Source§

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

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

impl Eq for DataType

Source§

impl Hash for DataType

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 DataType

Source§

fn eq(&self, other: &DataType) -> 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 DataType

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
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> 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, 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.