Mojo struct
DType
Represents DType and provides methods for working with it.
Aliases
type = dtype
:invalid
: Represents an invalid or unknown data type.bool
: Represents a boolean data type.int8
: Represents a signed integer type whose bitwidth is 8.uint8
: Represents an unsigned integer type whose bitwidth is 8.int16
: Represents a signed integer type whose bitwidth is 16.uint16
: Represents an unsigned integer type whose bitwidth is 16.int32
: Represents a signed integer type whose bitwidth is 32.uint32
: Represents an unsigned integer type whose bitwidth is 32.int64
: Represents a signed integer type whose bitwidth is 64.uint64
: Represents an unsigned integer type whose bitwidth is 64.bfloat16
: Represents a brain floating point value whose bitwidth is 16.float16
: Represents an IEEE754-2008binary16
floating point value.float32
: Represents an IEEE754-2008binary32
floating point value.tensor_float32
: Represents a special floating point format supported by NVIDIA Tensor Cores, with the same range as float32 and reduced precision (>=10 bits). Note that this type is only available on NVIDIA GPUs.float64
: Represents an IEEE754-2008binary64
floating point value.index
: Represents an integral type whose bitwidth is the maximum integral value on the system.
Fields
- value (
dtype
): The underlying storage for the DType value.
Implemented traits
AnyType
,
CollectionElement
,
CollectionElementNew
,
Copyable
,
EqualityComparable
,
ExplicitlyCopyable
,
Formattable
,
Hashable
,
KeyElement
,
Movable
,
Representable
,
Stringable
Methods
__init__
__init__(inout self: Self, *, other: Self)
Copy this DType.
Args:
- other (
Self
): The DType to copy.
__eq__
__eq__(self: Self, rhs: Self) -> Bool
Compares one DType to another for equality.
Args:
- rhs (
Self
): The DType to compare against.
Returns:
True if the DTypes are the same and False otherwise.
__ne__
__ne__(self: Self, rhs: Self) -> Bool
Compares one DType to another for inequality.
Args:
- rhs (
Self
): The DType to compare against.
Returns:
False if the DTypes are the same and True otherwise.
__is__
__is__(self: Self, rhs: Self) -> Bool
Compares one DType to another for equality.
Args:
- rhs (
Self
): The DType to compare against.
Returns:
True if the DTypes are the same and False otherwise.
__isnot__
__isnot__(self: Self, rhs: Self) -> Bool
Compares one DType to another for inequality.
Args:
- rhs (
Self
): The DType to compare against.
Returns:
True if the DTypes are the same and False otherwise.
__str__
__str__(self: Self) -> String
Gets the name of the DType.
Returns:
The name of the dtype.
format_to
format_to(self: Self, inout writer: Formatter)
Formats this dtype to the provided formatter.
Args:
- writer (
Formatter
): The formatter to write to.
__repr__
__repr__(self: Self) -> String
Gets the representation of the DType e.g. "DType.float32"
.
Returns:
The representation of the dtype.
get_value
get_value(self: Self) -> dtype
Gets the associated internal kgen.dtype value.
Returns:
The kgen.dtype value.
__hash__
__hash__(self: Self) -> UInt
Return a 64-bit hash for this DType
value.
Returns:
A 64-bit integer hash of this DType
value.
is_unsigned
is_unsigned(self: Self) -> Bool
Returns True if the type parameter is unsigned and False otherwise.
Returns:
Returns True if the input type parameter is unsigned.
is_signed
is_signed(self: Self) -> Bool
Returns True if the type parameter is signed and False otherwise.
Returns:
Returns True if the input type parameter is signed.
is_integral
is_integral(self: Self) -> Bool
Returns True if the type parameter is an integer and False otherwise.
Returns:
Returns True if the input type parameter is an integer.
is_floating_point
is_floating_point(self: Self) -> Bool
Returns True if the type parameter is a floating-point and False otherwise.
Returns:
Returns True if the input type parameter is a floating-point.
is_half_float
is_half_float(self: Self) -> Bool
Returns True if the type is a half-precision floating point type, e.g. either fp16 or bf16.
Returns:
True if the type is a half-precision float, false otherwise..
is_numeric
is_numeric(self: Self) -> Bool
Returns True if the type parameter is numeric (i.e. you can perform arithmetic operations on).
Returns:
Returns True if the input type parameter is either integral or floating-point.
sizeof
sizeof(self: Self) -> Int
Returns the size in bytes of the current DType.
Returns:
Returns the size in bytes of the current DType.
bitwidth
bitwidth(self: Self) -> Int
Returns the size in bits of the current DType.
Returns:
Returns the size in bits of the current DType.
dispatch_integral
dispatch_integral[func: fn[DType]() capturing -> None](self: Self)
Dispatches an integral function corresponding to the current DType.
Constraints:
DType must be integral.
Parameters:
- func (
fn[DType]() capturing -> None
): A parametrized on dtype function to dispatch.
dispatch_floating
dispatch_floating[func: fn[DType]() capturing -> None](self: Self)
Dispatches a floating-point function corresponding to the current DType.
Constraints:
DType must be floating-point or integral.
Parameters:
- func (
fn[DType]() capturing -> None
): A parametrized on dtype function to dispatch.
dispatch_arithmetic
dispatch_arithmetic[func: fn[DType]() capturing -> None](self: Self)
Dispatches a function corresponding to the current DType.
Parameters:
- func (
fn[DType]() capturing -> None
): A parametrized on dtype function to dispatch.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
😔 What went wrong?