{"record":{"id":"0ee525381fade82c","repo":"tracel-ai/burn","slug":"float-into-int-unsupported-source-dtype","errorCode":null,"errorMessage":"float_into_int: unsupported source dtype {:?}","messagePattern":"float_into_int: unsupported source dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/float.rs","lineNumber":103,"sourceCode":"                        })\n                        .collect(),\n                    DType::F16 => tensor\n                        .storage::<f16>()\n                        .iter()\n                        .map(|v| {\n                            let $x = f32::from(*v) as f64;\n                            $conv\n                        })\n                        .collect(),\n                    DType::BF16 => tensor\n                        .storage::<bf16>()\n                        .iter()\n                        .map(|v| {\n                            let $x = f32::from(*v) as f64;\n                            $conv\n                        })\n                        .collect(),\n                    _ => panic!(\"float_into_int: unsupported source dtype {:?}\", src),\n                }\n            };\n        }\n\n        macro_rules! convert {\n            ($int_ty:ty) => {{\n                let data: Vec<$int_ty> = read_floats!(|x| x as $int_ty);\n                FlexTensor::new(Bytes::from_elems(data), Layout::contiguous(shape), out_dt)\n            }};\n        }\n\n        match out_dtype {\n            IntDType::I64 => convert!(i64),\n            IntDType::I32 => convert!(i32),\n            IntDType::I16 => convert!(i16),\n            IntDType::I8 => convert!(i8),\n            IntDType::U64 => convert!(u64),\n            IntDType::U32 => convert!(u32),","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/float.rs#L85-L121","documentation":"float_into_int converts a float tensor's data to an integer dtype. The read_floats! macro only handles F32, F64, F16, and BF16 source dtypes; passing a tensor whose dtype is anything else (e.g. a bool or int tensor routed here by mistake) hits the catch-all panic. It is a defensive guard against backend misuse, not a user-facing conversion failure.","triggerScenarios":"Calling float_into_int (via dtype cast/conversion APIs) with a source tensor whose dtype is not a floating-point type, e.g. Bool or an Int dtype. In normal use this only happens if another op mis-dispatches a non-float tensor into the float cast path.","commonSituations":"Backend bug or an op that returns an int/bool tensor where a float tensor was expected; casting a boolean mask tensor through the float cast path; version drift where a new DType variant was added without updating this match.","solutions":["Check the tensor's dtype before casting; only float tensors (F32/F64/F16/BF16) can go through float_into_int","If the tensor is bool/int, use the appropriate int/bool conversion op instead of the float cast","If the source op unexpectedly returned a non-float dtype, fix the upstream op or add an explicit .float() cast first","If a new DType variant was added to the backend, add a matching arm in the read_floats! macro"],"exampleFix":"// before: mask is Bool -> panic in float_into_int\nlet ints = mask.cast(IntDType::I32);\n// after: cast bool to float first\nlet ints = mask.cast(FloatDType::F32).cast(IntDType::I32);","handlingStrategy":"type-guard","validationCode":"use burn_tensor::DType;\nfn ensure_float(dt: DType) -> Result<(), String> {\n    match dt {\n        DType::F32 | DType::F64 | DType::F16 | DType::BF16 => Ok(()),\n        other => Err(format!(\"float_into_int requires a float dtype, got {:?}\", other)),\n    }\n}","typeGuard":"fn is_float_dtype(dt: DType) -> bool {\n    matches!(dt, DType::F32 | DType::F64 | DType::F16 | DType::BF16)\n}","tryCatchPattern":null,"preventionTips":["Check tensor.dtype() before any cast/conversion op","Route int/bool tensors to their own conversion ops, never the float path","Keep dtype tracking explicit in pipelines that mix masks, indices, and activations","After adding a new DType, grep for matches on DType to update all dispatch tables"],"tags":["rust","tensor","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"}