nalgebra/src/sparse/cs_utils.rs

17 lines
356 B
Rust
Raw Normal View History

2018-11-07 01:31:04 +08:00
use allocator::Allocator;
use {DefaultAllocator, Dim, VectorN};
pub fn cumsum<D: Dim>(a: &mut VectorN<usize, D>, b: &mut VectorN<usize, D>) -> usize
2018-11-07 01:32:20 +08:00
where DefaultAllocator: Allocator<usize, D> {
2018-11-07 01:31:04 +08:00
assert!(a.len() == b.len());
let mut sum = 0;
for i in 0..a.len() {
b[i] = sum;
sum += a[i];
a[i] = b[i];
}
sum
}