{"record":{"id":"fc54098de461c9ac","repo":"tracel-ai/burn","slug":"compare-int-elem-unsupported-dtype","errorCode":null,"errorMessage":"compare_int_elem: unsupported dtype {:?}","messagePattern":"compare_int_elem: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/comparison.rs","lineNumber":694,"sourceCode":"        DType::I32 => compare_elem_typed(lhs, i64_rhs as i32, out_dtype, |a: i32, b: i32| {\n            i64_cmp(a as i64, b as i64)\n        }),\n        DType::I16 => compare_elem_typed(lhs, i64_rhs as i16, out_dtype, |a: i16, b: i16| {\n            i64_cmp(a as i64, b as i64)\n        }),\n        DType::I8 => compare_elem_typed(lhs, i64_rhs as i8, out_dtype, |a: i8, b: i8| {\n            i64_cmp(a as i64, b as i64)\n        }),\n        DType::U32 => compare_elem_typed(lhs, i64_rhs as u32, out_dtype, |a: u32, b: u32| {\n            i64_cmp(a as i64, b as i64)\n        }),\n        DType::U16 => compare_elem_typed(lhs, i64_rhs as u16, out_dtype, |a: u16, b: u16| {\n            i64_cmp(a as i64, b as i64)\n        }),\n        DType::U8 => compare_elem_typed(lhs, i64_rhs as u8, out_dtype, |a: u8, b: u8| {\n            i64_cmp(a as i64, b as i64)\n        }),\n        other => panic!(\"compare_int_elem: unsupported dtype {:?}\", other),\n    }\n}\n\npub fn int_greater(lhs: FlexTensor, rhs: FlexTensor, out_dtype: BoolDType) -> FlexTensor {\n    compare_int(lhs, rhs, out_dtype, |a, b| a > b, |a, b| a > b)\n}\n\npub fn int_greater_elem(\n    lhs: FlexTensor,\n    i64_rhs: i64,\n    u64_rhs: u64,\n    out_dtype: BoolDType,\n) -> FlexTensor {\n    compare_int_elem(lhs, i64_rhs, u64_rhs, out_dtype, |a, b| a > b, |a, b| a > b)\n}\n\npub fn int_greater_equal(lhs: FlexTensor, rhs: FlexTensor, out_dtype: BoolDType) -> FlexTensor {\n    compare_int(lhs, rhs, out_dtype, |a, b| a >= b, |a, b| a >= b)","sourceCodeStart":676,"sourceCodeEnd":712,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/comparison.rs#L676-L712","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet out = int_greater_elem(a_f32, 0.5, BoolDType::Native);\n// after\nlet out = compare_elem_f32(a_f32, 0.5, BoolDType::Native);","handlingStrategy":"validation","validationCode":"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());","typeGuard":"fn is_int_dtype(d: &DType) -> bool {\n    matches!(d, DType::I64|DType::I32|DType::I16|DType::I8|DType::U64|DType::U32|DType::U16|DType::U8)\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["rust","burn","dtype","panic"],"backgroundTag":"unsupported-dtype","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}