1 | import { factory } from '../../utils/factory.js';
|
2 | import { createAlgorithm02 } from '../../type/matrix/utils/algorithm02.js';
|
3 | import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03.js';
|
4 | import { createAlgorithm05 } from '../../type/matrix/utils/algorithm05.js';
|
5 | import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11.js';
|
6 | import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12.js';
|
7 | import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js';
|
8 | import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
|
9 | import { modNumber } from '../../plain/number/index.js';
|
10 | var name = 'mod';
|
11 | var dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix'];
|
12 | export var createMod = factory(name, dependencies, (_ref) => {
|
13 | var {
|
14 | typed,
|
15 | matrix,
|
16 | equalScalar,
|
17 | DenseMatrix
|
18 | } = _ref;
|
19 | var algorithm02 = createAlgorithm02({
|
20 | typed,
|
21 | equalScalar
|
22 | });
|
23 | var algorithm03 = createAlgorithm03({
|
24 | typed
|
25 | });
|
26 | var algorithm05 = createAlgorithm05({
|
27 | typed,
|
28 | equalScalar
|
29 | });
|
30 | var algorithm11 = createAlgorithm11({
|
31 | typed,
|
32 | equalScalar
|
33 | });
|
34 | var algorithm12 = createAlgorithm12({
|
35 | typed,
|
36 | DenseMatrix
|
37 | });
|
38 | var algorithm13 = createAlgorithm13({
|
39 | typed
|
40 | });
|
41 | var algorithm14 = createAlgorithm14({
|
42 | typed
|
43 | });
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | return typed(name, {
|
81 | 'number, number': modNumber,
|
82 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
83 | if (y.isNeg()) {
|
84 | throw new Error('Cannot calculate mod for a negative divisor');
|
85 | }
|
86 |
|
87 | return y.isZero() ? x : x.mod(y);
|
88 | },
|
89 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
90 | if (y.compare(0) < 0) {
|
91 | throw new Error('Cannot calculate mod for a negative divisor');
|
92 | }
|
93 |
|
94 |
|
95 | return x.compare(0) >= 0 ? x.mod(y) : x.mod(y).add(y).mod(y);
|
96 | },
|
97 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
98 | return algorithm05(x, y, this, false);
|
99 | },
|
100 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
101 | return algorithm02(y, x, this, true);
|
102 | },
|
103 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
104 | return algorithm03(x, y, this, false);
|
105 | },
|
106 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
107 | return algorithm13(x, y, this);
|
108 | },
|
109 | 'Array, Array': function ArrayArray(x, y) {
|
110 |
|
111 | return this(matrix(x), matrix(y)).valueOf();
|
112 | },
|
113 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
114 |
|
115 | return this(matrix(x), y);
|
116 | },
|
117 | 'Matrix, Array': function MatrixArray(x, y) {
|
118 |
|
119 | return this(x, matrix(y));
|
120 | },
|
121 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
122 | return algorithm11(x, y, this, false);
|
123 | },
|
124 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
125 | return algorithm14(x, y, this, false);
|
126 | },
|
127 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
128 | return algorithm12(y, x, this, true);
|
129 | },
|
130 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
131 | return algorithm14(y, x, this, true);
|
132 | },
|
133 | 'Array, any': function ArrayAny(x, y) {
|
134 |
|
135 | return algorithm14(matrix(x), y, this, false).valueOf();
|
136 | },
|
137 | 'any, Array': function anyArray(x, y) {
|
138 |
|
139 | return algorithm14(matrix(y), x, this, true).valueOf();
|
140 | }
|
141 | });
|
142 | }); |
\ | No newline at end of file |