1 | 'use strict'
|
2 |
|
3 | function factory (type, config, load, typed) {
|
4 | const latex = require('../../utils/latex')
|
5 |
|
6 | const matrix = load(require('../../type/matrix/function/matrix'))
|
7 |
|
8 | const algorithm03 = load(require('../../type/matrix/utils/algorithm03'))
|
9 | const algorithm05 = load(require('../../type/matrix/utils/algorithm05'))
|
10 | const algorithm12 = load(require('../../type/matrix/utils/algorithm12'))
|
11 | const algorithm13 = load(require('../../type/matrix/utils/algorithm13'))
|
12 | const algorithm14 = load(require('../../type/matrix/utils/algorithm14'))
|
13 |
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | const or = typed('or', {
|
43 |
|
44 | 'number, number': function (x, y) {
|
45 | return !!(x || y)
|
46 | },
|
47 |
|
48 | 'Complex, Complex': function (x, y) {
|
49 | return (x.re !== 0 || x.im !== 0) || (y.re !== 0 || y.im !== 0)
|
50 | },
|
51 |
|
52 | 'BigNumber, BigNumber': function (x, y) {
|
53 | return (!x.isZero() && !x.isNaN()) || (!y.isZero() && !y.isNaN())
|
54 | },
|
55 |
|
56 | 'Unit, Unit': function (x, y) {
|
57 | return or(x.value || 0, y.value || 0)
|
58 | },
|
59 |
|
60 | 'SparseMatrix, SparseMatrix': function (x, y) {
|
61 | return algorithm05(x, y, or)
|
62 | },
|
63 |
|
64 | 'SparseMatrix, DenseMatrix': function (x, y) {
|
65 | return algorithm03(y, x, or, true)
|
66 | },
|
67 |
|
68 | 'DenseMatrix, SparseMatrix': function (x, y) {
|
69 | return algorithm03(x, y, or, false)
|
70 | },
|
71 |
|
72 | 'DenseMatrix, DenseMatrix': function (x, y) {
|
73 | return algorithm13(x, y, or)
|
74 | },
|
75 |
|
76 | 'Array, Array': function (x, y) {
|
77 |
|
78 | return or(matrix(x), matrix(y)).valueOf()
|
79 | },
|
80 |
|
81 | 'Array, Matrix': function (x, y) {
|
82 |
|
83 | return or(matrix(x), y)
|
84 | },
|
85 |
|
86 | 'Matrix, Array': function (x, y) {
|
87 |
|
88 | return or(x, matrix(y))
|
89 | },
|
90 |
|
91 | 'SparseMatrix, any': function (x, y) {
|
92 | return algorithm12(x, y, or, false)
|
93 | },
|
94 |
|
95 | 'DenseMatrix, any': function (x, y) {
|
96 | return algorithm14(x, y, or, false)
|
97 | },
|
98 |
|
99 | 'any, SparseMatrix': function (x, y) {
|
100 | return algorithm12(y, x, or, true)
|
101 | },
|
102 |
|
103 | 'any, DenseMatrix': function (x, y) {
|
104 | return algorithm14(y, x, or, true)
|
105 | },
|
106 |
|
107 | 'Array, any': function (x, y) {
|
108 |
|
109 | return algorithm14(matrix(x), y, or, false).valueOf()
|
110 | },
|
111 |
|
112 | 'any, Array': function (x, y) {
|
113 |
|
114 | return algorithm14(matrix(y), x, or, true).valueOf()
|
115 | }
|
116 | })
|
117 |
|
118 | or.toTex = {
|
119 | 2: `\\left(\${args[0]}${latex.operators['or']}\${args[1]}\\right)`
|
120 | }
|
121 |
|
122 | return or
|
123 | }
|
124 |
|
125 | exports.name = 'or'
|
126 | exports.factory = factory
|