1 | import { factory } from '../../utils/factory'
|
2 | import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03'
|
3 | import { createAlgorithm07 } from '../../type/matrix/utils/algorithm07'
|
4 | import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12'
|
5 | import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14'
|
6 | import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13'
|
7 |
|
8 | const name = 'unequal'
|
9 | const dependencies = [
|
10 | 'typed',
|
11 | 'config',
|
12 | 'equalScalar',
|
13 | 'matrix',
|
14 | 'DenseMatrix'
|
15 | ]
|
16 |
|
17 | export const createUnequal = factory(name, dependencies, ({ typed, config, equalScalar, matrix, DenseMatrix }) => {
|
18 | const algorithm03 = createAlgorithm03({ typed })
|
19 | const algorithm07 = createAlgorithm07({ typed, DenseMatrix })
|
20 | const algorithm12 = createAlgorithm12({ typed, DenseMatrix })
|
21 | const algorithm13 = createAlgorithm13({ typed })
|
22 | const algorithm14 = createAlgorithm14({ typed })
|
23 |
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | const unequal = typed('unequal', {
|
68 |
|
69 | 'any, any': function (x, y) {
|
70 |
|
71 | if (x === null) { return y !== null }
|
72 | if (y === null) { return x !== null }
|
73 | if (x === undefined) { return y !== undefined }
|
74 | if (y === undefined) { return x !== undefined }
|
75 |
|
76 | return _unequal(x, y)
|
77 | },
|
78 |
|
79 | 'SparseMatrix, SparseMatrix': function (x, y) {
|
80 | return algorithm07(x, y, _unequal)
|
81 | },
|
82 |
|
83 | 'SparseMatrix, DenseMatrix': function (x, y) {
|
84 | return algorithm03(y, x, _unequal, true)
|
85 | },
|
86 |
|
87 | 'DenseMatrix, SparseMatrix': function (x, y) {
|
88 | return algorithm03(x, y, _unequal, false)
|
89 | },
|
90 |
|
91 | 'DenseMatrix, DenseMatrix': function (x, y) {
|
92 | return algorithm13(x, y, _unequal)
|
93 | },
|
94 |
|
95 | 'Array, Array': function (x, y) {
|
96 |
|
97 | return unequal(matrix(x), matrix(y)).valueOf()
|
98 | },
|
99 |
|
100 | 'Array, Matrix': function (x, y) {
|
101 |
|
102 | return unequal(matrix(x), y)
|
103 | },
|
104 |
|
105 | 'Matrix, Array': function (x, y) {
|
106 |
|
107 | return unequal(x, matrix(y))
|
108 | },
|
109 |
|
110 | 'SparseMatrix, any': function (x, y) {
|
111 | return algorithm12(x, y, _unequal, false)
|
112 | },
|
113 |
|
114 | 'DenseMatrix, any': function (x, y) {
|
115 | return algorithm14(x, y, _unequal, false)
|
116 | },
|
117 |
|
118 | 'any, SparseMatrix': function (x, y) {
|
119 | return algorithm12(y, x, _unequal, true)
|
120 | },
|
121 |
|
122 | 'any, DenseMatrix': function (x, y) {
|
123 | return algorithm14(y, x, _unequal, true)
|
124 | },
|
125 |
|
126 | 'Array, any': function (x, y) {
|
127 |
|
128 | return algorithm14(matrix(x), y, _unequal, false).valueOf()
|
129 | },
|
130 |
|
131 | 'any, Array': function (x, y) {
|
132 |
|
133 | return algorithm14(matrix(y), x, _unequal, true).valueOf()
|
134 | }
|
135 | })
|
136 |
|
137 | function _unequal (x, y) {
|
138 | return !equalScalar(x, y)
|
139 | }
|
140 |
|
141 | return unequal
|
142 | })
|
143 |
|
144 | export const createUnequalNumber = factory(name, ['typed', 'equalScalar'], ({ typed, equalScalar }) => {
|
145 | return typed(name, {
|
146 | 'any, any': function (x, y) {
|
147 |
|
148 | if (x === null) { return y !== null }
|
149 | if (y === null) { return x !== null }
|
150 | if (x === undefined) { return y !== undefined }
|
151 | if (y === undefined) { return x !== undefined }
|
152 |
|
153 | return !equalScalar(x, y)
|
154 | }
|
155 | })
|
156 | })
|