MCPcopy Index your code
hub / github.com/josdejong/mathjs / csFkeep

Function csFkeep

src/function/algebra/sparse/csFkeep.js:18–54  ·  view source on GitHub ↗
(a, callback, other)

Source from the content-addressed store, hash-verified

16 * @return The number of nonzero elements in the matrix
17 */
18export function csFkeep (a, callback, other) {
19 // a arrays
20 const avalues = a._values
21 const aindex = a._index
22 const aptr = a._ptr
23 const asize = a._size
24 // columns
25 const n = asize[1]
26 // nonzero items
27 let nz = 0
28 // loop columns
29 for (let j = 0; j < n; j++) {
30 // get current location of col j
31 let p = aptr[j]
32 // record new location of col j
33 aptr[j] = nz
34 for (; p < aptr[j + 1]; p++) {
35 // check we need to keep this item
36 if (callback(aindex[p], j, avalues ? avalues[p] : 1, other)) {
37 // keep A(i,j)
38 aindex[nz] = aindex[p]
39 // check we need to process values (pattern only)
40 if (avalues) { avalues[nz] = avalues[p] }
41 // increment nonzero items
42 nz++
43 }
44 }
45 }
46 // finalize A
47 aptr[n] = nz
48 // trim arrays
49 aindex.splice(nz, aindex.length - nz)
50 // check we need to process values (pattern only)
51 if (avalues) { avalues.splice(nz, avalues.length - nz) }
52 // return number of nonzero items
53 return nz
54}

Callers 1

csAmd.jsFile · 0.90

Calls 1

callbackFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…