{"record":{"id":"01fdbda7f8a4fa02","repo":"tracel-ai/burn","slug":"read-indices-unsupported-index-dtype","errorCode":null,"errorMessage":"read_indices: unsupported index dtype {:?}","messagePattern":"read_indices: unsupported index dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/gather_scatter.rs","lineNumber":134,"sourceCode":"            tensor\n                .storage::<u32>()\n                .iter()\n                .map(|&v| {\n                    isize::try_from(v).unwrap_or_else(|_| {\n                        panic!(\"read_indices: u32 index {v} out of isize range\")\n                    })\n                })\n                .collect(),\n        ),\n        DType::U16 => Cow::Owned(\n            tensor\n                .storage::<u16>()\n                .iter()\n                .map(|&v| v as isize)\n                .collect(),\n        ),\n        DType::U8 => Cow::Owned(tensor.storage::<u8>().iter().map(|&v| v as isize).collect()),\n        other => panic!(\"read_indices: unsupported index dtype {:?}\", other),\n    }\n}\n\n#[cold]\n#[inline(never)]\nfn index_oob(raw: isize, dim_size: usize) -> ! {\n    panic!(\"index {raw} out of bounds for dimension of size {dim_size}\");\n}\n\n/// Validate an index is non-negative and within bounds, panicking with a clear message otherwise.\n#[inline(always)]\nfn checked_index(raw: isize, dim_size: usize) -> usize {\n    if raw < 0 || raw as usize >= dim_size {\n        index_oob(raw, dim_size);\n    }\n    raw as usize\n}\n","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/gather_scatter.rs#L116-L152","documentation":"read_indices supports only I64, I32, U64, U32, U16, and U8 index tensors. Any other dtype (floats, bool) passed as the indices argument makes it panic with 'unsupported index dtype'. The library requires index tensors to be of integer dtype because they address elements.","triggerScenarios":"Passing a float (F32/F64/F16/BF16) or bool tensor as the indices argument to gather, scatter_update, select, select_update, scatter_nd, or gather_nd.","commonSituations":"Porting NumPy/PyTorch code where indices are floats (e.g. argmax results cast implicitly, or `indices.round()` returning a float tensor), forgetting to cast after arithmetic, or API confusion between a values tensor and the indices tensor argument order.","solutions":["Cast the indices tensor to an integer dtype: indices.cast::<i64>() (or i32/u32)","If indices come from float math, use floor/round then cast to an int dtype","Double-check argument order — the second tensor to gather/scatter must be the indices","Ensure argmax/top-k outputs (already int dtype) are not cast to floats in between"],"exampleFix":"// before\nlet idx = positions.cast::<f32>();\nlet out = tensor.gather(0, idx); // panic: unsupported index dtype F32\n// after\nlet out = tensor.gather(0, positions.cast::<i64>());","handlingStrategy":"type-guard","validationCode":"// before passing indices to gather/scatter\nmatch indices.dtype() {\n    DType::I64 | DType::I32 | DType::U64 | DType::U32 | DType::U16 | DType::U8 => {},\n    other => panic!(\"indices must be an integer dtype, got {:?}\", other),\n}","typeGuard":"fn is_valid_index_dtype(d: DType) -> bool {\n    matches!(d, DType::I64 | DType::I32 | DType::U64 | DType::U32 | DType::U16 | DType::U8)\n}","tryCatchPattern":null,"preventionTips":["Always cast index tensors to i64/i32 before gather/scatter","Never round-trip indices through float dtypes","Check argument order: indices is always the second tensor"],"tags":["panic","dtype-mismatch","indexing","rust"],"backgroundTag":"unsupported-dtype","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"}