{"record":{"id":"045acb48762ddbb8","repo":"tracel-ai/burn","slug":"not-supported-for-sorting-operations","errorCode":null,"errorMessage":"not supported for sorting operations","messagePattern":"not supported for sorting operations","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-backend/src/backend/ops/sort.rs","lineNumber":34,"sourceCode":"        macro_rules! dispatch_index {\n            ($index_ty:ty) => {\n                match $data.dtype {\n                    DType::F64 => $fn::<f64, $index_ty>($data, $($args),*),\n                    DType::F32 | DType::Flex32 => {\n                        $fn::<f32, $index_ty>($data, $($args),*)\n                    }\n                    DType::F16 => $fn::<f16, $index_ty>($data, $($args),*),\n                    DType::BF16 => $fn::<bf16, $index_ty>($data, $($args),*),\n                    DType::I64 => $fn::<i64, $index_ty>($data, $($args),*),\n                    DType::I32 => $fn::<i32, $index_ty>($data, $($args),*),\n                    DType::I16 => $fn::<i16, $index_ty>($data, $($args),*),\n                    DType::I8 => $fn::<i8, $index_ty>($data, $($args),*),\n                    DType::U64 => $fn::<u64, $index_ty>($data, $($args),*),\n                    DType::U32 => $fn::<u32, $index_ty>($data, $($args),*),\n                    DType::U16 => $fn::<u16, $index_ty>($data, $($args),*),\n                    DType::U8 => $fn::<u8, $index_ty>($data, $($args),*),\n                    DType::Bool(_) | DType::QFloat(_) => {\n                        unimplemented!(\"not supported for sorting operations\")\n                    }\n                }\n            };\n        }\n\n        match $index_dtype {\n            IntDType::I64 => dispatch_index!(i64),\n            IntDType::I32 => dispatch_index!(i32),\n            IntDType::I16 => dispatch_index!(i16),\n            IntDType::I8 => dispatch_index!(i8),\n            IntDType::U64 => dispatch_index!(u64),\n            IntDType::U32 => dispatch_index!(u32),\n            IntDType::U16 => dispatch_index!(u16),\n            IntDType::U8 => dispatch_index!(u8),\n        }\n    }};\n\n    // Dispatch only element dtype.","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-backend/src/backend/ops/sort.rs#L16-L52","documentation":"A dtype-dispatch macro in crates/burn-backend/src/backend/ops/sort.rs matches the element dtype before invoking a sorting kernel; `Bool` and `QFloat` dtypes fall through to `unimplemented!(\"not supported for sorting operations\")`. Sorting kernels only support numeric integer/float dtypes.","triggerScenarios":"Calling sort/topk/argsort (the macro-generated dispatch with index dtype parameter) on a Bool or quantized (QFloat) tensor.","commonSituations":"Sorting a boolean mask tensor directly instead of converting it; applying topk/argsort to quantized model outputs without dequantizing first.","solutions":["Cast the Bool tensor to a numeric dtype (e.g. I32/U8/F32) before sorting.","Dequantize QFloat tensors to F32/F16 before sorting operations.","Reorder logic so masks are used to filter/select, not sorted."],"exampleFix":"// before\nlet sorted = tensor.sort(dim); // tensor is Bool or QFloat -> panics\n\n// after\nlet numeric = tensor.cast(DType::F32); // or dequantize QFloat\nlet sorted = numeric.sort(dim);","handlingStrategy":"validation","validationCode":"fn sortable(dtype: DType) -> bool {\n    !matches!(dtype, DType::Bool(_) | DType::QFloat(_))\n}\nassert!(sortable(tensor.dtype()), \"cast or dequantize before sorting\");","typeGuard":"fn is_sortable(dtype: DType) -> bool {\n    matches!(dtype, DType::F32 | DType::F16 | DType::BF16 | DType::I8 | DType::I16 | DType::I32 | DType::I64 | DType::U8 | DType::U16 | DType::U32 | DType::U64)\n}","tryCatchPattern":null,"preventionTips":["Never sort Bool masks; cast to numeric first.","Dequantize QFloat tensors before any sort/topk/argsort.","Add dtype assertions before dispatching to sort kernels."],"tags":["rust","sorting","dtype","bool","quantization"],"backgroundTag":"dtype-not-supported","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"}