{"record":{"id":"9ed62021ca4aa6da","repo":"tracel-ai/burn","slug":"int-cast-unsupported-conversion-from-to","errorCode":null,"errorMessage":"int_cast: unsupported conversion from {:?} to {:?}","messagePattern":"int_cast: unsupported conversion from (.+?) to (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/int.rs","lineNumber":958,"sourceCode":"            // From U8\n            DType::U8 => {\n                let storage: &[u8] = tensor.storage();\n                match target_dtype {\n                    DType::I64 => cast_impl!(storage, i64),\n                    DType::I32 => cast_impl!(storage, i32),\n                    DType::I16 => cast_impl!(storage, i16),\n                    DType::I8 => cast_impl!(storage, i8),\n                    DType::U64 => cast_impl!(storage, u64),\n                    DType::U32 => cast_impl!(storage, u32),\n                    DType::U16 => cast_impl!(storage, u16),\n                    _ => None,\n                }\n            }\n\n            _ => None,\n        };\n        let Some(bytes) = bytes else {\n            panic!(\n                \"int_cast: unsupported conversion from {:?} to {:?}\",\n                tensor.dtype(),\n                target_dtype\n            )\n        };\n        FlexTensor::new(bytes, Layout::contiguous(shape), target_dtype)\n    }\n\n    fn int_unfold(\n        tensor: IntTensor<Flex>,\n        dim: usize,\n        size: usize,\n        step: usize,\n    ) -> IntTensor<Flex> {\n        crate::ops::unfold::unfold_int(tensor, dim, size, step)\n    }\n\n    fn int_neg(tensor: IntTensor<Flex>) -> IntTensor<Flex> {","sourceCodeStart":940,"sourceCodeEnd":976,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/int.rs#L940-L976","documentation":"int_cast converts an integer tensor between integer dtypes via a large source-dtype x target-dtype match table. When no combination matches (bytes == None) it panics. This happens when the source or target dtype is not an integer type — e.g. casting an int tensor to a float dtype through this path, or casting a float/bool tensor to int — because those conversions are handled elsewhere (int_into_float / float ops).","triggerScenarios":"Calling tensor.cast::<T>() where the source tensor is int but the target is a float dtype (should go through int_into_float), or where the source is a float/bool tensor being cast to int, or an int-to-int pair absent from the table.","commonSituations":"Mixing int and float pipelines: casting counts/indices to f32 for division; casting boolean masks to i64 via the generic cast; using a dtype constant (e.g. DType::F32) computed dynamically so the non-int case isn't visible at compile time.","solutions":["For int-to-float conversion, ensure the call routes through the float cast path (int_into_float), not int_cast.","For float/bool sources, convert to an integer dtype using the appropriate op before int_cast.","Check both tensor.dtype() and the target dtype at the call site; log them if unsure.","Restrict dynamic dtype parameters to integer dtypes when the tensor is known to be int."],"exampleFix":"// before\nlet f = int_tensor.cast::<f32>(); // routed to int_cast -> panic\n// after\nlet f = int_tensor.float_cast::<f32>(); // or use the float conversion API (int_into_float path)","handlingStrategy":"validation","validationCode":"assert!(t.dtype().is_int() && target_dtype.is_int(), \"int_cast requires int-to-int conversion, got {:?} -> {:?}\", t.dtype(), target_dtype);","typeGuard":"fn is_int_to_int(src: DType, dst: DType) -> bool { src.is_int() && dst.is_int() }","tryCatchPattern":null,"preventionTips":["Route int-to-float conversions through the float cast path, not int_cast","Check both source and target dtype before generic casts","Avoid dynamic dtype parameters that can silently be float dtypes"],"tags":["rust","burn","dtype","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"}