{"record":{"id":"2507b21764f424a1","repo":"tracel-ai/burn","slug":"expected-bool-data-type-got-value","errorCode":null,"errorMessage":"Expected bool data type, got {value:?}","messagePattern":"Expected bool data type, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-std/src/tensor/dtype.rs","lineNumber":304,"sourceCode":"\n/// Boolean dtype.\n///\n/// This is currently an alias to [`BoolStore`], since it only varies by the storage representation.\npub type BoolDType = BoolStore;\n\n#[allow(deprecated)]\nimpl From<DType> for BoolDType {\n    fn from(value: DType) -> Self {\n        match value {\n            DType::Bool(store) => match store {\n                BoolStore::Native => BoolDType::Native,\n                BoolStore::U8 => BoolDType::U8,\n                BoolStore::U32 => BoolDType::U32,\n            },\n            // For compat BoolElem associated type\n            DType::U8 => BoolDType::U8,\n            DType::U32 => BoolDType::U32,\n            _ => panic!(\"Expected bool data type, got {value:?}\"),\n        }\n    }\n}\n\nimpl From<BoolDType> for DType {\n    fn from(value: BoolDType) -> Self {\n        match value {\n            BoolDType::Native => DType::Bool(BoolStore::Native),\n            BoolDType::U8 => DType::Bool(BoolStore::U8),\n            BoolDType::U32 => DType::Bool(BoolStore::U32),\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-std/src/tensor/dtype.rs#L286-L322","documentation":"`impl From<DType> for BoolDType` in burn-std only knows how to convert DTypes that represent boolean data (DType::Bool variants, plus U8/U32 as legacy compat aliases for the old BoolElem associated type). If the DType is a float, integer, or other non-bool type, the conversion is undefined and the code panics. It means you asked a DType to be interpreted as a boolean dtype when it is not one.","triggerScenarios":"Calling `BoolDType::from(dtype)` (or `dtype.into()`) where `dtype` is e.g. DType::F32, DType::I64, etc. Typically reached through code paths that assume a tensor/operand has a bool dtype (mask handling, bool storage config) but receive a non-bool tensor.","commonSituations":"Passing a float/int tensor where a boolean mask is expected; mixing dtypes when constructing bool-backed tensors with U8/U32 storage; generic code that assumes `B::BoolElem`-compatible dtype but is fed another dtype after a backend or burn-version change.","solutions":["Check the tensor's dtype before converting; ensure it is DType::Bool (or U8/U32) before calling `BoolDType::from`.","Cast the tensor to bool (e.g. `tensor.bool()` / `bool_mask` helpers) instead of converting the dtype directly.","If this comes from library internals after an upgrade, verify storage types: bool tensors saved/loaded with a different BoolStore (Native/U8/U32) may arrive mis-typed; re-export/reload data with the current version."],"exampleFix":"// before\nlet bdt: BoolDType = tensor.dtype().into(); // panics if dtype is F32\n// after\nlet bdt = match tensor.dtype() {\n    DType::Bool(_) | DType::U8 | DType::U32 => BoolDType::from(tensor.dtype()),\n    _ => panic!(\"mask tensor must be bool, got {:?}\", tensor.dtype()),\n};","handlingStrategy":"validation","validationCode":"fn ensure_bool_compatible(dtype: DType) {\n    match dtype {\n        DType::Bool(_) | DType::U8 | DType::U32 => {}\n        other => panic!(\"expected bool-like dtype, got {other:?}\"),\n    }\n}","typeGuard":"fn is_bool_dtype(dtype: &DType) -> bool {\n    matches!(dtype, DType::Bool(_) | DType::U8 | DType::U32)\n}","tryCatchPattern":"// panic-based; guard the conversion instead\nlet bdt = if is_bool_dtype(&dtype) { BoolDType::from(dtype) } else { return Err(\"not a bool dtype\"); };","preventionTips":["Check tensor.dtype() before any dtype conversion","Cast masks to bool explicitly before use","Be aware U8/U32 are only compat aliases for bool, not general int types"],"tags":["rust","panic","dtype","tensor"],"backgroundTag":"incompatible-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"}