UNPKG

5.88 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createUnequalNumber = exports.createUnequal = void 0;
7
8var _factory = require("../../utils/factory");
9
10var _algorithm = require("../../type/matrix/utils/algorithm03");
11
12var _algorithm2 = require("../../type/matrix/utils/algorithm07");
13
14var _algorithm3 = require("../../type/matrix/utils/algorithm12");
15
16var _algorithm4 = require("../../type/matrix/utils/algorithm14");
17
18var _algorithm5 = require("../../type/matrix/utils/algorithm13");
19
20var name = 'unequal';
21var dependencies = ['typed', 'config', 'equalScalar', 'matrix', 'DenseMatrix'];
22var createUnequal = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
23 var typed = _ref.typed,
24 config = _ref.config,
25 equalScalar = _ref.equalScalar,
26 matrix = _ref.matrix,
27 DenseMatrix = _ref.DenseMatrix;
28 var algorithm03 = (0, _algorithm.createAlgorithm03)({
29 typed: typed
30 });
31 var algorithm07 = (0, _algorithm2.createAlgorithm07)({
32 typed: typed,
33 DenseMatrix: DenseMatrix
34 });
35 var algorithm12 = (0, _algorithm3.createAlgorithm12)({
36 typed: typed,
37 DenseMatrix: DenseMatrix
38 });
39 var algorithm13 = (0, _algorithm5.createAlgorithm13)({
40 typed: typed
41 });
42 var algorithm14 = (0, _algorithm4.createAlgorithm14)({
43 typed: typed
44 });
45 /**
46 * Test whether two values are unequal.
47 *
48 * The function tests whether the relative difference between x and y is
49 * larger than the configured epsilon. The function cannot be used to compare
50 * values smaller than approximately 2.22e-16.
51 *
52 * For matrices, the function is evaluated element wise.
53 * In case of complex numbers, x.re must unequal y.re, or x.im must unequal y.im.
54 * Strings are compared by their numerical value.
55 *
56 * Values `null` and `undefined` are compared strictly, thus `null` is unequal
57 * with everything except `null`, and `undefined` is unequal with everything
58 * except `undefined`.
59 *
60 * Syntax:
61 *
62 * math.unequal(x, y)
63 *
64 * Examples:
65 *
66 * math.unequal(2 + 2, 3) // returns true
67 * math.unequal(2 + 2, 4) // returns false
68 *
69 * const a = math.unit('50 cm')
70 * const b = math.unit('5 m')
71 * math.unequal(a, b) // returns false
72 *
73 * const c = [2, 5, 1]
74 * const d = [2, 7, 1]
75 *
76 * math.unequal(c, d) // returns [false, true, false]
77 * math.deepEqual(c, d) // returns false
78 *
79 * math.unequal(0, null) // returns true
80 * See also:
81 *
82 * equal, deepEqual, smaller, smallerEq, larger, largerEq, compare
83 *
84 * @param {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} x First value to compare
85 * @param {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} y Second value to compare
86 * @return {boolean | Array | Matrix} Returns true when the compared values are unequal, else returns false
87 */
88
89 var unequal = typed('unequal', {
90 'any, any': function anyAny(x, y) {
91 // strict equality for null and undefined?
92 if (x === null) {
93 return y !== null;
94 }
95
96 if (y === null) {
97 return x !== null;
98 }
99
100 if (x === undefined) {
101 return y !== undefined;
102 }
103
104 if (y === undefined) {
105 return x !== undefined;
106 }
107
108 return _unequal(x, y);
109 },
110 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
111 return algorithm07(x, y, _unequal);
112 },
113 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
114 return algorithm03(y, x, _unequal, true);
115 },
116 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
117 return algorithm03(x, y, _unequal, false);
118 },
119 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
120 return algorithm13(x, y, _unequal);
121 },
122 'Array, Array': function ArrayArray(x, y) {
123 // use matrix implementation
124 return unequal(matrix(x), matrix(y)).valueOf();
125 },
126 'Array, Matrix': function ArrayMatrix(x, y) {
127 // use matrix implementation
128 return unequal(matrix(x), y);
129 },
130 'Matrix, Array': function MatrixArray(x, y) {
131 // use matrix implementation
132 return unequal(x, matrix(y));
133 },
134 'SparseMatrix, any': function SparseMatrixAny(x, y) {
135 return algorithm12(x, y, _unequal, false);
136 },
137 'DenseMatrix, any': function DenseMatrixAny(x, y) {
138 return algorithm14(x, y, _unequal, false);
139 },
140 'any, SparseMatrix': function anySparseMatrix(x, y) {
141 return algorithm12(y, x, _unequal, true);
142 },
143 'any, DenseMatrix': function anyDenseMatrix(x, y) {
144 return algorithm14(y, x, _unequal, true);
145 },
146 'Array, any': function ArrayAny(x, y) {
147 // use matrix implementation
148 return algorithm14(matrix(x), y, _unequal, false).valueOf();
149 },
150 'any, Array': function anyArray(x, y) {
151 // use matrix implementation
152 return algorithm14(matrix(y), x, _unequal, true).valueOf();
153 }
154 });
155
156 function _unequal(x, y) {
157 return !equalScalar(x, y);
158 }
159
160 return unequal;
161});
162exports.createUnequal = createUnequal;
163var createUnequalNumber = (0, _factory.factory)(name, ['typed', 'equalScalar'], function (_ref2) {
164 var typed = _ref2.typed,
165 equalScalar = _ref2.equalScalar;
166 return typed(name, {
167 'any, any': function anyAny(x, y) {
168 // strict equality for null and undefined?
169 if (x === null) {
170 return y !== null;
171 }
172
173 if (y === null) {
174 return x !== null;
175 }
176
177 if (x === undefined) {
178 return y !== undefined;
179 }
180
181 if (y === undefined) {
182 return x !== undefined;
183 }
184
185 return !equalScalar(x, y);
186 }
187 });
188});
189exports.createUnequalNumber = createUnequalNumber;
\No newline at end of file