IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

cast_uint_to_fp4e2m1

def cast_uint_to_fp4e2m1[in_dtype: DType, in_width: SIMDLength, //, *, out_dtype: DType, out_width: Int](x: SIMD[in_dtype, in_width]) -> SIMD[out_dtype, out_width]

Unpacks FP4 E2M1 nibbles packed inside unsigned integers to floating-point values.

Each input integer (uint8, uint16, or uint32) holds multiple packed 4-bit E2M1 values. The function extracts each nibble, looks up its float32 value in E2M1_TO_FLOAT32, casts to out_dtype, and assembles the result vector.

Parameters:

  • ​in_dtype (DType): Unsigned integer type holding packed FP4 nibbles (uint8, uint16, or uint32).
  • ​in_width (SIMDLength): Number of input integer elements.
  • ​out_dtype (DType): Output floating-point element type.
  • ​out_width (Int): Total output elements; must equal in_width * (bit_width(in_dtype) // 4).

Args:

Returns:

SIMD[out_dtype, out_width]: Decoded floating-point vector of length out_width.