1 | import { factory } from '../../utils/factory'
|
2 | import { createAlgorithm02 } from '../../type/matrix/utils/algorithm02'
|
3 | import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03'
|
4 | import { createAlgorithm05 } from '../../type/matrix/utils/algorithm05'
|
5 | import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11'
|
6 | import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12'
|
7 | import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13'
|
8 | import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14'
|
9 | import { modNumber } from '../../plain/number'
|
10 |
|
11 | const name = 'mod'
|
12 | const dependencies = [
|
13 | 'typed',
|
14 | 'matrix',
|
15 | 'equalScalar',
|
16 | 'DenseMatrix'
|
17 | ]
|
18 |
|
19 | export const createMod = factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix }) => {
|
20 | const algorithm02 = createAlgorithm02({ typed, equalScalar })
|
21 | const algorithm03 = createAlgorithm03({ typed })
|
22 | const algorithm05 = createAlgorithm05({ typed, equalScalar })
|
23 | const algorithm11 = createAlgorithm11({ typed, equalScalar })
|
24 | const algorithm12 = createAlgorithm12({ typed, DenseMatrix })
|
25 | const algorithm13 = createAlgorithm13({ typed })
|
26 | const algorithm14 = createAlgorithm14({ typed })
|
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 | const mod = typed(name, {
|
64 |
|
65 | 'number, number': modNumber,
|
66 |
|
67 | 'BigNumber, BigNumber': function (x, y) {
|
68 | return y.isZero() ? x : x.mod(y)
|
69 | },
|
70 |
|
71 | 'Fraction, Fraction': function (x, y) {
|
72 | return x.mod(y)
|
73 | },
|
74 |
|
75 | 'SparseMatrix, SparseMatrix': function (x, y) {
|
76 | return algorithm05(x, y, mod, false)
|
77 | },
|
78 |
|
79 | 'SparseMatrix, DenseMatrix': function (x, y) {
|
80 | return algorithm02(y, x, mod, true)
|
81 | },
|
82 |
|
83 | 'DenseMatrix, SparseMatrix': function (x, y) {
|
84 | return algorithm03(x, y, mod, false)
|
85 | },
|
86 |
|
87 | 'DenseMatrix, DenseMatrix': function (x, y) {
|
88 | return algorithm13(x, y, mod)
|
89 | },
|
90 |
|
91 | 'Array, Array': function (x, y) {
|
92 |
|
93 | return mod(matrix(x), matrix(y)).valueOf()
|
94 | },
|
95 |
|
96 | 'Array, Matrix': function (x, y) {
|
97 |
|
98 | return mod(matrix(x), y)
|
99 | },
|
100 |
|
101 | 'Matrix, Array': function (x, y) {
|
102 |
|
103 | return mod(x, matrix(y))
|
104 | },
|
105 |
|
106 | 'SparseMatrix, any': function (x, y) {
|
107 | return algorithm11(x, y, mod, false)
|
108 | },
|
109 |
|
110 | 'DenseMatrix, any': function (x, y) {
|
111 | return algorithm14(x, y, mod, false)
|
112 | },
|
113 |
|
114 | 'any, SparseMatrix': function (x, y) {
|
115 | return algorithm12(y, x, mod, true)
|
116 | },
|
117 |
|
118 | 'any, DenseMatrix': function (x, y) {
|
119 | return algorithm14(y, x, mod, true)
|
120 | },
|
121 |
|
122 | 'Array, any': function (x, y) {
|
123 |
|
124 | return algorithm14(matrix(x), y, mod, false).valueOf()
|
125 | },
|
126 |
|
127 | 'any, Array': function (x, y) {
|
128 |
|
129 | return algorithm14(matrix(y), x, mod, true).valueOf()
|
130 | }
|
131 | })
|
132 |
|
133 | return mod
|
134 | })
|