dtype

Module

Implements the DType class.

These are Mojo built-ins, so you don’t need to import them.

DType

Represents DType and provides methods for working with it.

Aliases:

  • type = dtype
  • invalid = invalid: Represents an invalid or unknown data type.
  • bool = bool: Represents a boolean data type.
  • int8 = si8: Represents a signed integer type whose bitwidth is 8.
  • uint8 = ui8: Represents an unsigned integer type whose bitwidth is 8.
  • int16 = si16: Represents a signed integer type whose bitwidth is 16.
  • uint16 = ui16: Represents an unsigned integer type whose bitwidth is 16.
  • int32 = si32: Represents a signed integer type whose bitwidth is 32.
  • uint32 = ui32: Represents an unsigned integer type whose bitwidth is 32.
  • int64 = si64: Represents a signed integer type whose bitwidth is 64.
  • uint64 = ui64: Represents an unsigned integer type whose bitwidth is 64.
  • bfloat16 = bf16: Represents a brain floating point value whose bitwidth is 16.
  • float16 = f16: Represents an IEEE754-2008 binary16 floating point value.
  • float32 = f32: Represents an IEEE754-2008 binary32 floating point value.
  • float64 = f64: Represents an IEEE754-2008 binary64 floating point value.
  • index = index: Represents an integral type whose bitwidth is the maximum integral value on the system.
  • address = address: Represents a pointer type whose bitwidth is the same as the bitwidth of the hardware’s pointer type (32-bit on 32-bit machines and 64-bit on 64-bit machines).

Fields:

  • value (dtype): The underlying storage for the DType value.

Functions:

__init__

__init__(value: dtype) -> Self

__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 non-equality.

Args:

  • rhs (Self): The DType to compare against.

Returns:

False if the DTypes are the same and True otherwise.

__str__

__str__(self: Self) -> StringLiteral

Gets the name of the DType.

Returns:

The name of the dtype.

get_value

get_value(self: Self) -> dtype

Gets the associated internal kgen.dtype value.

Returns:

The kgen.dtype value.

isa

isa[other: Self](self: Self) -> Bool

Checks if this DType matches the other one, specified as a parameter.

Parameters:

  • other (Self): The DType to compare against.

Returns:

True if the DTypes are the same and False otherwise.

is_bool

is_bool(self: Self) -> Bool

Checks if this DType is Bool.

Returns:

True if the DType is Bool and False otherwise.

is_uint8

is_uint8(self: Self) -> Bool

Checks if this DType is UInt8.

Returns:

True if the DType is UInt8 and False otherwise.

is_int8

is_int8(self: Self) -> Bool

Checks if this DType is Int8.

Returns:

True if the DType is Int8 and False otherwise.

is_uint16

is_uint16(self: Self) -> Bool

Checks if this DType is UInt16.

Returns:

True if the DType is UInt16 and False otherwise.

is_int16

is_int16(self: Self) -> Bool

Checks if this DType is Int16.

Returns:

True if the DType is Int16 and False otherwise.

is_uint32

is_uint32(self: Self) -> Bool

Checks if this DType is UInt32.

Returns:

True if the DType is UInt32 and False otherwise.

is_int32

is_int32(self: Self) -> Bool

Checks if this DType is Int32.

Returns:

True if the DType is Int32 and False otherwise.

is_uint64

is_uint64(self: Self) -> Bool

Checks if this DType is UInt64.

Returns:

True if the DType is UInt64 and False otherwise.

is_int64

is_int64(self: Self) -> Bool

Checks if this DType is Int64.

Returns:

True if the DType is Int64 and False otherwise.

is_bfloat16

is_bfloat16(self: Self) -> Bool

Checks if this DType is BFloat16.

Returns:

True if the DType is BFloat16 and False otherwise.

is_float16

is_float16(self: Self) -> Bool

Checks if this DType is Float16.

Returns:

True if the DType is Float16 and False otherwise.

is_float32

is_float32(self: Self) -> Bool

Checks if this DType is Float32.

Returns:

True if the DType is Float32 and False otherwise.

is_float64

is_float64(self: Self) -> Bool

Checks if this DType is Float64.

Returns:

True if the DType is Float64 and False otherwise.

is_index

is_index(self: Self) -> Bool

Checks if this DType is Index.

Returns:

True if the DType is Index and False otherwise.

is_address

is_address(self: Self) -> Bool

Checks if this DType is Address.

Returns:

True if the DType is Address and False otherwise.

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.

sizeof

sizeof(self: Self) -> Int

Returns the size in bytes of the current DType.

Returns:

Returns the size in bytes of the current DType and -1 if the size is unknown.

bitwidth

bitwidth(self: Self) -> Int

Returns the size in bits of the current DType.

Returns:

Returns the size in bits of the current DType and -1 if the size is unknown.

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_integral[func: fn[DType]() capturing -> None](self: Self, out_chain: OutputChainPtr)

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.

Args:

  • out_chain (OutputChainPtr): The output chain used to report errors.

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.

Parameters:

  • func (fn[DType]() capturing -> None): A parametrized on dtype function to dispatch.

dispatch_floating[func: fn[DType]() capturing -> None](self: Self, out_chain: OutputChainPtr)

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.

Args:

  • out_chain (OutputChainPtr): The output chain used to report errors.

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.

dispatch_arithmetic[func: fn[DType]() capturing -> None](self: Self, out_chain: OutputChainPtr)

Dispatches a function corresponding to the current DType.

Parameters:

  • func (fn[DType]() capturing -> None): A parametrized on dtype function to dispatch.

Args:

  • out_chain (OutputChainPtr): The output chain used to report errors.