1 | import { factory } from '../../utils/factory.js';
|
2 | import { DimensionError } from '../../error/DimensionError.js';
|
3 | import { createAlgorithm01 } from '../../type/matrix/utils/algorithm01.js';
|
4 | import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03.js';
|
5 | import { createAlgorithm05 } from '../../type/matrix/utils/algorithm05.js';
|
6 | import { createAlgorithm10 } from '../../type/matrix/utils/algorithm10.js';
|
7 | import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js';
|
8 | import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
|
9 | var name = 'subtract';
|
10 | var dependencies = ['typed', 'matrix', 'equalScalar', 'addScalar', 'unaryMinus', 'DenseMatrix'];
|
11 | export var createSubtract = factory(name, dependencies, (_ref) => {
|
12 | var {
|
13 | typed,
|
14 | matrix,
|
15 | equalScalar,
|
16 | addScalar,
|
17 | unaryMinus,
|
18 | DenseMatrix
|
19 | } = _ref;
|
20 |
|
21 | var algorithm01 = createAlgorithm01({
|
22 | typed
|
23 | });
|
24 | var algorithm03 = createAlgorithm03({
|
25 | typed
|
26 | });
|
27 | var algorithm05 = createAlgorithm05({
|
28 | typed,
|
29 | equalScalar
|
30 | });
|
31 | var algorithm10 = createAlgorithm10({
|
32 | typed,
|
33 | DenseMatrix
|
34 | });
|
35 | var algorithm13 = createAlgorithm13({
|
36 | typed
|
37 | });
|
38 | var algorithm14 = createAlgorithm14({
|
39 | typed
|
40 | });
|
41 | |
42 |
|
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 | return typed(name, {
|
76 | 'number, number': function numberNumber(x, y) {
|
77 | return x - y;
|
78 | },
|
79 | 'Complex, Complex': function ComplexComplex(x, y) {
|
80 | return x.sub(y);
|
81 | },
|
82 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
83 | return x.minus(y);
|
84 | },
|
85 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
86 | return x.sub(y);
|
87 | },
|
88 | 'Unit, Unit': function UnitUnit(x, y) {
|
89 | if (x.value === null) {
|
90 | throw new Error('Parameter x contains a unit with undefined value');
|
91 | }
|
92 |
|
93 | if (y.value === null) {
|
94 | throw new Error('Parameter y contains a unit with undefined value');
|
95 | }
|
96 |
|
97 | if (!x.equalBase(y)) {
|
98 | throw new Error('Units do not match');
|
99 | }
|
100 |
|
101 | var res = x.clone();
|
102 | res.value = this(res.value, y.value);
|
103 | res.fixPrefix = false;
|
104 | return res;
|
105 | },
|
106 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
107 | checkEqualDimensions(x, y);
|
108 | return algorithm05(x, y, this);
|
109 | },
|
110 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
111 | checkEqualDimensions(x, y);
|
112 | return algorithm03(y, x, this, true);
|
113 | },
|
114 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
115 | checkEqualDimensions(x, y);
|
116 | return algorithm01(x, y, this, false);
|
117 | },
|
118 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
119 | checkEqualDimensions(x, y);
|
120 | return algorithm13(x, y, this);
|
121 | },
|
122 | 'Array, Array': function ArrayArray(x, y) {
|
123 |
|
124 | return this(matrix(x), matrix(y)).valueOf();
|
125 | },
|
126 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
127 |
|
128 | return this(matrix(x), y);
|
129 | },
|
130 | 'Matrix, Array': function MatrixArray(x, y) {
|
131 |
|
132 | return this(x, matrix(y));
|
133 | },
|
134 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
135 | return algorithm10(x, unaryMinus(y), addScalar);
|
136 | },
|
137 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
138 | return algorithm14(x, y, this);
|
139 | },
|
140 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
141 | return algorithm10(y, x, this, true);
|
142 | },
|
143 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
144 | return algorithm14(y, x, this, true);
|
145 | },
|
146 | 'Array, any': function ArrayAny(x, y) {
|
147 |
|
148 | return algorithm14(matrix(x), y, this, false).valueOf();
|
149 | },
|
150 | 'any, Array': function anyArray(x, y) {
|
151 |
|
152 | return algorithm14(matrix(y), x, this, true).valueOf();
|
153 | }
|
154 | });
|
155 | });
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | function checkEqualDimensions(x, y) {
|
164 | var xsize = x.size();
|
165 | var ysize = y.size();
|
166 |
|
167 | if (xsize.length !== ysize.length) {
|
168 | throw new DimensionError(xsize.length, ysize.length);
|
169 | }
|
170 | } |
\ | No newline at end of file |