{"record":{"id":"84210b873b4714a6","repo":"tracel-ai/burn","slug":"prod-unsupported-dtype","errorCode":null,"errorMessage":"prod: unsupported dtype {:?}","messagePattern":"prod: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/reduce.rs","lineNumber":363,"sourceCode":"    }\n}\n\n/// Product of all elements in a tensor, returning a scalar tensor.\npub fn prod(tensor: FlexTensor) -> FlexTensor {\n    match tensor.dtype() {\n        DType::F32 => prod_impl::<f32>(&tensor),\n        DType::F64 => prod_impl::<f64>(&tensor),\n        DType::F16 => reduce_scalar_half(&tensor, |a, b| a * b, 1.0, f16::to_f32, f16::from_f32),\n        DType::BF16 => reduce_scalar_half(&tensor, |a, b| a * b, 1.0, bf16::to_f32, bf16::from_f32),\n        DType::I8 => prod_impl_widening::<i8>(&tensor),\n        DType::I16 => prod_impl_widening::<i16>(&tensor),\n        DType::I32 => prod_impl_widening::<i32>(&tensor),\n        DType::I64 => prod_impl::<i64>(&tensor),\n        DType::U8 => prod_impl_widening::<u8>(&tensor),\n        DType::U16 => prod_impl_widening::<u16>(&tensor),\n        DType::U32 => prod_impl_widening::<u32>(&tensor),\n        DType::U64 => prod_impl::<u64>(&tensor),\n        _ => panic!(\"prod: unsupported dtype {:?}\", tensor.dtype()),\n    }\n}\n\nfn prod_impl<E: Element + bytemuck::Pod + Default + core::iter::Product>(\n    tensor: &FlexTensor,\n) -> FlexTensor {\n    let result: E = match tensor.layout().contiguous_offsets() {\n        Some((start, end)) => {\n            let data: &[E] = tensor.storage();\n            data[start..end].iter().copied().product()\n        }\n        None => {\n            let data: &[E] = tensor.storage();\n            StridedIter::new(tensor.layout())\n                .map(|idx| data[idx])\n                .product()\n        }\n    };","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/reduce.rs#L345-L381","documentation":"burn-flex's `prod` multiplies all elements; it supports float dtypes and integer dtypes I8–I64 / U8–U64 (with widening accumulation to reduce overflow risk). Any other dtype (Bool, quantized) triggers the panic.","triggerScenarios":"Calling `Tensor::prod()` on a Bool or quantized tensor — e.g. computing a conjunction over a boolean mask with product instead of logical all.","commonSituations":"Using prod as a logical AND over bool masks without casting; product over quantized values; dtype inferred from upstream ops in generic code.","solutions":["Cast before product: `mask.cast(DType::I32).prod()`, or use `all`-style logic for booleans.","For quantized tensors, dequantize first.","Beware integer overflow — prefer widening dtypes (I32/I64) before prod."],"exampleFix":"// before\nlet all_match = mask.prod(); // Bool\n// after\nlet all_match = mask.cast(DType::I32).prod();","handlingStrategy":"validation","validationCode":"assert!(!matches!(t.dtype(), DType::Bool | DType::QFloat(_)), \"prod unsupported for {:?}; cast or dequantize first\", t.dtype());","typeGuard":"fn is_prod_capable(d: DType) -> bool {\n    matches!(d, DType::F32 | DType::F64 | DType::F16 | DType::BF16\n        | DType::I8 | DType::I16 | DType::I32 | DType::I64\n        | DType::U8 | DType::U16 | DType::U32 | DType::U64)\n}","tryCatchPattern":null,"preventionTips":["Cast bool masks to I32 before prod-based AND logic.","Prefer wider dtypes (I32/I64) to limit overflow in products.","Dequantize before products on quantized tensors."],"tags":["rust","burn","reduce","prod","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"}