UNPKG

3.98 kBJavaScriptView Raw
1import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03';
2import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12';
3import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13';
4import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14';
5import { createAlgorithm05 } from '../../type/matrix/utils/algorithm05';
6import { factory } from '../../utils/factory';
7import { orNumber } from '../../plain/number';
8var name = 'or';
9var dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix'];
10export var createOr =
11/* #__PURE__ */
12factory(name, dependencies, function (_ref) {
13 var typed = _ref.typed,
14 matrix = _ref.matrix,
15 equalScalar = _ref.equalScalar,
16 DenseMatrix = _ref.DenseMatrix;
17 var algorithm03 = createAlgorithm03({
18 typed: typed
19 });
20 var algorithm05 = createAlgorithm05({
21 typed: typed,
22 equalScalar: equalScalar
23 });
24 var algorithm12 = createAlgorithm12({
25 typed: typed,
26 DenseMatrix: DenseMatrix
27 });
28 var algorithm13 = createAlgorithm13({
29 typed: typed
30 });
31 var algorithm14 = createAlgorithm14({
32 typed: typed
33 });
34 /**
35 * Logical `or`. Test if at least one value is defined with a nonzero/nonempty value.
36 * For matrices, the function is evaluated element wise.
37 *
38 * Syntax:
39 *
40 * math.or(x, y)
41 *
42 * Examples:
43 *
44 * math.or(2, 4) // returns true
45 *
46 * a = [2, 5, 0]
47 * b = [0, 22, 0]
48 * c = 0
49 *
50 * math.or(a, b) // returns [true, true, false]
51 * math.or(b, c) // returns [false, true, false]
52 *
53 * See also:
54 *
55 * and, not, xor
56 *
57 * @param {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
58 * @param {number | BigNumber | Complex | Unit | Array | Matrix} y Second value to check
59 * @return {boolean | Array | Matrix}
60 * Returns true when one of the inputs is defined with a nonzero/nonempty value.
61 */
62
63 var or = typed(name, {
64 'number, number': orNumber,
65 'Complex, Complex': function ComplexComplex(x, y) {
66 return x.re !== 0 || x.im !== 0 || y.re !== 0 || y.im !== 0;
67 },
68 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
69 return !x.isZero() && !x.isNaN() || !y.isZero() && !y.isNaN();
70 },
71 'Unit, Unit': function UnitUnit(x, y) {
72 return or(x.value || 0, y.value || 0);
73 },
74 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
75 return algorithm05(x, y, or);
76 },
77 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
78 return algorithm03(y, x, or, true);
79 },
80 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
81 return algorithm03(x, y, or, false);
82 },
83 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
84 return algorithm13(x, y, or);
85 },
86 'Array, Array': function ArrayArray(x, y) {
87 // use matrix implementation
88 return or(matrix(x), matrix(y)).valueOf();
89 },
90 'Array, Matrix': function ArrayMatrix(x, y) {
91 // use matrix implementation
92 return or(matrix(x), y);
93 },
94 'Matrix, Array': function MatrixArray(x, y) {
95 // use matrix implementation
96 return or(x, matrix(y));
97 },
98 'SparseMatrix, any': function SparseMatrixAny(x, y) {
99 return algorithm12(x, y, or, false);
100 },
101 'DenseMatrix, any': function DenseMatrixAny(x, y) {
102 return algorithm14(x, y, or, false);
103 },
104 'any, SparseMatrix': function anySparseMatrix(x, y) {
105 return algorithm12(y, x, or, true);
106 },
107 'any, DenseMatrix': function anyDenseMatrix(x, y) {
108 return algorithm14(y, x, or, true);
109 },
110 'Array, any': function ArrayAny(x, y) {
111 // use matrix implementation
112 return algorithm14(matrix(x), y, or, false).valueOf();
113 },
114 'any, Array': function anyArray(x, y) {
115 // use matrix implementation
116 return algorithm14(matrix(y), x, or, true).valueOf();
117 }
118 });
119 return or;
120});
\No newline at end of file