tracel-ai/burn · error

int_mask_where: unsupported dtype {:?}

Error message

int_mask_where: unsupported dtype {:?}

What it means

int_mask_where applies a boolean mask (mask_where) on integer tensors and dispatches on the tensor's dtype. All integer dtypes (I64..U8) are handled; any other dtype reaching this function panics, because masking is only implemented for the listed element types.

Source

Thrown at crates/burn-flex/src/ops/int.rs:74

        tensor: IntTensor<Flex>,
        mask: BoolTensor<Flex>,
        value: IntTensor<Flex>,
    ) -> IntTensor<Flex> {
        debug_assert_eq!(
            tensor.dtype(),
            value.dtype(),
            "int_mask_where: dtype mismatch"
        );
        match tensor.dtype() {
            DType::I64 => crate::ops::mask::mask_where::<i64>(tensor, mask, value),
            DType::I32 => crate::ops::mask::mask_where::<i32>(tensor, mask, value),
            DType::I16 => crate::ops::mask::mask_where::<i16>(tensor, mask, value),
            DType::I8 => crate::ops::mask::mask_where::<i8>(tensor, mask, value),
            DType::U64 => crate::ops::mask::mask_where::<u64>(tensor, mask, value),
            DType::U32 => crate::ops::mask::mask_where::<u32>(tensor, mask, value),
            DType::U16 => crate::ops::mask::mask_where::<u16>(tensor, mask, value),
            DType::U8 => crate::ops::mask::mask_where::<u8>(tensor, mask, value),
            dt => panic!("int_mask_where: unsupported dtype {:?}", dt),
        }
    }

    fn int_mask_fill(
        tensor: IntTensor<Flex>,
        mask: BoolTensor<Flex>,
        value: Scalar,
    ) -> IntTensor<Flex> {
        match tensor.dtype() {
            DType::I64 => crate::ops::mask::mask_fill(tensor, mask, value.to_i64().unwrap()),
            DType::I32 => crate::ops::mask::mask_fill(tensor, mask, value.to_i64().unwrap() as i32),
            DType::I16 => crate::ops::mask::mask_fill(tensor, mask, value.to_i64().unwrap() as i16),
            DType::I8 => crate::ops::mask::mask_fill(tensor, mask, value.to_i64().unwrap() as i8),
            DType::U64 => crate::ops::mask::mask_fill(tensor, mask, value.to_u64().unwrap()),
            DType::U32 => crate::ops::mask::mask_fill(tensor, mask, value.to_u64().unwrap() as u32),
            DType::U16 => crate::ops::mask::mask_fill(tensor, mask, value.to_u64().unwrap() as u16),
            DType::U8 => crate::ops::mask::mask_fill(tensor, mask, value.to_u64().unwrap() as u8),
            dt => panic!("int_mask_fill: unsupported dtype {:?}", dt),

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use the float backend's mask_where for float tensors instead of int_mask_where
  2. Cast the tensor to an integer dtype if integer semantics are intended
  3. Check generic call sites — the dtype must be one of I64, I32, I16, I8, U64, U32, U16, U8
  4. Verify tensor provenance; a dtype swap earlier in the pipeline may route it here

Example fix

// before
let out = backend.int_mask_where(float_tensor, mask, value); // panic: unsupported dtype F32
// after
let out = backend.float_mask_where(float_tensor, mask, value); // float op for float data
Defensive patterns

Strategy: validation

Validate before calling

// before calling int_mask_where
assert!(tensor.dtype().is_int(), "int_mask_where requires an integer tensor, got {:?}", tensor.dtype());

Type guard

fn is_int_dtype(d: DType) -> bool {
    matches!(d, DType::I64 | DType::I32 | DType::I16 | DType::I8 | DType::U64 | DType::U32 | DType::U16 | DType::U8)
}

Prevention

When it happens

Trigger: Calling int_mask_where (the IntOps mask_where entry of the Flex backend) with a tensor whose dtype is not an integer — float or bool tensors routed here by mistake.

Common situations: Passing a float tensor to the int-specific ops API, generic code where a type parameter resolved to a non-int dtype at runtime, or backend dispatch bugs after refactors.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/8581b77f124558e0. Report an issue: GitHub.