tracel-ai/burn · error
compare_int_elem: unsupported dtype {:?}
Error message
compare_int_elem: unsupported dtype {:?} What it means
Dtype-dispatch exhaustiveness panic in the Flex backend: `compare_int_elem` handles all integer dtypes (and casts them against i64); a non-integer dtype (float or bool) reaching this integer-comparison path hits the fallback arm. It indicates an op-routing bug where an int comparison op was invoked on a tensor of the wrong kind.
Source
Thrown at crates/burn-flex/src/ops/comparison.rs:694
DType::I32 => compare_elem_typed(lhs, i64_rhs as i32, out_dtype, |a: i32, b: i32| {
i64_cmp(a as i64, b as i64)
}),
DType::I16 => compare_elem_typed(lhs, i64_rhs as i16, out_dtype, |a: i16, b: i16| {
i64_cmp(a as i64, b as i64)
}),
DType::I8 => compare_elem_typed(lhs, i64_rhs as i8, out_dtype, |a: i8, b: i8| {
i64_cmp(a as i64, b as i64)
}),
DType::U32 => compare_elem_typed(lhs, i64_rhs as u32, out_dtype, |a: u32, b: u32| {
i64_cmp(a as i64, b as i64)
}),
DType::U16 => compare_elem_typed(lhs, i64_rhs as u16, out_dtype, |a: u16, b: u16| {
i64_cmp(a as i64, b as i64)
}),
DType::U8 => compare_elem_typed(lhs, i64_rhs as u8, out_dtype, |a: u8, b: u8| {
i64_cmp(a as i64, b as i64)
}),
other => panic!("compare_int_elem: unsupported dtype {:?}", other),
}
}
pub fn int_greater(lhs: FlexTensor, rhs: FlexTensor, out_dtype: BoolDType) -> FlexTensor {
compare_int(lhs, rhs, out_dtype, |a, b| a > b, |a, b| a > b)
}
pub fn int_greater_elem(
lhs: FlexTensor,
i64_rhs: i64,
u64_rhs: u64,
out_dtype: BoolDType,
) -> FlexTensor {
compare_int_elem(lhs, i64_rhs, u64_rhs, out_dtype, |a, b| a > b, |a, b| a > b)
}
pub fn int_greater_equal(lhs: FlexTensor, rhs: FlexTensor, out_dtype: BoolDType) -> FlexTensor {
compare_int(lhs, rhs, out_dtype, |a, b| a >= b, |a, b| a >= b)View on GitHub (pinned to d16f7ba2ed)
Solutions
- Use the float elemwise comparison variants for float tensors
- Cast the tensor to an integer dtype before the elemwise int comparison
- Log/assert the dtype at the call site to catch dtype drift early
Example fix
// before let out = int_greater_elem(a_f32, 0.5, BoolDType::Native); // after let out = compare_elem_f32(a_f32, 0.5, BoolDType::Native);
Defensive patterns
Strategy: validation
Validate before calling
assert!(matches!(a.dtype(), DType::I64|DType::I32|DType::I16|DType::I8|DType::U64|DType::U32|DType::U16|DType::U8), "compare_int_elem needs an int tensor, got {:?}", a.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
- Use the float *_elem comparison ops for float tensors
- Cast before comparing if dtypes must change
- Add dtype assertions in helper wrappers around elemwise ops
When it happens
Trigger: Calling int_greater_elem/int_lower_elem/int_equal_elem etc. with a tensor whose dtype is a float or bool rather than an integer dtype.
Common situations: Mixing a scalar comparison intended for floats into int-tensor code; tensor dtype changed upstream (e.g. loaded as F32) while the comparison call was written for ints.
Related errors
- burn-flex does not support Bool(U32) storage (only Native an
- compare_int: unsupported dtype {:?}
- any_float: unsupported dtype {:?}
- all_float: unsupported dtype {:?}
- any_int: unsupported dtype {:?}
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/fc54098de461c9ac.
Report an issue: GitHub.