csCumsum.js (769B)
1 "use strict"; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 exports.csCumsum = csCumsum; 7 8 /** 9 * It sets the p[i] equal to the sum of c[0] through c[i-1]. 10 * 11 * @param {Array} ptr The Sparse Matrix ptr array 12 * @param {Array} c The Sparse Matrix ptr array 13 * @param {Number} n The number of columns 14 * 15 * Reference: http://faculty.cse.tamu.edu/davis/publications.html 16 */ 17 function csCumsum(ptr, c, n) { 18 // variables 19 var i; 20 var nz = 0; 21 22 for (i = 0; i < n; i++) { 23 // initialize ptr @ i 24 ptr[i] = nz; // increment number of nonzeros 25 26 nz += c[i]; // also copy p[0..n-1] back into c[0..n-1] 27 28 c[i] = ptr[i]; 29 } // finalize ptr 30 31 32 ptr[n] = nz; // return sum (c [0..n-1]) 33 34 return nz; 35 }