{"record":{"id":"0d15f78aa0e6741d","repo":"tracel-ai/burn","slug":"int-binary-op-unsupported-dtype","errorCode":null,"errorMessage":"int_binary_op: unsupported dtype {:?}","messagePattern":"int_binary_op: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/binary.rs","lineNumber":379,"sourceCode":"    debug_assert_eq!(lhs.dtype(), rhs.dtype(), \"int_binary_op: dtype mismatch\");\n\n    // Broadcast tensors to the same shape if needed\n    let (lhs, rhs) = crate::ops::expand::broadcast_binary(lhs, rhs);\n\n    let dtype = lhs.dtype();\n\n    match dtype {\n        DType::I64 => binary_op_typed(lhs, rhs, op),\n        DType::I32 => binary_op_typed(lhs, rhs, |a: i32, b: i32| op(a as i64, b as i64) as i32),\n        DType::I16 => binary_op_typed(lhs, rhs, |a: i16, b: i16| op(a as i64, b as i64) as i16),\n        DType::I8 => binary_op_typed(lhs, rhs, |a: i8, b: i8| op(a as i64, b as i64) as i8),\n        // u64 values > i64::MAX wrap to negative i64. This is correct for\n        // add/sub/mul/bitwise (two's complement). Div/rem are handled at the call site.\n        DType::U64 => binary_op_typed(lhs, rhs, |a: u64, b: u64| op(a as i64, b as i64) as u64),\n        DType::U32 => binary_op_typed(lhs, rhs, |a: u32, b: u32| op(a as i64, b as i64) as u32),\n        DType::U16 => binary_op_typed(lhs, rhs, |a: u16, b: u16| op(a as i64, b as i64) as u16),\n        DType::U8 => binary_op_typed(lhs, rhs, |a: u8, b: u8| op(a as i64, b as i64) as u8),\n        _ => panic!(\"int_binary_op: unsupported dtype {:?}\", dtype),\n    }\n}\n\n/// Apply a scalar operation to each element of an integer tensor.\n/// Note: scalar is truncated to target dtype (matches PyTorch).\npub fn int_scalar_op<Op>(tensor: FlexTensor, scalar: i64, op: Op) -> FlexTensor\nwhere\n    Op: Fn(i64, i64) -> i64 + Copy,\n{\n    let dtype = tensor.dtype();\n\n    match dtype {\n        DType::I64 => scalar_op_typed(tensor, scalar, op),\n        DType::I32 => scalar_op_typed(tensor, scalar as i32, |a: i32, b: i32| {\n            op(a as i64, b as i64) as i32\n        }),\n        DType::I16 => scalar_op_typed(tensor, scalar as i16, |a: i16, b: i16| {\n            op(a as i64, b as i64) as i16","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/binary.rs#L361-L397","documentation":"int_binary_op dispatches integer elementwise ops (int_add, int_sub, int_mul, int_div, int_remainder, bitwise_and) on the tensor dtype. Signed ints and U64/U32/U16/U8 are handled (unsigned values are computed through i64 two's-complement, with div/rem caveats at the call site); signed I64/I32 and float/bool dtypes hit the panic arm. Float tensors must go through binary_op instead.","triggerScenarios":"Calling int_add/int_sub/int_mul/int_div/int_remainder/bitwise_and on a float tensor (F32/F64/F16/BF16), a Bool tensor, or a signed dtype branch not covered by the match; dividing or taking remainder of u64 values where the call site must special-case.","commonSituations":"Mixing float and int arithmetic expecting promotion; bitwise ops on bool tensors; using int_* entry points on float counters or indices converted from float.","solutions":["Use binary_op / float ops for float tensors: cast to float or call the float variant of the op.","Cast Bool tensors to an int dtype (e.g. tensor.cast(DType::U8) or bool_into_int) before int ops.","Check the dtype at the call site and route signed dtypes through the supported arms or extend the match."],"exampleFix":"// before\nlet z = int_add(a_f32, b_f32); // panics: floats\n// after\nlet z = binary_add(a_f32, b_f32); // float path","handlingStrategy":"validation","validationCode":"if !matches!(lhs.dtype(), DType::U64 | DType::U32 | DType::U16 | DType::U8 | DType::I64 | DType::I32) {\n    panic!(\"int_binary_op needs integer tensors, got {:?}\", lhs.dtype());\n}","typeGuard":"fn is_supported_int(d: DType) -> bool {\n    matches!(d, DType::U64 | DType::U32 | DType::U16 | DType::U8 | DType::I64 | DType::I32)\n}","tryCatchPattern":"let z = std::panic::catch_unwind(|| int_add(lhs.clone(), rhs.clone()))\n    .unwrap_or_else(|_| binary_add(lhs.cast(DType::F32), rhs.cast(DType::F32)).cast(lhs.dtype()));","preventionTips":["Route float tensors to binary_op, ints to int_binary_op.","Cast Bool to U8 before bitwise/int ops.","Remember div/rem on u64 needs call-site handling per the code comment.","Assert operand dtypes match before any binary op."],"tags":["panic","dtype","int","binary-op","unsupported-dtype"],"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"}