subtensor
subtensor copied to clipboard
Ban direct indexing in `Math.rs`
Ban direct indexing in subtensor/src/math.rs
Problem:
The remaining #[allow(clippy::indexing_slicing)] live in math.rs, allowing potential panics in vec[idx] and slice[...].
Proposal:
- Remove
#[allow(clippy::indexing_slicing)]frompallets/subtensor/src/math.rs. - Replace every
vec[idx]orslice[a..b]with a safe alternative, for example:// Before — can panic if `i >= vector.len()` idxs.sort_by_key(|&i| &vector[i]); // After — returns zero on OOB idxs.sort_by_key(|&i| { vector .get(i) .copied() .unwrap_or(I32F32::saturating_from_num(0)) });```