{"record":{"id":"9f7b92a7729701c5","repo":"tracel-ai/burn","slug":"expected-float-handle-got-9f7b92","errorCode":null,"errorMessage":"Expected float handle, got {}","messagePattern":"Expected float handle, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/backend.rs","lineNumber":137,"sourceCode":"                }\n            }\n        }\n    }\n\n    fn device_count(_: u16) -> usize {\n        1\n    }\n\n    fn flush(_device: &Self::Device) {}\n}\n\nimpl BackendIr for NdArray {\n    type Handle = HandleKind<Self>;\n\n    fn float_tensor(handle: TensorHandle<Self::Handle>) -> FloatTensor<Self> {\n        match handle.handle {\n            HandleKind::Float(handle) => handle,\n            _ => panic!(\"Expected float handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn int_tensor(handle: TensorHandle<Self::Handle>) -> IntTensor<Self> {\n        match handle.handle {\n            HandleKind::Int(handle) => handle,\n            _ => panic!(\"Expected int handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn bool_tensor(handle: TensorHandle<Self::Handle>) -> BoolTensor<Self> {\n        match handle.handle {\n            HandleKind::Bool(handle) => handle,\n            _ => panic!(\"Expected bool handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn quantized_tensor(handle: TensorHandle<Self::Handle>) -> QuantizedTensor<Self> {","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/backend.rs#L119-L155","documentation":"`NdArray::float_tensor` (BackendIr) unwraps a type-erased `HandleKind` and panics if the variant is not `HandleKind::Float`. It is called when the burn runtime converts a tensor handle into the NdArray float tensor primitive; receiving a non-float handle means the runtime handed a float-typed operation a tensor registered as int, bool, or quantized.","triggerScenarios":"Calling `NdArray::float_tensor(handle)` (or `HandleStore::get_float_tensor`, or float tensor ops via burn-ir graph execution) with a TensorIr/handle whose registered kind is Int, Bool, or Quantized.","commonSituations":"Mixing integer and float tensors in a frontend op that assumes float; a mis-typed graph in custom IR code passing an int tensor where the descriptor says float; wrong `TensorKind` used when registering the tensor in the handle store.","solutions":["Check the dtype/kind of the tensor being passed; convert with `.float()` / `cast(DType::F32)` in the frontend before the op.","Fix the `TensorKind` used when registering the tensor (TensorDescription) so it matches the actual handle variant.","In custom BackendIr code, ensure you call `int_tensor`/`bool_tensor`/`quantized_tensor` for their respective kinds instead of `float_tensor`.","If the mix comes from a burn-ir graph, dump the graph (tensor descriptions) and find the op whose output kind is wrong."],"exampleFix":"// before\nlet out = NdArray::float_tensor(handle_of_int_tensor); // panics\n// after\nlet out = NdArray::int_tensor(handle_of_int_tensor); // or cast the tensor to float first","handlingStrategy":"type-guard","validationCode":"fn ensure_float<B: BackendIr>(t: &TensorIr) -> Result<(), String> {\n    (t.kind == TensorKind::Float && matches!(t.dtype, DType::F32 | DType::F64))\n        .then_some(())\n        .ok_or_else(|| format!(\"expected float tensor, got kind {:?} dtype {:?}\", t.kind, t.dtype))\n}","typeGuard":"fn as_float_handle(h: HandleKind<NdArray>) -> Option<ArrayHandle> {\n    match h { HandleKind::Float(a) => Some(a), _ => None }\n}","tryCatchPattern":"let f = std::panic::catch_unwind(|| NdArray::float_tensor(th))\n    .map_err(|_| anyhow!(\"handle is not float; expected {}\", th.handle.name()))?;","preventionTips":["Match the accessor to the tensor kind: float_tensor/int_tensor/bool_tensor/quantized_tensor","Cast frontend tensors to float before float-only ops","Verify TensorKind in TensorIr matches the stored HandleKind variant","Dump the graph's tensor descriptions when a mismatch appears to find the mis-registered op"],"tags":["panic","burn","ndarray","backend","handle-mismatch"],"backgroundTag":"handle-kind-mismatch","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"}