{"record":{"id":"ddc1334becd83188","repo":"tracel-ai/burn","slug":"compare-unsupported-dtype","errorCode":null,"errorMessage":"compare: unsupported dtype {:?}","messagePattern":"compare: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/comparison.rs","lineNumber":49,"sourceCode":"    F64Cmp: Fn(f64, f64) -> bool + Copy,\n{\n    debug_assert_eq!(lhs.dtype(), rhs.dtype(), \"compare: dtype mismatch\");\n\n    // Broadcast to 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::F32 => compare_f32(lhs, &rhs, out_dtype, f32_cmp, simd_hint),\n        DType::F64 => compare_typed(lhs, &rhs, out_dtype, f64_cmp),\n        DType::F16 => compare_typed(lhs, &rhs, out_dtype, |a: f16, b: f16| {\n            f32_cmp(a.to_f32(), b.to_f32())\n        }),\n        DType::BF16 => compare_typed(lhs, &rhs, out_dtype, |a: bf16, b: bf16| {\n            f32_cmp(a.to_f32(), b.to_f32())\n        }),\n        _ => panic!(\"compare: unsupported dtype {:?}\", dtype),\n    }\n}\n\n/// Specialized comparison for f32 with SIMD fast path.\n#[cfg(feature = \"simd\")]\nfn compare_f32<Cmp>(\n    lhs: FlexTensor,\n    rhs: &FlexTensor,\n    out_dtype: BoolDType,\n    cmp: Cmp,\n    simd_hint: Option<CompareOp>,\n) -> FlexTensor\nwhere\n    Cmp: Fn(f32, f32) -> bool,\n{\n    // SIMD fast path: both tensors contiguous\n    if let (Some((l_start, l_end)), Some((r_start, r_end))) = (\n        lhs.layout().contiguous_offsets(),","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/comparison.rs#L31-L67","documentation":"compare in burn-flex performs elementwise tensor-vs-tensor comparisons (greater, greater_equal, lower, lower_equal, equal, not_equal), dispatching on the input dtype. F32 (SIMD fast path), F64, F16 and BF16 are supported; other dtypes panic. An out_dtype parameter selects the boolean output representation.","triggerScenarios":"Calling any of greater/greater_equal/lower/lower_equal/equal/not_equal on integer, unsigned or bool tensors — the comparison entry points shown here only wire up the float branches. E.g. comparing two i64 index tensors.","commonSituations":"Comparing token indices or integer labels; comparing bool masks for equality; expecting PyTorch-style comparisons that accept any dtype.","solutions":["Cast operands to a float dtype before comparing: a.cast(DType::F32).equal(b.cast(DType::F32)).","Check for an integer/bool comparison variant in the ops module and use that instead.","If comparing for exact equality on ints is intended, extend compare_typed with the needed element type instantiation."],"exampleFix":"// before\nlet eq = lower(a_i64, b_i64); // panics\n// after\nlet eq = lower(a_i64.cast(DType::F32), b_i64.cast(DType::F32));","handlingStrategy":"validation","validationCode":"if !matches!(lhs.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16) {\n    lhs = lhs.cast(DType::F32);\n    rhs = rhs.cast(DType::F32);\n}\nlet mask = equal(lhs, rhs, out_dtype);","typeGuard":"fn is_float_dtype(d: DType) -> bool {\n    matches!(d, DType::F32 | DType::F64 | DType::F16 | DType::BF16)\n}","tryCatchPattern":"let mask = std::panic::catch_unwind(|| equal(lhs.clone(), rhs.clone(), out_dtype))\n    .unwrap_or_else(|_| equal(lhs.cast(DType::F32), rhs.cast(DType::F32), out_dtype));","preventionTips":["Cast int/bool tensors to float before elementwise comparisons.","Look for dedicated int comparison ops before forcing a cast.","Keep comparison operands dtype-identical.","Cover each *_elem/* comparison in dtype-parametrized tests."],"tags":["panic","dtype","comparison","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"}