{"record":{"id":"0bc15f20182953d9","repo":"tracel-ai/burn","slug":"unsupported-dtype-for-bool-from-data-0bc15f","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-tch/src/ops/bool_tensor.rs","lineNumber":19,"sourceCode":"use super::TchOps;\nuse crate::IntoKind;\nuse crate::{LibTorch, LibTorchDevice, TchShape, TchTensor};\nuse burn_backend::BoolStore;\nuse burn_backend::ExecutionError;\nuse burn_backend::IntDType;\nuse burn_backend::Scalar;\nuse burn_backend::tensor::BoolTensor;\nuse burn_backend::tensor::IntTensor;\nuse burn_backend::{BoolDType, FloatDType};\nuse burn_backend::{Shape, TensorData, TensorMetadata, ops::BoolTensorOps};\n\nimpl BoolTensorOps<Self> for LibTorch {\n    fn bool_from_data(data: TensorData, device: &LibTorchDevice) -> TchTensor {\n        match data.dtype {\n            burn_backend::DType::Bool(BoolStore::Native) => {\n                TchTensor::from_data::<bool>(data, (*device).into())\n            }\n            _ => unimplemented!(\"Unsupported dtype for `bool_from_data`\"),\n        }\n    }\n\n    fn bool_repeat_dim(tensor: TchTensor, dim: usize, times: usize) -> TchTensor {\n        TchOps::repeat_dim(tensor, dim, times)\n    }\n\n    async fn bool_into_data(tensor: TchTensor) -> Result<TensorData, ExecutionError> {\n        let shape = tensor.shape();\n        let tensor = Self::bool_reshape(tensor.clone(), Shape::new([shape.num_elements()]));\n        let values: Result<Vec<bool>, tch::TchError> = tensor.tensor.shallow_clone().try_into();\n        Ok(TensorData::new(values.unwrap(), shape))\n    }\n\n    fn bool_to_device(tensor: TchTensor, device: &LibTorchDevice) -> TchTensor {\n        TchOps::to_device(tensor, device)\n    }\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tch/src/ops/bool_tensor.rs#L1-L37","documentation":"LibTorch's bool_from_data in burn-tch only supports TensorData whose dtype is Bool(Native); any other dtype falls into a catch-all unimplemented!(). It converts tensor data into a torch bool tensor and simply does not handle casts from other element types.","triggerScenarios":"Calling tensor creation APIs that route to bool_from_data (e.g. Tensor::from_data into a bool tensor on the LibTorch backend) with data whose dtype is not burn_backend::DType::Bool(BoolStore::Native).","commonSituations":"Passing byte/u8-backed boolean masks (common from file formats or numpy arrays) into LibTorch-backed bool tensors; differences in how bools are stored across backends or serialized records.","solutions":["Convert the data to a native bool dtype before constructing the tensor (TensorData::convert::<bool>())","Create the tensor with the original dtype and cast afterwards via tensor.cast::<bool>() or .to_dtype()","Check data.dtype with a type guard before the call","File/patch burn-tch to reinterpret non-native bool storage instead of panicking"],"exampleFix":"// before\nlet mask = Tensor::<LibTorch, _, _>::from_data(data_u8, &device);\n\n// after\nlet mask = Tensor::<LibTorch, _, _>::from_data(\n    data_u8.convert::<bool>(), &device\n);","handlingStrategy":"validation","validationCode":"if data.dtype != burn_backend::DType::Bool(BoolStore::Native) {\n    data = data.convert::<bool>();\n}\nlet mask = Tensor::<LibTorch, D, Bool>::from_data(data, &device);","typeGuard":"fn is_native_bool(dtype: burn_backend::DType) -> bool {\n    dtype == burn_backend::DType::Bool(BoolStore::Native)\n}","tryCatchPattern":null,"preventionTips":["Always convert TensorData to bool before creating bool tensors on LibTorch","Check dtype when loading masks from files/numpy (often u8-backed)","Add dtype assertions at deserialization boundaries"],"tags":["rust","burn","libtorch","tensor","dtype"],"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"}