{"record":{"id":"d940b8db69a2dbdc","repo":"tracel-ai/burn","slug":"argmin-unsupported-dtype","errorCode":null,"errorMessage":"argmin: unsupported dtype {:?}","messagePattern":"argmin: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/reduce.rs","lineNumber":835,"sourceCode":"                f16::from_f32,\n            )\n            .1\n        }\n        DType::BF16 => {\n            extremum_dim_with_indices_half::<bf16, _>(\n                &tensor,\n                dim,\n                |a, b| !b.is_nan() && (a.is_nan() || a < b),\n                bf16::to_f32,\n                bf16::from_f32,\n            )\n            .1\n        }\n        DType::I8 => extremum_dim_with_indices::<i8, _>(&tensor, dim, |a, b| a < b).1,\n        DType::I16 => extremum_dim_with_indices::<i16, _>(&tensor, dim, |a, b| a < b).1,\n        DType::I32 => extremum_dim_with_indices::<i32, _>(&tensor, dim, |a, b| a < b).1,\n        DType::I64 => extremum_dim_with_indices::<i64, _>(&tensor, dim, |a, b| a < b).1,\n        _ => panic!(\"argmin: unsupported dtype {:?}\", tensor.dtype()),\n    }\n}\n\n// ============================================================================\n// Dimension reduction helpers\n// ============================================================================\n\n#[derive(Clone, Copy)]\nenum ReduceOp {\n    Sum,\n    Prod,\n}\n\n/// Optimized f32 dimension reduction with SIMD.\nfn reduce_dim_f32(tensor: &FlexTensor, dim: usize, op: ReduceOp) -> FlexTensor {\n    let ndims = tensor.layout().shape().num_dims();\n\n    assert!(","sourceCodeStart":817,"sourceCodeEnd":853,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/reduce.rs#L817-L853","documentation":"The burn-flex `argmin` reduction panics when the tensor dtype has no argmin implementation. Identical structure to `argmax` (reduce.rs:798-837): only F32/F64/F16/BF16 and I8-I64 are handled; unsigned integers and Bool reach the `_ => panic!` arm at line 835.","triggerScenarios":"Calling `ops::reduce::argmin(tensor, dim)` on a U8/U16/U32/U64 or Bool tensor. Dim-bounds problems fail earlier with different messages, so this panic only fires on unhandled dtypes.","commonSituations":"Argmin over u8 image data (nearest-color / template matching); argmin over a bool mask; porting code from a backend that supported unsigned argmin to burn-flex.","solutions":["Cast to a supported dtype before the call: `tensor.cast(DType::I64)` (watch for u64 values above i64::MAX) or `tensor.cast(DType::F32)`.","For Bool tensors cast to U8 or I64 first.","Add unsigned arms (`extremum_dim_with_indices::<u8, _>(...)` etc.) to the argmin match in crates/burn-flex/src/ops/reduce.rs if unsigned support is needed.","Check the dtype of the tensor at production time; fix the upstream cast if an unexpected dtype is flowing in."],"exampleFix":"// before\nlet idx = argmin(u32_tensor, 0); // panics: unsupported dtype U32\n// after\nlet idx = argmin(u32_tensor.cast(DType::I64), 0);","handlingStrategy":"validation","validationCode":"fn ensure_argmin_supported(dtype: DType) -> Result<(), String> {\n    match dtype {\n        DType::F32 | DType::F64 | DType::F16 | DType::BF16\n        | DType::I8 | DType::I16 | DType::I32 | DType::I64 => Ok(()),\n        other => Err(format!(\"argmin: unsupported dtype {other:?}; cast first\")),\n    }\n}","typeGuard":"fn is_argmin_supported(dtype: DType) -> bool {\n    matches!(dtype, DType::F32 | DType::F64 | DType::F16 | DType::BF16\n        | DType::I8 | DType::I16 | DType::I32 | DType::I64)\n}","tryCatchPattern":"let out = std::panic::catch_unwind(|| argmin(t.clone(), dim))\n    .ok()\n    .unwrap_or_else(|| argmin(t.cast(DType::I64), dim));","preventionTips":["Cast U8/U16/U32/U64 tensors to I64 (or F32) before argmin","Watch for u64 values exceeding i64::MAX when casting","Cast Bool masks to numeric types before index-reductions","Keep a shared dtype-allowlist helper used by both argmax and argmin call sites"],"tags":["panic","dtype","burn","argmin","reduce-ops"],"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"}