1 | import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual'
|
2 | import { nearlyEqual } from '../../utils/number'
|
3 | import { factory } from '../../utils/factory'
|
4 | import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03'
|
5 | import { createAlgorithm07 } from '../../type/matrix/utils/algorithm07'
|
6 | import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12'
|
7 | import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14'
|
8 | import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13'
|
9 |
|
10 | const name = 'larger'
|
11 | const dependencies = [
|
12 | 'typed',
|
13 | 'config',
|
14 | 'matrix',
|
15 | 'DenseMatrix'
|
16 | ]
|
17 |
|
18 | export const createLarger = factory(name, dependencies, ({ typed, config, matrix, DenseMatrix }) => {
|
19 | const algorithm03 = createAlgorithm03({ typed })
|
20 | const algorithm07 = createAlgorithm07({ typed, DenseMatrix })
|
21 | const algorithm12 = createAlgorithm12({ typed, DenseMatrix })
|
22 | const algorithm13 = createAlgorithm13({ typed })
|
23 | const algorithm14 = createAlgorithm14({ typed })
|
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 | const larger = typed(name, {
|
57 |
|
58 | 'boolean, boolean': function (x, y) {
|
59 | return x > y
|
60 | },
|
61 |
|
62 | 'number, number': function (x, y) {
|
63 | return x > y && !nearlyEqual(x, y, config.epsilon)
|
64 | },
|
65 |
|
66 | 'BigNumber, BigNumber': function (x, y) {
|
67 | return x.gt(y) && !bigNearlyEqual(x, y, config.epsilon)
|
68 | },
|
69 |
|
70 | 'Fraction, Fraction': function (x, y) {
|
71 | return x.compare(y) === 1
|
72 | },
|
73 |
|
74 | 'Complex, Complex': function () {
|
75 | throw new TypeError('No ordering relation is defined for complex numbers')
|
76 | },
|
77 |
|
78 | 'Unit, Unit': function (x, y) {
|
79 | if (!x.equalBase(y)) {
|
80 | throw new Error('Cannot compare units with different base')
|
81 | }
|
82 | return larger(x.value, y.value)
|
83 | },
|
84 |
|
85 | 'SparseMatrix, SparseMatrix': function (x, y) {
|
86 | return algorithm07(x, y, larger)
|
87 | },
|
88 |
|
89 | 'SparseMatrix, DenseMatrix': function (x, y) {
|
90 | return algorithm03(y, x, larger, true)
|
91 | },
|
92 |
|
93 | 'DenseMatrix, SparseMatrix': function (x, y) {
|
94 | return algorithm03(x, y, larger, false)
|
95 | },
|
96 |
|
97 | 'DenseMatrix, DenseMatrix': function (x, y) {
|
98 | return algorithm13(x, y, larger)
|
99 | },
|
100 |
|
101 | 'Array, Array': function (x, y) {
|
102 |
|
103 | return larger(matrix(x), matrix(y)).valueOf()
|
104 | },
|
105 |
|
106 | 'Array, Matrix': function (x, y) {
|
107 |
|
108 | return larger(matrix(x), y)
|
109 | },
|
110 |
|
111 | 'Matrix, Array': function (x, y) {
|
112 |
|
113 | return larger(x, matrix(y))
|
114 | },
|
115 |
|
116 | 'SparseMatrix, any': function (x, y) {
|
117 | return algorithm12(x, y, larger, false)
|
118 | },
|
119 |
|
120 | 'DenseMatrix, any': function (x, y) {
|
121 | return algorithm14(x, y, larger, false)
|
122 | },
|
123 |
|
124 | 'any, SparseMatrix': function (x, y) {
|
125 | return algorithm12(y, x, larger, true)
|
126 | },
|
127 |
|
128 | 'any, DenseMatrix': function (x, y) {
|
129 | return algorithm14(y, x, larger, true)
|
130 | },
|
131 |
|
132 | 'Array, any': function (x, y) {
|
133 |
|
134 | return algorithm14(matrix(x), y, larger, false).valueOf()
|
135 | },
|
136 |
|
137 | 'any, Array': function (x, y) {
|
138 |
|
139 | return algorithm14(matrix(y), x, larger, true).valueOf()
|
140 | }
|
141 | })
|
142 |
|
143 | return larger
|
144 | })
|
145 |
|
146 | export const createLargerNumber = factory(name, ['typed', 'config'], ({ typed, config }) => {
|
147 | return typed(name, {
|
148 | 'number, number': function (x, y) {
|
149 | return x > y && !nearlyEqual(x, y, config.epsilon)
|
150 | }
|
151 | })
|
152 | })
|