tracel-ai/burn · error
compare_int: unsupported dtype {:?}
Error message
compare_int: unsupported dtype {:?} What it means
compare_int dispatches integer comparison over a fixed set of int dtypes (I64..U8, compared via i64 widening). Any other dtype reaching it — i.e. a float or bool tensor passed where an integer comparison is expected — hits the catch-all panic.
Source
Thrown at crates/burn-flex/src/ops/comparison.rs:657
DType::I32 => compare_typed(lhs, &rhs, out_dtype, |a: i32, b: i32| {
i64_cmp(a as i64, b as i64)
}),
DType::I16 => compare_typed(lhs, &rhs, out_dtype, |a: i16, b: i16| {
i64_cmp(a as i64, b as i64)
}),
DType::I8 => compare_typed(lhs, &rhs, out_dtype, |a: i8, b: i8| {
i64_cmp(a as i64, b as i64)
}),
DType::U32 => compare_typed(lhs, &rhs, out_dtype, |a: u32, b: u32| {
i64_cmp(a as i64, b as i64)
}),
DType::U16 => compare_typed(lhs, &rhs, out_dtype, |a: u16, b: u16| {
i64_cmp(a as i64, b as i64)
}),
DType::U8 => compare_typed(lhs, &rhs, out_dtype, |a: u8, b: u8| {
i64_cmp(a as i64, b as i64)
}),
other => panic!("compare_int: unsupported dtype {:?}", other),
}
}
fn compare_int_elem<I64Cmp, U64Cmp>(
lhs: FlexTensor,
i64_rhs: i64,
u64_rhs: u64,
out_dtype: BoolDType,
i64_cmp: I64Cmp,
u64_cmp: U64Cmp,
) -> FlexTensor
where
I64Cmp: Fn(i64, i64) -> bool,
U64Cmp: Fn(u64, u64) -> bool,
{
match lhs.dtype() {
DType::I64 => compare_elem_typed(lhs, i64_rhs, out_dtype, i64_cmp),
DType::U64 => compare_elem_typed(lhs, u64_rhs, out_dtype, u64_cmp),View on GitHub (pinned to d16f7ba2ed)
Solutions
- Check tensor.dtype() before calling; use the float comparison ops (compare_f32/compare_typed) for float tensors
- Convert the tensor to an integer dtype first if int semantics are intended
- Verify upstream ops are producing the dtype you expect
Example fix
// before let out = int_greater(a_f32, b_f32, BoolDType::Native); // after let out = compare_f32(a_f32, b_f32, 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 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
- Branch on dtype family: compare_f32/compare_typed for floats, compare_int for ints
- Assert dtypes at API boundaries where tensors enter your code
- Track dtype through your pipeline to catch silent conversions
When it happens
Trigger: Calling int_greater/int_lower/int_equal (or their _equal variants) with a tensor whose dtype is not one of the supported integer dtypes (e.g. F32, F64, Bool).
Common situations: Passing a float tensor to an int comparison by mistake; a dtype-inference bug upstream that left the tensor as F16/BF16; generic code that assumes all numeric dtypes are routed through compare_int.
Related errors
- burn-flex does not support Bool(U32) storage (only Native an
- compare_int_elem: 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/17dbaec1e5be9e90.
Report an issue: GitHub.