{"record":{"id":"69bb68d880c082fc","repo":"tracel-ai/burn","slug":"expected-bool-tensor-got","errorCode":null,"errorMessage":"Expected bool tensor, got {:?}","messagePattern":"Expected bool tensor, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/tensor.rs","lineNumber":41,"sourceCode":"    F64(NdArrayStorage<f64>),\n    F32(NdArrayStorage<f32>),\n    I64(NdArrayStorage<i64>),\n    I32(NdArrayStorage<i32>),\n    I16(NdArrayStorage<i16>),\n    I8(NdArrayStorage<i8>),\n    U64(NdArrayStorage<u64>),\n    U32(NdArrayStorage<u32>),\n    U16(NdArrayStorage<u16>),\n    U8(NdArrayStorage<u8>),\n    Bool(NdArrayStorage<bool>),\n}\n\nimpl NdArrayTensor {\n    /// Extract bool array, converting to owned if necessary.\n    pub(crate) fn bool(self) -> SharedArray<bool> {\n        match self {\n            NdArrayTensor::Bool(storage) => storage.into_shared(),\n            _ => unimplemented!(\"Expected bool tensor, got {:?}\", self.dtype()),\n        }\n    }\n\n    /// Returns true if this tensor uses borrowed (zero-copy) storage.\n    #[inline]\n    pub fn is_borrowed(&self) -> bool {\n        macro_rules! check {\n            ($($variant:ident),*) => {\n                match self {\n                    $(NdArrayTensor::$variant(s) => s.is_borrowed(),)*\n                }\n            };\n        }\n        check!(F64, F32, I64, I32, I16, I8, U64, U32, U16, U8, Bool)\n    }\n}\n\npub(crate) fn cast_to_dtype<E1: Element>(array: SharedArray<E1>, dtype: DType) -> NdArrayTensor","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/tensor.rs#L23-L59","documentation":"Type guard in `NdArrayTensor::bool`: a caller invoked a boolean tensor operation (and/or/not/equal/slice_assign/reshape access path) on storage whose dtype is not Bool; the ndarray backend cannot reinterpret non-boolean storage as a bool array, so it panics.","triggerScenarios":"Thrown at crates/burn-ndarray/src/tensor.rs:41 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the tensor was created with DType::Bool before applying boolean ops","Explicitly cast/convert the tensor to bool (e.g., via a comparison op)","Check the dtype reported in the message and trace where the tensor was produced"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}