DataTypeΒΆ

class onnx_ir.DataType(value)ΒΆ

Enum for the data types of ONNX tensors, defined in onnx.TensorProto.

classmethod from_numpy(dtype)[source]ΒΆ

Returns the ONNX data type for the numpy dtype.

Raises:

TypeError – If the data type is not supported by ONNX.

Parameters:

dtype (dtype)

Return type:

DataType

classmethod from_short_name(short_name)[source]ΒΆ

Returns the ONNX data type for the short name.

Raises:

TypeError – If the short name is not available for the data type.

Parameters:

short_name (str)

Return type:

DataType

property itemsize: floatΒΆ

Returns the size of the data type in bytes.

property bitwidth: intΒΆ

Returns the bit width of the data type.

Added in version 0.1.2.

Raises:

TypeError – If the data type is not supported.

property exponent_bitwidth: intΒΆ

Returns the bit width of the exponent for floating-point types.

Added in version 0.1.8.

Raises:

TypeError – If the data type is not supported.

property mantissa_bitwidth: intΒΆ

Returns the bit width of the mantissa for floating-point types.

Added in version 0.1.8.

Raises:

TypeError – If the data type is not supported.

property eps: int | floating[Any]ΒΆ

Returns the difference between 1.0 and the next smallest representable float larger than 1.0 for the ONNX data type.

Returns 1 for integers.

Added in version 0.1.8.

Raises:

TypeError – If the data type is not a numeric data type.

property tiny: int | floating[Any]ΒΆ

Returns the smallest positive non-zero value for the ONNX data type.

Returns 1 for integers.

Added in version 0.1.8.

Raises:

TypeError – If the data type is not a numeric data type.

property min: int | floating[Any]ΒΆ

Returns the minimum representable value for the ONNX data type.

Added in version 0.1.8.

Raises:

TypeError – If the data type is not a numeric data type.

property max: int | floating[Any]ΒΆ

Returns the maximum representable value for the ONNX data type.

Added in version 0.1.8.

Raises:

TypeError – If the data type is not a numeric data type.

property precision: intΒΆ

Returns the precision for the ONNX dtype if supported.

For floats returns the approximate number of decimal digits to which this kind of float is precise. Returns 0 for integers.

Added in version 0.1.8.

Raises:

TypeError – If the data type is not a numeric data type.

property resolution: int | floating[Any]ΒΆ

Returns the resolution for the ONNX dtype if supported.

Returns the approximate decimal resolution of this type, i.e.,

10**-precision. Returns 1 for integers.

Added in version 0.1.8.

Raises:

TypeError – If the data type is not a numeric data type.

numpy()[source]ΒΆ

Returns the numpy dtype for the ONNX data type.

Raises:

TypeError – If the data type is not supported by numpy.

Return type:

dtype

short_name()[source]ΒΆ

Returns the short name of the data type.

The short name is a string that is used to represent the data type in a more compact form. For example, the short name for DataType.FLOAT is β€œf32”. To get the corresponding data type back, call from_short_name on a string.

Naming reference: https://github.com/pytorch/pytorch/blob/4bead7b85ea4160243c74109e0ce9bb80686d016/torch/utils/_dtype_abbrs.py

Raises:

TypeError – If the short name is not available for the data type.

Return type:

str

is_floating_point()[source]ΒΆ

Returns True if the data type is a floating point type.

Return type:

bool

is_integer()[source]ΒΆ

Returns True if the data type is an integer.

Added in version 0.1.4.

Return type:

bool

is_signed()[source]ΒΆ

Returns True if the data type is a signed type.

Added in version 0.1.4.

Return type:

bool

is_string()[source]ΒΆ

Returns True if the data type is a string type.

Added in version 0.1.8.

Return type:

bool

UNDEFINED = 0ΒΆ
FLOAT = 1ΒΆ
UINT8 = 2ΒΆ
INT8 = 3ΒΆ
UINT16 = 4ΒΆ
INT16 = 5ΒΆ
INT32 = 6ΒΆ
INT64 = 7ΒΆ
STRING = 8ΒΆ
BOOL = 9ΒΆ
FLOAT16 = 10ΒΆ
DOUBLE = 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ΒΆ