{"record":{"id":"9c44957ba4a499ff","repo":"tracel-ai/burn","slug":"expected-int-handle-got-9c4495","errorCode":null,"errorMessage":"Expected int handle, got {}","messagePattern":"Expected int handle, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/backend.rs","lineNumber":144,"sourceCode":"    }\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> {\n        match handle.handle {\n            HandleKind::Quantized(handle) => handle,\n            _ => panic!(\"Expected quantized handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn float_tensor_handle(tensor: FloatTensor<Self>) -> Self::Handle {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/backend.rs#L126-L162","documentation":"`NdArray::int_tensor` (BackendIr) panics when the given TensorHandle wraps a `HandleKind` other than `HandleKind::Int`. The runtime uses it to materialize integer tensor primitives; a Float/Bool/Quantized handle reaching it is a type-erased handle mismatch between the declared tensor kind and the stored resource.","triggerScenarios":"Calling `NdArray::int_tensor(handle)` (or `get_int_tensor`) with a handle registered as Float, Bool, or Quantized — e.g. passing a float tensor to an integer op.","commonSituations":"Frontend op expecting an int tensor receives a float one (missing cast before `topk` indices, arange, embedding ids); custom IR code registering tensors with the wrong TensorKind; version mismatch where a backend changed handle wrapping.","solutions":["Cast the tensor to an integer dtype in the frontend before the op (`tensor.int()` / `cast(DType::I64)`).","Call the matching accessor (`float_tensor`, `bool_tensor`, `quantized_tensor`) for the handle's actual kind in custom backend code.","Verify the TensorKind in the TensorIr/TensorDescription matches the resource stored in the handle store.","Trace where the tensor was created and ensure it was registered as an int tensor."],"exampleFix":"// before\nlet ids = NdArray::int_tensor(float_handle); // panics\n// after\nlet ids = NdArray::int_tensor(int_handle); // or: let f = NdArray::float_tensor(float_handle);","handlingStrategy":"type-guard","validationCode":"fn ensure_int(t: &TensorIr) -> Result<(), String> {\n    (t.kind == TensorKind::Int && matches!(t.dtype, DType::I8 | DType::I16 | DType::I32 | DType::I64))\n        .then_some(())\n        .ok_or_else(|| format!(\"expected int tensor, got kind {:?} dtype {:?}\", t.kind, t.dtype))\n}","typeGuard":"fn as_int_handle(h: HandleKind<NdArray>) -> Option<ArrayHandle> {\n    match h { HandleKind::Int(a) => Some(a), _ => None }\n}","tryCatchPattern":"let i = std::panic::catch_unwind(|| NdArray::int_tensor(th))\n    .map_err(|_| anyhow!(\"handle is not int; expected {}\", th.handle.name()))?;","preventionTips":["Call int_tensor only for TensorKind::Int registrations","Cast float tensors with .int() before integer ops (indices, arange, embeddings)","Keep frontend tensor types distinct (Tensor<B, D, Int> vs Float) so the compiler enforces kinds","Validate TensorKind in any hand-built TensorIr"],"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"}