refactor: simplify sub_matrix with iterator-driven column population
Refactored `sub_matrix` to delegate column population to `fill_sub_matrix`, replacing manual buffer allocation and explicit permutation loops with direct value assignment via `enumerate_slots_values`. This eliminates intermediate allocations, reduces pipeline overhead, and simplifies control flow while preserving slot ordering and permutation semantics.
This commit is contained in:
@@ -368,13 +368,8 @@ impl PersistentCompactIntMatrix {
|
|||||||
/// in the same order as `slots`. Column access is sequential to maximize
|
/// in the same order as `slots`. Column access is sequential to maximize
|
||||||
/// cache efficiency on the underlying mmap.
|
/// cache efficiency on the underlying mmap.
|
||||||
pub fn sub_matrix(&self, slots: &[usize]) -> Vec<Vec<u32>> {
|
pub fn sub_matrix(&self, slots: &[usize]) -> Vec<Vec<u32>> {
|
||||||
let n_cols = self.n_cols();
|
let mut out: Vec<Vec<u32>> = (0..self.n_cols()).map(|_| Vec::new()).collect();
|
||||||
let mut out: Vec<Vec<u32>> = Vec::with_capacity(n_cols);
|
self.fill_sub_matrix(slots, &mut out);
|
||||||
for c in 0..n_cols {
|
|
||||||
let mut col_buf = vec![0u32; slots.len()];
|
|
||||||
self.col_view(c).fill_slots_values(slots, &mut col_buf);
|
|
||||||
out.push(col_buf);
|
|
||||||
}
|
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,10 +391,8 @@ impl PersistentCompactIntMatrix {
|
|||||||
let sorted_slots: Vec<usize> = perm.iter().map(|&i| slots[i]).collect();
|
let sorted_slots: Vec<usize> = perm.iter().map(|&i| slots[i]).collect();
|
||||||
for (c, col) in out.iter_mut().enumerate() {
|
for (c, col) in out.iter_mut().enumerate() {
|
||||||
col.resize(n, 0);
|
col.resize(n, 0);
|
||||||
let mut tmp = vec![0u32; n];
|
for (i, v) in self.col_view(c).enumerate_slots_values(&sorted_slots) {
|
||||||
self.col_view(c).fill_slots_values_sorted(&sorted_slots, &mut tmp);
|
col[perm[i]] = v;
|
||||||
for (i, &orig_idx) in perm.iter().enumerate() {
|
|
||||||
col[orig_idx] = tmp[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user