{"record":{"id":"6fe89bc7f3604b3f","repo":"tracel-ai/burn","slug":"scatter-nd-is-not-supported-for-bool-tensors","errorCode":null,"errorMessage":"scatter_nd is not supported for bool tensors","messagePattern":"scatter_nd is not supported for bool tensors","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tensor/src/bridge/ops/bool.rs","lineNumber":163,"sourceCode":"    ) -> BridgeTensor {\n        match update {\n            IndexingUpdateOp::Add => BridgeTensor::bool(Dispatch::bool_scatter_or(\n                dim,\n                tensor.into(),\n                indices.into(),\n                values.into(),\n            )),\n            _ => unimplemented!(),\n        }\n    }\n\n    fn scatter_nd(\n        _data: BridgeTensor,\n        _indices: BridgeTensor,\n        _values: BridgeTensor,\n        _reduction: IndexingUpdateOp,\n    ) -> BridgeTensor {\n        panic!(\"scatter_nd is not supported for bool tensors\")\n    }\n\n    fn gather_nd(_data: BridgeTensor, _indices: BridgeTensor) -> BridgeTensor {\n        panic!(\"gather_nd is not supported for bool tensors\")\n    }\n\n    fn device(tensor: &BridgeTensor) -> Device {\n        Device::new(tensor.as_dispatch().device())\n    }\n\n    fn to_device(tensor: BridgeTensor, device: &Device) -> BridgeTensor {\n        BridgeTensor::bool(Dispatch::bool_to_device(\n            tensor.into(),\n            device.as_dispatch(),\n        ))\n    }\n\n    async fn into_data_async(tensor: BridgeTensor) -> Result<TensorData, ExecutionError> {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tensor/src/bridge/ops/bool.rs#L145-L181","documentation":"The Bool bridge does not implement scatter_nd; the method unconditionally panics. Scatter-style indexed updates are only supported for numeric element types (Float/Int), so attempting one on a bool tensor always aborts.","triggerScenarios":"Calling tensor.scatter(indices, values, op) / scatter_nd on a Tensor::<B, D, Bool> — e.g. building boolean masks by writing true/false values at index positions.","commonSituations":"Porting numeric scatter code to bool masks; constructing boolean lookup masks by scattered assignment; translating models (e.g. from ONNX) that scatter bool values.","solutions":["Scatter on an integer tensor instead, then convert to bool with .bool_cast() / .bool()","Write the mask differently: compute bool results with comparisons (e.g. create Int zeros, scatter 1s, compare == 1)","If the values are boolean flags, scatter uint8/int8 values 0/1 and cast to Bool","Reformulate the op with slicing/assignment or select/gather constructs that Bool does support"],"exampleFix":"// before\nlet mask: Tensor<B, 2, Bool> = zeros.scatter(indices, ones_bool, UpdateOp::Assign);\n// after\nlet ints: Tensor<B, 2, Int> = zeros.scatter(indices, ones, UpdateOp::Assign);\nlet mask = ints.bool_cast();","handlingStrategy":"validation","validationCode":"fn scatter_bool_safe<B: Backend, const D: usize>(\n    data: Tensor<B, D, Bool>, _indices: Tensor<B, 1, Int>, _values: Tensor<B, 1, Bool>,\n) -> Tensor<B, D, Bool> {\n    panic!(\"scatter is unsupported on Bool; scatter on Int and cast with .bool_cast() instead\")\n}\n// preferred: scatter on Int, then convert\n// let ints = zeros_int.scatter(indices, ones_int, UpdateOp::Assign);\n// let mask = ints.bool_cast();","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| mask.scatter(indices, values, UpdateOp::Assign))\n    .map_err(|_| \"scatter_nd unsupported for Bool; scatter on Int and cast\")?;","preventionTips":["Never call scatter/gather_nd on Tensor<..., Bool>; encode masks as 0/1 Int tensors instead","Search the codebase for scatter on Bool tensors when porting models","Document in mask-building helpers that Bool only supports comparison/select-style ops"],"tags":["rust","burn","unsupported-operation","bool","scatter"],"backgroundTag":"unsupported-op-backend","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"}