torch_cpu_topk_set

Function torch_cpu_topk_set 

Source
pub fn torch_cpu_topk_set(vals: &[f32], k: usize) -> Vec<usize>
Expand description

2026-09-25: The index set torch’s CPU topk(k, largest=True) returns for vals, ties included, emulated as libstdc++’s introselect (__introselect, __move_median_to_first, __unguarded_partition, __insertion_sort) over (value, index) pairs with a descending comparator, keeping the first k pairs. Among equal values (the indexer’s many -inf entries) the set is whatever that order leaves in front. Only k * 64 > n is emulated (asserted). Pinned by topk_tie_order_matches_torch_cpu.