{"record":{"id":"31159e13c7646c5d","repo":"tracel-ai/burn","slug":"unsupported-dtype-for-int-from-data-31159e","errorCode":null,"errorMessage":"Unsupported dtype for `int_from_data`: {:?}","messagePattern":"Unsupported dtype for `int_from_data`: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/ops/int_tensor.rs","lineNumber":29,"sourceCode":"\n// Current crate\nuse crate::SharedArray;\nuse crate::execute_with_int_dtype;\nuse crate::ops::matmul::matmul;\nuse crate::{ExpElement, NdArrayDevice, SEED, execute_with_int_out_dtype, slice};\nuse crate::{NdArray, cast_to_dtype, execute_with_dtype, tensor::NdArrayTensor};\nuse crate::{cat_with_dtype, execute_with_float_out_dtype};\n\n// Workspace crates\nuse super::{NdArrayBitOps, NdArrayMathOps, NdArrayOps};\nuse burn_backend::{DType, Shape, TensorData};\n\nimpl IntTensorOps<Self> for NdArray {\n    fn int_from_data(data: TensorData, _device: &NdArrayDevice) -> NdArrayTensor {\n        if data.dtype.is_int() || data.dtype.is_uint() {\n            NdArrayTensor::from_data(data)\n        } else {\n            unimplemented!(\"Unsupported dtype for `int_from_data`: {:?}\", data.dtype)\n        }\n    }\n\n    async fn int_into_data(tensor: NdArrayTensor) -> Result<TensorData, ExecutionError> {\n        Ok(tensor.into_data())\n    }\n\n    fn int_to_device(tensor: NdArrayTensor, _device: &NdArrayDevice) -> NdArrayTensor {\n        tensor\n    }\n\n    fn int_reshape(tensor: NdArrayTensor, shape: Shape) -> NdArrayTensor {\n        execute_with_int_dtype!(tensor, |array| NdArrayOps::reshape(array, shape))\n    }\n\n    fn int_slice(tensor: NdArrayTensor, slices: &[burn_backend::Slice]) -> NdArrayTensor {\n        slice!(tensor, slices)\n    }","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/ops/int_tensor.rs#L11-L47","documentation":"burn-ndarray's `int_from_data` accepts only int or uint dtype TensorData; float or bool data reaches the `else` arm and panics with `unimplemented!(\"Unsupported dtype for `int_from_data`: {:?}\", data.dtype)`. There is no implicit dtype conversion in the ndarray backend's tensor constructors.","triggerScenarios":"Creating an int tensor from float TensorData via `int_from_data` / `Tensor::<NdArray,_,Int>::from_data(...)`, e.g. passing F32 buffers, image data decoded as float, or imported ONNX weights stored as float into int tensors.","commonSituations":"Feeding image pixel buffers (F32-normalized) into int tensors; loading indices from float-preprocessed arrays; assuming cross-backend from_data behavior (some backends coerce, ndarray does not).","solutions":["Convert the data first: `data.convert::<i64>()` (or the target int type)","On the Tensor API, create as float then `.int()` to cast","Fix the data source to emit int/uint buffers","Check `data.dtype.is_int() || data.dtype.is_uint()` before calling"],"exampleFix":"// before\nlet t = Tensor::<NdArray, 1, Int>::from_data(data_f32, &device);\n// after\nlet t = Tensor::<NdArray, 1, Int>::from_data(data_f32.convert::<i64>(), &device);","handlingStrategy":"validation","validationCode":"if !(data.dtype.is_int() || data.dtype.is_uint()) {\n    data = data.convert::<i64>();\n}\nlet t = Tensor::<NdArray, 1, Int>::from_data(data, &device);","typeGuard":"fn is_int_data(data: &TensorData) -> bool {\n    data.dtype.is_int() || data.dtype.is_uint()\n}","tryCatchPattern":"// pre-convert; from_data panics instead of returning Err\nlet safe_data = if is_int_data(&data) { data } else { data.convert::<i64>() };\nlet t = Tensor::<NdArray, 1, Int>::from_data(safe_data, &device);","preventionTips":["Never assume from_data coerces float data; convert explicitly","Normalize decoded image/imported data dtypes at load time","Create tensors with the correct kind (Float vs Int) for their payload","Check data.dtype before every Tensor::from_data call on the ndarray backend"],"tags":["rust","dtype","ndarray","tensor-creation"],"backgroundTag":"unsupported-dtype-conversion","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"}