{"record":{"id":"8ef5331c48fecf61","repo":"tracel-ai/burn","slug":"unsupported-dtype-for-bool-from-data-8ef533","errorCode":null,"errorMessage":"Unsupported dtype for `bool_from_data`","messagePattern":"Unsupported dtype for `bool_from_data`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/ops/bool_tensor.rs","lineNumber":28,"sourceCode":"};\nuse burn_std::{BoolDType, FloatDType, IntDType};\nuse ndarray::IntoDimension;\n\n// Current crate\nuse crate::{NdArray, execute_with_int_dtype, tensor::NdArrayTensor};\nuse crate::{\n    NdArrayDevice, SharedArray, execute_with_float_out_dtype, execute_with_int_out_dtype, slice,\n};\n\n// Workspace crates\nuse burn_backend::{Shape, TensorData};\n\nuse super::{NdArrayBoolOps, NdArrayOps};\n\nimpl BoolTensorOps<Self> for NdArray {\n    fn bool_from_data(data: TensorData, _device: &NdArrayDevice) -> NdArrayTensor {\n        if !data.dtype.is_bool() {\n            unimplemented!(\"Unsupported dtype for `bool_from_data`\")\n        }\n        NdArrayTensor::from_data(data)\n    }\n\n    async fn bool_into_data(tensor: NdArrayTensor) -> Result<TensorData, ExecutionError> {\n        Ok(tensor.into_data())\n    }\n\n    fn bool_to_device(tensor: NdArrayTensor, _device: &NdArrayDevice) -> NdArrayTensor {\n        tensor\n    }\n\n    fn bool_reshape(tensor: NdArrayTensor, shape: Shape) -> NdArrayTensor {\n        NdArrayOps::reshape(tensor.bool(), shape).into()\n    }\n\n    fn bool_slice(tensor: NdArrayTensor, slices: &[burn_backend::Slice]) -> NdArrayTensor {\n        slice!(tensor, slices)","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/ops/bool_tensor.rs#L10-L46","documentation":"burn-ndarray's `bool_from_data` validates that incoming `TensorData` has a bool dtype before constructing the tensor; anything else (int, float, uint) panics with `unimplemented!(\"Unsupported dtype for `bool_from_data`\")`. The ndarray backend does not implicitly convert data types on tensor creation.","triggerScenarios":"Creating a bool tensor from data via `bool_from_data` / `Tensor::<NdArray,_,Bool>::from_data(...)` where the TensorData dtype is not Bool, e.g. data loaded from a file or produced by an int/float op.","commonSituations":"Loading masks from numpy/pickle files saved as uint8; building tensors from raw buffers whose dtype metadata is I32 or F32; backend migration where another backend auto-converted.","solutions":["Convert the data to bool before calling: `data.convert::<bool>()`","On the Tensor API, cast first: `tensor.bool()` / `tensor.cast(DType::Bool)` then take data","Fix the data producer so masks are stored as bool","Explicitly compare/re-derive the mask with bool ops instead of converting raw data"],"exampleFix":"// before\nlet t = Tensor::<NdArray, 2, Bool>::from_data(data_u8, &device);\n// after\nlet t = Tensor::<NdArray, 2, Bool>::from_data(data_u8.convert::<bool>(), &device);","handlingStrategy":"validation","validationCode":"if !data.dtype.is_bool() {\n    data = data.convert::<bool>();\n}\nlet t = Tensor::<NdArray, 2, Bool>::from_data(data, &device);","typeGuard":"fn is_bool_data(data: &TensorData) -> bool {\n    data.dtype.is_bool()\n}","tryCatchPattern":"// panic is unrecoverable; normalize data before the API call\nlet safe_data = if is_bool_data(&data) { data } else { data.convert::<bool>() };\nlet t = Tensor::<NdArray, 2, Bool>::from_data(safe_data, &device);","preventionTips":["Store boolean masks as bool dtype in files/buffers (not uint8)","Call `.convert::<bool>()` on TensorData before bool tensor creation","Check data.dtype right after loading external data","Add a load helper that normalizes dtypes once at ingestion"],"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"}