UNPKG

668 BJavaScriptView Raw
1/**
2 * It sets the p[i] equal to the sum of c[0] through c[i-1].
3 *
4 * @param {Array} ptr The Sparse Matrix ptr array
5 * @param {Array} c The Sparse Matrix ptr array
6 * @param {Number} n The number of columns
7 *
8 * Reference: http://faculty.cse.tamu.edu/davis/publications.html
9 */
10export function csCumsum (ptr, c, n) {
11 // variables
12 let i
13 let nz = 0
14
15 for (i = 0; i < n; i++) {
16 // initialize ptr @ i
17 ptr[i] = nz
18 // increment number of nonzeros
19 nz += c[i]
20 // also copy p[0..n-1] back into c[0..n-1]
21 c[i] = ptr[i]
22 }
23 // finalize ptr
24 ptr[n] = nz
25 // return sum (c [0..n-1])
26 return nz
27}