UNPKG

1.61 kBJavaScriptView Raw
1'use strict'
2
3module.exports = function scatter (a, j, w, x, u, mark, c, f, inverse, update, value) {
4 // a arrays
5 const avalues = a._values
6 const aindex = a._index
7 const aptr = a._ptr
8 // c arrays
9 const cindex = c._index
10
11 // vars
12 let k, k0, k1, i
13
14 // check we need to process values (pattern matrix)
15 if (x) {
16 // values in j
17 for (k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
18 // row
19 i = aindex[k]
20 // check value exists in current j
21 if (w[i] !== mark) {
22 // i is new entry in j
23 w[i] = mark
24 // add i to pattern of C
25 cindex.push(i)
26 // x(i) = A, check we need to call function this time
27 if (update) {
28 // copy value to workspace calling callback function
29 x[i] = inverse ? f(avalues[k], value) : f(value, avalues[k])
30 // function was called on current row
31 u[i] = mark
32 } else {
33 // copy value to workspace
34 x[i] = avalues[k]
35 }
36 } else {
37 // i exists in C already
38 x[i] = inverse ? f(avalues[k], x[i]) : f(x[i], avalues[k])
39 // function was called on current row
40 u[i] = mark
41 }
42 }
43 } else {
44 // values in j
45 for (k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
46 // row
47 i = aindex[k]
48 // check value exists in current j
49 if (w[i] !== mark) {
50 // i is new entry in j
51 w[i] = mark
52 // add i to pattern of C
53 cindex.push(i)
54 } else {
55 // indicate function was called on current row
56 u[i] = mark
57 }
58 }
59 }
60}