{"record":{"id":"d1b20bed6b6bb26a","repo":"tracel-ai/burn","slug":"int-into-float-unsupported-source-dtype","errorCode":null,"errorMessage":"int_into_float: unsupported source dtype {:?}","messagePattern":"int_into_float: unsupported source dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/int.rs","lineNumber":599,"sourceCode":"        let tensor = tensor.to_contiguous();\n        let shape = tensor.layout().shape().clone();\n        let src = tensor.dtype();\n        let out_dt = DType::from(out_dtype);\n\n        // Read source ints, applying conversion per-element.\n        // Each arm binds `$x` to the native int value; `$conv` must work for all int types.\n        macro_rules! read_ints {\n            (|$x:ident| $conv:expr) => {\n                match src {\n                    DType::I64 => tensor.storage::<i64>().iter().map(|&$x| $conv).collect(),\n                    DType::I32 => tensor.storage::<i32>().iter().map(|&$x| $conv).collect(),\n                    DType::I16 => tensor.storage::<i16>().iter().map(|&$x| $conv).collect(),\n                    DType::I8 => tensor.storage::<i8>().iter().map(|&$x| $conv).collect(),\n                    DType::U64 => tensor.storage::<u64>().iter().map(|&$x| $conv).collect(),\n                    DType::U32 => tensor.storage::<u32>().iter().map(|&$x| $conv).collect(),\n                    DType::U16 => tensor.storage::<u16>().iter().map(|&$x| $conv).collect(),\n                    DType::U8 => tensor.storage::<u8>().iter().map(|&$x| $conv).collect(),\n                    _ => panic!(\"int_into_float: unsupported source dtype {:?}\", src),\n                }\n            };\n        }\n\n        match out_dtype {\n            FloatDType::F64 => {\n                let data: Vec<f64> = read_ints!(|x| x as f64);\n                FlexTensor::new(Bytes::from_elems(data), Layout::contiguous(shape), out_dt)\n            }\n            FloatDType::F32 | FloatDType::Flex32 => {\n                let data: Vec<f32> = read_ints!(|x| x as f32);\n                FlexTensor::new(Bytes::from_elems(data), Layout::contiguous(shape), out_dt)\n            }\n            FloatDType::F16 => {\n                let data: Vec<f16> = read_ints!(|x| f16::from_f32(x as f32));\n                FlexTensor::new(Bytes::from_elems(data), Layout::contiguous(shape), out_dt)\n            }\n            FloatDType::BF16 => {","sourceCodeStart":581,"sourceCodeEnd":617,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/int.rs#L581-L617","documentation":"int_into_float converts an integer tensor to a floating-point tensor. The read_ints! macro matches on the source dtype and covers all integer dtypes (I64/I32/I16/I8/U64/U32/U16/U8); the panic fires only when the source tensor is a non-integer dtype (e.g. F32, Bool), meaning a float or bool tensor reached the int->float conversion path. This is an internal invariant check: callers should never pass a non-int tensor here.","triggerScenarios":"Calling tensor.cast::<f32>() (or another float cast) on a Burn Flex tensor whose dtype is not an integer type — e.g. a F32/F64/BF16/F16 or Bool tensor produced by a comparison or already-float pipeline.","commonSituations":"Casting a boolean mask tensor (result of ==, >, etc.) to float; double-casting a tensor that was already converted; dtype mismatch after loading a checkpoint or external data where the tensor dtype was inferred differently than expected.","solutions":["Check the source tensor's dtype before casting and only call the float cast on integer tensors.","If the tensor is Bool, convert it to an integer dtype explicitly first (e.g. via int cast ops) before casting to float.","Remove redundant casts in the pipeline so an already-float tensor is not cast again.","Verify data-loading code produces the dtype you expect (log or assert tensor.dtype() upstream)."],"exampleFix":"// before: casting a bool mask directly\nlet mask_f = mask.cast::<f32>(); // panics: source dtype is Bool\n// after\nlet mask_i = mask.bool_to_int(); // or ensure mask was created as Int dtype\nlet mask_f = mask_i.cast::<f32>();","handlingStrategy":"validation","validationCode":"assert!(t.dtype().is_int(), \"int_into_float requires an int tensor, got {:?}\", t.dtype());","typeGuard":"fn is_int_tensor(t: &FlexTensor) -> bool { matches!(t.dtype(), DType::I64 | DType::I32 | DType::I16 | DType::I8 | DType::U64 | DType::U32 | DType::U16 | DType::U8) }","tryCatchPattern":null,"preventionTips":["Check dtype before every cast in mixed int/float pipelines","Convert Bool masks to int explicitly before float casts","Avoid double-casting tensors already converted to float"],"tags":["rust","burn","dtype","tensor-cast"],"backgroundTag":"unsupported-dtype-cast","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"}