@danielsimonjr/mathts-compat 0.4.30 → 0.4.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +316 -561
- package/package.json +17 -6
package/dist/index.js
CHANGED
|
@@ -1,621 +1,376 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
LN2 as CORE_LN2,
|
|
13
|
-
LN10 as CORE_LN10,
|
|
14
|
-
LOG2E as CORE_LOG2E,
|
|
15
|
-
LOG10E as CORE_LOG10E,
|
|
16
|
-
SQRT2 as CORE_SQRT2,
|
|
17
|
-
SQRT1_2 as CORE_SQRT1_2
|
|
18
|
-
} from "@danielsimonjr/mathts-core";
|
|
19
|
-
import {
|
|
20
|
-
add as _add,
|
|
21
|
-
subtract as _subtract,
|
|
22
|
-
multiply as _multiply,
|
|
23
|
-
divide as _divide,
|
|
24
|
-
pow as _pow,
|
|
25
|
-
sqrt as _sqrt,
|
|
26
|
-
abs as _abs,
|
|
27
|
-
exp as _exp,
|
|
28
|
-
log as _log,
|
|
29
|
-
sin as _sin,
|
|
30
|
-
cos as _cos,
|
|
31
|
-
tan as _tan,
|
|
32
|
-
sum as _sum,
|
|
33
|
-
mean as _mean,
|
|
34
|
-
min as _min,
|
|
35
|
-
max as _max,
|
|
36
|
-
gcd as _gcd,
|
|
37
|
-
lcm as _lcm,
|
|
38
|
-
round as _round,
|
|
39
|
-
floor as _floor,
|
|
40
|
-
ceil as _ceil
|
|
41
|
-
} from "@danielsimonjr/mathts-functions";
|
|
42
|
-
import {
|
|
43
|
-
DenseMatrix,
|
|
44
|
-
SparseMatrix,
|
|
45
|
-
add as _matAdd,
|
|
46
|
-
subtract as _matSubtract,
|
|
47
|
-
multiply as _matMultiply
|
|
48
|
-
} from "@danielsimonjr/mathts-matrix";
|
|
49
|
-
function complex(re2, im2) {
|
|
50
|
-
if (re2 === void 0) {
|
|
51
|
-
return COMPLEX_ZERO;
|
|
52
|
-
}
|
|
53
|
-
if (re2 instanceof Complex) {
|
|
54
|
-
return re2;
|
|
55
|
-
}
|
|
56
|
-
if (typeof re2 === "string") {
|
|
57
|
-
return Complex.parse(re2);
|
|
58
|
-
}
|
|
59
|
-
return new Complex(re2, im2 ?? 0);
|
|
1
|
+
import { BIGNUMBER_E, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_ZERO, BigNumber, BigNumber as BigNumber$1, COMPLEX_ONE, COMPLEX_ZERO, COMPLEX_ZERO as COMPLEX_ZERO$1, Complex, Complex as Complex$1, FRACTION_ONE, FRACTION_ZERO, Fraction, Fraction as Fraction$1, I, I as I$1, LN10 as LN10$1, LN2 as LN2$1, LOG10E as LOG10E$1, LOG2E as LOG2E$1, SQRT1_2 as SQRT1_2$1, SQRT2 as SQRT2$1, isBigNumber, isComplex, isFraction, isNumber } from "@danielsimonjr/mathts-core";
|
|
2
|
+
import * as mathFunctions from "@danielsimonjr/mathts-functions";
|
|
3
|
+
import { abs as abs$1, add as add$1, ceil as ceil$1, cos as cos$1, divide as divide$1, exp as exp$1, floor as floor$1, gcd as gcd$1, lcm as lcm$1, log as log$1, max as max$1, mean as mean$1, min as min$1, multiply as multiply$1, pow as pow$1, round as round$1, sin as sin$1, sqrt as sqrt$1, subtract as subtract$1, sum as sum$1, tan as tan$1 } from "@danielsimonjr/mathts-functions";
|
|
4
|
+
import { DenseMatrix, DenseMatrix as DenseMatrix$1, SparseMatrix, SparseMatrix as SparseMatrix$1, add as add$2, multiply as multiply$2, subtract as subtract$2 } from "@danielsimonjr/mathts-matrix";
|
|
5
|
+
import { computePool } from "@danielsimonjr/mathts-parallel";
|
|
6
|
+
//#region src/shims.ts
|
|
7
|
+
function complex(re, im) {
|
|
8
|
+
if (re === void 0) return COMPLEX_ZERO$1;
|
|
9
|
+
if (re instanceof Complex$1) return re;
|
|
10
|
+
if (typeof re === "string") return Complex$1.parse(re);
|
|
11
|
+
return new Complex$1(re, im ?? 0);
|
|
60
12
|
}
|
|
61
13
|
function fraction(numerator, denominator) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
if (typeof numerator === "string") {
|
|
69
|
-
return Fraction.parse(numerator);
|
|
70
|
-
}
|
|
71
|
-
if (denominator !== void 0) {
|
|
72
|
-
return new Fraction(numerator, denominator);
|
|
73
|
-
}
|
|
74
|
-
return Fraction.fromNumber(numerator);
|
|
14
|
+
if (numerator === void 0) return new Fraction$1(0, 1);
|
|
15
|
+
if (numerator instanceof Fraction$1) return numerator;
|
|
16
|
+
if (typeof numerator === "string") return Fraction$1.parse(numerator);
|
|
17
|
+
if (denominator !== void 0) return new Fraction$1(numerator, denominator);
|
|
18
|
+
return Fraction$1.fromNumber(numerator);
|
|
75
19
|
}
|
|
76
20
|
function bignumber(value) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
if (typeof value === "string") {
|
|
84
|
-
return BigNumber.parse(value);
|
|
85
|
-
}
|
|
86
|
-
return BigNumber.fromNumber(value);
|
|
21
|
+
if (value === void 0) return BigNumber$1.fromNumber(0);
|
|
22
|
+
if (value instanceof BigNumber$1) return value;
|
|
23
|
+
if (typeof value === "string") return BigNumber$1.parse(value);
|
|
24
|
+
return BigNumber$1.fromNumber(value);
|
|
87
25
|
}
|
|
88
26
|
function matrix(data, format) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
const dense = DenseMatrix.fromArray(data);
|
|
96
|
-
if (format === "sparse") {
|
|
97
|
-
return SparseMatrix.fromDense(dense);
|
|
98
|
-
}
|
|
99
|
-
return dense;
|
|
27
|
+
if (data === void 0) return DenseMatrix$1.zeros(0, 0);
|
|
28
|
+
if (data instanceof DenseMatrix$1 || data instanceof SparseMatrix$1) return data;
|
|
29
|
+
const dense = DenseMatrix$1.fromArray(data);
|
|
30
|
+
if (format === "sparse") return SparseMatrix$1.fromDense(dense);
|
|
31
|
+
return dense;
|
|
100
32
|
}
|
|
101
33
|
function sparse(data) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
return SparseMatrix.fromDense(DenseMatrix.fromArray(data));
|
|
34
|
+
if (data === void 0) return SparseMatrix$1.zeros(0, 0);
|
|
35
|
+
return SparseMatrix$1.fromDense(DenseMatrix$1.fromArray(data));
|
|
106
36
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
37
|
+
const isMatrixLike = (x) => x instanceof DenseMatrix$1 || Array.isArray(x) && x.length > 0 && Array.isArray(x[0]);
|
|
38
|
+
const toDenseMatrix = (x) => x instanceof DenseMatrix$1 ? x : DenseMatrix$1.fromArray(x);
|
|
39
|
+
const unwrap = (r) => r instanceof DenseMatrix$1 ? r.toArray() : r;
|
|
40
|
+
const applyArithmetic = (scalarFn, matrixFn, a, b) => {
|
|
41
|
+
if (isMatrixLike(a) || isMatrixLike(b)) {
|
|
42
|
+
const aa = isMatrixLike(a) ? toDenseMatrix(a) : a;
|
|
43
|
+
const bb = isMatrixLike(b) ? toDenseMatrix(b) : b;
|
|
44
|
+
return unwrap(matrixFn(aa, bb));
|
|
45
|
+
}
|
|
46
|
+
return scalarFn(a, b);
|
|
117
47
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (args.length === 1) {
|
|
123
|
-
return args[0];
|
|
124
|
-
}
|
|
125
|
-
return args.reduce((acc, next) => applyArithmetic(scalarFn, matrixFn, acc, next));
|
|
48
|
+
const makeArithmetic = (scalarFn, matrixFn) => (...args) => {
|
|
49
|
+
if (args.length === 0) throw new TypeError("Too few arguments (expected at least 1)");
|
|
50
|
+
if (args.length === 1) return args[0];
|
|
51
|
+
return args.reduce((acc, next) => applyArithmetic(scalarFn, matrixFn, acc, next));
|
|
126
52
|
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
var divide = _divide;
|
|
140
|
-
var pow = _pow;
|
|
141
|
-
var sqrt = _sqrt;
|
|
142
|
-
var abs = _abs;
|
|
143
|
-
var exp = _exp;
|
|
144
|
-
var log = _log;
|
|
145
|
-
var sin = _sin;
|
|
146
|
-
var cos = _cos;
|
|
147
|
-
var tan = _tan;
|
|
53
|
+
const add = makeArithmetic(add$1, add$2);
|
|
54
|
+
const subtract = makeArithmetic(subtract$1, subtract$2);
|
|
55
|
+
const multiply = makeArithmetic(multiply$1, multiply$2);
|
|
56
|
+
const divide = divide$1;
|
|
57
|
+
const pow = pow$1;
|
|
58
|
+
const sqrt = sqrt$1;
|
|
59
|
+
const abs = abs$1;
|
|
60
|
+
const exp = exp$1;
|
|
61
|
+
const log = log$1;
|
|
62
|
+
const sin = sin$1;
|
|
63
|
+
const cos = cos$1;
|
|
64
|
+
const tan = tan$1;
|
|
148
65
|
function asin(x) {
|
|
149
|
-
|
|
66
|
+
return Math.asin(x);
|
|
150
67
|
}
|
|
151
68
|
function acos(x) {
|
|
152
|
-
|
|
69
|
+
return Math.acos(x);
|
|
153
70
|
}
|
|
154
71
|
function atan(x) {
|
|
155
|
-
|
|
72
|
+
return Math.atan(x);
|
|
156
73
|
}
|
|
157
74
|
function atan2(y, x) {
|
|
158
|
-
|
|
75
|
+
return Math.atan2(y, x);
|
|
159
76
|
}
|
|
160
|
-
|
|
161
|
-
|
|
77
|
+
const sum = sum$1;
|
|
78
|
+
const mean = mean$1;
|
|
162
79
|
function toNumericArray(data) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
80
|
+
if (data instanceof DenseMatrix$1) return data.toArray().flat(Infinity);
|
|
81
|
+
if (Array.isArray(data)) return data.flat(Infinity);
|
|
82
|
+
return [data];
|
|
166
83
|
}
|
|
167
84
|
function variance(data, normalization = "unbiased") {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const denom = normalization === "uncorrected" ? n : normalization === "biased" ? n + 1 : n > 1 ? n - 1 : n;
|
|
174
|
-
return ss / denom;
|
|
85
|
+
const arr = toNumericArray(data);
|
|
86
|
+
const n = arr.length;
|
|
87
|
+
if (n === 0) return NaN;
|
|
88
|
+
const mu = arr.reduce((s, x) => s + x, 0) / n;
|
|
89
|
+
return arr.reduce((s, x) => s + (x - mu) * (x - mu), 0) / (normalization === "uncorrected" ? n : normalization === "biased" ? n + 1 : n > 1 ? n - 1 : n);
|
|
175
90
|
}
|
|
176
91
|
function std(data, normalization = "unbiased") {
|
|
177
|
-
|
|
92
|
+
return Math.sqrt(variance(data, normalization));
|
|
178
93
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
94
|
+
const min = min$1;
|
|
95
|
+
const max = max$1;
|
|
96
|
+
const gcd = gcd$1;
|
|
97
|
+
const lcm = lcm$1;
|
|
98
|
+
const round = round$1;
|
|
99
|
+
const floor = floor$1;
|
|
100
|
+
const ceil = ceil$1;
|
|
186
101
|
function conj(c) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
return c.conjugate();
|
|
102
|
+
if (!isComplex(c)) throw new TypeError("Expected Complex number");
|
|
103
|
+
return c.conjugate();
|
|
191
104
|
}
|
|
192
105
|
function re(c) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
106
|
+
if (typeof c === "number") return c;
|
|
107
|
+
if (isComplex(c)) return c.re;
|
|
108
|
+
throw new TypeError("Expected Complex or number");
|
|
196
109
|
}
|
|
197
110
|
function im(c) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
111
|
+
if (typeof c === "number") return 0;
|
|
112
|
+
if (isComplex(c)) return c.im;
|
|
113
|
+
throw new TypeError("Expected Complex or number");
|
|
201
114
|
}
|
|
202
115
|
function arg(c) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
return c.arg();
|
|
116
|
+
if (!isComplex(c)) throw new TypeError("Expected Complex number");
|
|
117
|
+
return c.arg();
|
|
207
118
|
}
|
|
208
119
|
function transpose(m) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
return m.transpose();
|
|
120
|
+
if (Array.isArray(m)) return DenseMatrix$1.fromArray(m).transpose().toArray();
|
|
121
|
+
return m.transpose();
|
|
213
122
|
}
|
|
214
123
|
function det(m) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (maxRow !== k) {
|
|
255
|
-
[lu[k], lu[maxRow]] = [lu[maxRow], lu[k]];
|
|
256
|
-
swaps++;
|
|
257
|
-
}
|
|
258
|
-
for (let i2 = k + 1; i2 < n; i2++) {
|
|
259
|
-
lu[i2][k] /= lu[k][k];
|
|
260
|
-
for (let j = k + 1; j < n; j++) {
|
|
261
|
-
lu[i2][j] -= lu[i2][k] * lu[k][j];
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
let result = 1;
|
|
266
|
-
for (let i2 = 0; i2 < n; i2++) {
|
|
267
|
-
result *= lu[i2][i2];
|
|
268
|
-
}
|
|
269
|
-
return swaps % 2 === 0 ? result : -result;
|
|
124
|
+
const matrix = Array.isArray(m) ? DenseMatrix$1.fromArray(m) : m;
|
|
125
|
+
if (!(matrix instanceof DenseMatrix$1)) throw new TypeError("Expected DenseMatrix or 2D array");
|
|
126
|
+
if (matrix.rows !== matrix.cols) throw new Error("Determinant requires a square matrix");
|
|
127
|
+
const n = matrix.rows;
|
|
128
|
+
if (n === 0) return 1;
|
|
129
|
+
if (n === 1) return matrix.get(0, 0);
|
|
130
|
+
if (n === 2) return matrix.get(0, 0) * matrix.get(1, 1) - matrix.get(0, 1) * matrix.get(1, 0);
|
|
131
|
+
if (n === 3) {
|
|
132
|
+
const a = matrix.get(0, 0), b = matrix.get(0, 1), c = matrix.get(0, 2);
|
|
133
|
+
const d = matrix.get(1, 0), e = matrix.get(1, 1), f = matrix.get(1, 2);
|
|
134
|
+
const g = matrix.get(2, 0), h = matrix.get(2, 1), i = matrix.get(2, 2);
|
|
135
|
+
return a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
|
|
136
|
+
}
|
|
137
|
+
const lu = [];
|
|
138
|
+
for (let i = 0; i < n; i++) {
|
|
139
|
+
lu[i] = [];
|
|
140
|
+
for (let j = 0; j < n; j++) lu[i][j] = matrix.get(i, j);
|
|
141
|
+
}
|
|
142
|
+
let swaps = 0;
|
|
143
|
+
for (let k = 0; k < n - 1; k++) {
|
|
144
|
+
let maxVal = Math.abs(lu[k][k]);
|
|
145
|
+
let maxRow = k;
|
|
146
|
+
for (let i = k + 1; i < n; i++) if (Math.abs(lu[i][k]) > maxVal) {
|
|
147
|
+
maxVal = Math.abs(lu[i][k]);
|
|
148
|
+
maxRow = i;
|
|
149
|
+
}
|
|
150
|
+
if (maxVal < 1e-12) return 0;
|
|
151
|
+
if (maxRow !== k) {
|
|
152
|
+
[lu[k], lu[maxRow]] = [lu[maxRow], lu[k]];
|
|
153
|
+
swaps++;
|
|
154
|
+
}
|
|
155
|
+
for (let i = k + 1; i < n; i++) {
|
|
156
|
+
lu[i][k] /= lu[k][k];
|
|
157
|
+
for (let j = k + 1; j < n; j++) lu[i][j] -= lu[i][k] * lu[k][j];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
let result = 1;
|
|
161
|
+
for (let i = 0; i < n; i++) result *= lu[i][i];
|
|
162
|
+
return swaps % 2 === 0 ? result : -result;
|
|
270
163
|
}
|
|
271
164
|
function identity(n) {
|
|
272
|
-
|
|
165
|
+
return DenseMatrix$1.identity(n);
|
|
273
166
|
}
|
|
274
167
|
function zeros(rows, cols) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
return DenseMatrix.zeros(rows, cols);
|
|
168
|
+
if (cols === void 0) return new Array(rows).fill(0);
|
|
169
|
+
return DenseMatrix$1.zeros(rows, cols);
|
|
279
170
|
}
|
|
280
171
|
function ones(rows, cols) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
return DenseMatrix.ones(rows, cols);
|
|
172
|
+
if (cols === void 0) return new Array(rows).fill(1);
|
|
173
|
+
return DenseMatrix$1.ones(rows, cols);
|
|
285
174
|
}
|
|
286
175
|
function size(m) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
return [m.rows, m.cols];
|
|
176
|
+
if (Array.isArray(m)) return [m.length, m[0]?.length ?? 0];
|
|
177
|
+
return [m.rows, m.cols];
|
|
291
178
|
}
|
|
292
179
|
function isComplex_(x) {
|
|
293
|
-
|
|
180
|
+
return isComplex(x);
|
|
294
181
|
}
|
|
295
182
|
function isFraction_(x) {
|
|
296
|
-
|
|
183
|
+
return isFraction(x);
|
|
297
184
|
}
|
|
298
185
|
function isBigNumber_(x) {
|
|
299
|
-
|
|
186
|
+
return isBigNumber(x);
|
|
300
187
|
}
|
|
301
188
|
function isNumber_(x) {
|
|
302
|
-
|
|
189
|
+
return isNumber(x);
|
|
303
190
|
}
|
|
304
191
|
function isMatrix(x) {
|
|
305
|
-
|
|
192
|
+
return x instanceof DenseMatrix$1 || x instanceof SparseMatrix$1;
|
|
306
193
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
phi,
|
|
382
|
-
tau,
|
|
383
|
-
LN2,
|
|
384
|
-
LN10,
|
|
385
|
-
LOG2E,
|
|
386
|
-
LOG10E,
|
|
387
|
-
SQRT2,
|
|
388
|
-
SQRT1_2,
|
|
389
|
-
Infinity: Infinity_,
|
|
390
|
-
NaN: NaN_
|
|
194
|
+
const i = I$1;
|
|
195
|
+
const pi = Math.PI;
|
|
196
|
+
const e = Math.E;
|
|
197
|
+
const phi = (1 + Math.sqrt(5)) / 2;
|
|
198
|
+
const tau = 2 * Math.PI;
|
|
199
|
+
const LN2 = LN2$1;
|
|
200
|
+
const LN10 = LN10$1;
|
|
201
|
+
const LOG2E = LOG2E$1;
|
|
202
|
+
const LOG10E = LOG10E$1;
|
|
203
|
+
const SQRT2 = SQRT2$1;
|
|
204
|
+
const SQRT1_2 = SQRT1_2$1;
|
|
205
|
+
const Infinity_ = Infinity;
|
|
206
|
+
const NaN_ = NaN;
|
|
207
|
+
const shims = {
|
|
208
|
+
complex,
|
|
209
|
+
fraction,
|
|
210
|
+
bignumber,
|
|
211
|
+
matrix,
|
|
212
|
+
sparse,
|
|
213
|
+
add,
|
|
214
|
+
subtract,
|
|
215
|
+
multiply,
|
|
216
|
+
divide,
|
|
217
|
+
pow,
|
|
218
|
+
sqrt,
|
|
219
|
+
abs,
|
|
220
|
+
exp,
|
|
221
|
+
log,
|
|
222
|
+
sin,
|
|
223
|
+
cos,
|
|
224
|
+
tan,
|
|
225
|
+
asin,
|
|
226
|
+
acos,
|
|
227
|
+
atan,
|
|
228
|
+
atan2,
|
|
229
|
+
sum,
|
|
230
|
+
mean,
|
|
231
|
+
std,
|
|
232
|
+
variance,
|
|
233
|
+
min,
|
|
234
|
+
max,
|
|
235
|
+
gcd,
|
|
236
|
+
lcm,
|
|
237
|
+
round,
|
|
238
|
+
floor,
|
|
239
|
+
ceil,
|
|
240
|
+
conj,
|
|
241
|
+
re,
|
|
242
|
+
im,
|
|
243
|
+
arg,
|
|
244
|
+
transpose,
|
|
245
|
+
det,
|
|
246
|
+
identity,
|
|
247
|
+
zeros,
|
|
248
|
+
ones,
|
|
249
|
+
size,
|
|
250
|
+
isComplex: isComplex_,
|
|
251
|
+
isFraction: isFraction_,
|
|
252
|
+
isBigNumber: isBigNumber_,
|
|
253
|
+
isNumber: isNumber_,
|
|
254
|
+
isMatrix,
|
|
255
|
+
i,
|
|
256
|
+
pi,
|
|
257
|
+
e,
|
|
258
|
+
phi,
|
|
259
|
+
tau,
|
|
260
|
+
LN2,
|
|
261
|
+
LN10,
|
|
262
|
+
LOG2E,
|
|
263
|
+
LOG10E,
|
|
264
|
+
SQRT2,
|
|
265
|
+
SQRT1_2,
|
|
266
|
+
Infinity: Infinity_,
|
|
267
|
+
NaN: NaN_
|
|
391
268
|
};
|
|
392
|
-
|
|
393
|
-
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/chain.ts
|
|
394
271
|
function createChain(math) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
if (typeof fn === "function") {
|
|
408
|
-
return (...args) => chain(fn(value, ...args));
|
|
409
|
-
}
|
|
410
|
-
return void 0;
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
return chain;
|
|
272
|
+
function chain(value) {
|
|
273
|
+
return new Proxy({
|
|
274
|
+
done: () => value,
|
|
275
|
+
valueOf: () => value,
|
|
276
|
+
toString: () => String(value)
|
|
277
|
+
}, { get(target, prop) {
|
|
278
|
+
if (prop in target || typeof prop === "symbol") return target[prop];
|
|
279
|
+
const fn = math[prop];
|
|
280
|
+
if (typeof fn === "function") return (...args) => chain(fn(value, ...args));
|
|
281
|
+
} });
|
|
282
|
+
}
|
|
283
|
+
return chain;
|
|
415
284
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
COMPLEX_ZERO as COMPLEX_ZERO2,
|
|
425
|
-
COMPLEX_ONE,
|
|
426
|
-
FRACTION_ZERO,
|
|
427
|
-
FRACTION_ONE,
|
|
428
|
-
BIGNUMBER_ZERO,
|
|
429
|
-
BIGNUMBER_ONE,
|
|
430
|
-
BIGNUMBER_PI,
|
|
431
|
-
BIGNUMBER_E
|
|
432
|
-
} from "@danielsimonjr/mathts-core";
|
|
433
|
-
import { DenseMatrix as DenseMatrix2, SparseMatrix as SparseMatrix2 } from "@danielsimonjr/mathts-matrix";
|
|
434
|
-
import { computePool } from "@danielsimonjr/mathts-parallel";
|
|
435
|
-
var defaultConfig = {
|
|
436
|
-
precision: 64,
|
|
437
|
-
matrix: "Matrix",
|
|
438
|
-
number: "number",
|
|
439
|
-
epsilon: 1e-12,
|
|
440
|
-
randomSeed: null
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/index.ts
|
|
287
|
+
const defaultConfig = {
|
|
288
|
+
precision: 64,
|
|
289
|
+
matrix: "Matrix",
|
|
290
|
+
number: "number",
|
|
291
|
+
epsilon: 1e-12,
|
|
292
|
+
randomSeed: null
|
|
441
293
|
};
|
|
442
|
-
function create(factories = all,
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
tau: shims.tau,
|
|
522
|
-
LN2: shims.LN2,
|
|
523
|
-
LN10: shims.LN10,
|
|
524
|
-
LOG2E: shims.LOG2E,
|
|
525
|
-
LOG10E: shims.LOG10E,
|
|
526
|
-
SQRT2: shims.SQRT2,
|
|
527
|
-
SQRT1_2: shims.SQRT1_2,
|
|
528
|
-
Infinity: shims.Infinity,
|
|
529
|
-
NaN: shims.NaN,
|
|
530
|
-
// Placeholder; rebound below once `instance` exists so chain methods can
|
|
531
|
-
// resolve against the full surfaced namespace.
|
|
532
|
-
chain: (() => {
|
|
533
|
-
throw new Error("chain not initialized");
|
|
534
|
-
})
|
|
535
|
-
};
|
|
536
|
-
instance.chain = createChain(instance);
|
|
537
|
-
return instance;
|
|
294
|
+
function create(factories = all, config = {}) {
|
|
295
|
+
const currentConfig = {
|
|
296
|
+
...defaultConfig,
|
|
297
|
+
...config
|
|
298
|
+
};
|
|
299
|
+
if (Object.keys(config).length > 0) mathFunctions.config(config);
|
|
300
|
+
const instance = {
|
|
301
|
+
...factories,
|
|
302
|
+
config: (newConfig) => {
|
|
303
|
+
const merged = mathFunctions.config(newConfig);
|
|
304
|
+
Object.assign(currentConfig, merged);
|
|
305
|
+
return { ...currentConfig };
|
|
306
|
+
},
|
|
307
|
+
complex: shims.complex,
|
|
308
|
+
fraction: shims.fraction,
|
|
309
|
+
bignumber: shims.bignumber,
|
|
310
|
+
matrix: shims.matrix,
|
|
311
|
+
sparse: shims.sparse,
|
|
312
|
+
add: shims.add,
|
|
313
|
+
subtract: shims.subtract,
|
|
314
|
+
multiply: shims.multiply,
|
|
315
|
+
divide: shims.divide,
|
|
316
|
+
pow: shims.pow,
|
|
317
|
+
sqrt: shims.sqrt,
|
|
318
|
+
abs: shims.abs,
|
|
319
|
+
exp: shims.exp,
|
|
320
|
+
log: shims.log,
|
|
321
|
+
sin: shims.sin,
|
|
322
|
+
cos: shims.cos,
|
|
323
|
+
tan: shims.tan,
|
|
324
|
+
asin: shims.asin,
|
|
325
|
+
acos: shims.acos,
|
|
326
|
+
atan: shims.atan,
|
|
327
|
+
atan2: shims.atan2,
|
|
328
|
+
sum: shims.sum,
|
|
329
|
+
mean: shims.mean,
|
|
330
|
+
std: shims.std,
|
|
331
|
+
variance: shims.variance,
|
|
332
|
+
min: shims.min,
|
|
333
|
+
max: shims.max,
|
|
334
|
+
gcd: shims.gcd,
|
|
335
|
+
lcm: shims.lcm,
|
|
336
|
+
round: shims.round,
|
|
337
|
+
floor: shims.floor,
|
|
338
|
+
ceil: shims.ceil,
|
|
339
|
+
conj: shims.conj,
|
|
340
|
+
re: shims.re,
|
|
341
|
+
im: shims.im,
|
|
342
|
+
arg: shims.arg,
|
|
343
|
+
transpose: shims.transpose,
|
|
344
|
+
det: shims.det,
|
|
345
|
+
identity: shims.identity,
|
|
346
|
+
zeros: shims.zeros,
|
|
347
|
+
ones: shims.ones,
|
|
348
|
+
size: shims.size,
|
|
349
|
+
isComplex: shims.isComplex,
|
|
350
|
+
isFraction: shims.isFraction,
|
|
351
|
+
isBigNumber: shims.isBigNumber,
|
|
352
|
+
isNumber: shims.isNumber,
|
|
353
|
+
isMatrix: shims.isMatrix,
|
|
354
|
+
i: shims.i,
|
|
355
|
+
pi: shims.pi,
|
|
356
|
+
e: shims.e,
|
|
357
|
+
phi: shims.phi,
|
|
358
|
+
tau: shims.tau,
|
|
359
|
+
LN2: shims.LN2,
|
|
360
|
+
LN10: shims.LN10,
|
|
361
|
+
LOG2E: shims.LOG2E,
|
|
362
|
+
LOG10E: shims.LOG10E,
|
|
363
|
+
SQRT2: shims.SQRT2,
|
|
364
|
+
SQRT1_2: shims.SQRT1_2,
|
|
365
|
+
Infinity: shims.Infinity,
|
|
366
|
+
NaN: shims.NaN,
|
|
367
|
+
chain: (() => {
|
|
368
|
+
throw new Error("chain not initialized");
|
|
369
|
+
})
|
|
370
|
+
};
|
|
371
|
+
instance.chain = createChain(instance);
|
|
372
|
+
return instance;
|
|
538
373
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
};
|
|
542
|
-
export {
|
|
543
|
-
BIGNUMBER_E,
|
|
544
|
-
BIGNUMBER_ONE,
|
|
545
|
-
BIGNUMBER_PI,
|
|
546
|
-
BIGNUMBER_ZERO,
|
|
547
|
-
BigNumber2 as BigNumber,
|
|
548
|
-
COMPLEX_ONE,
|
|
549
|
-
COMPLEX_ZERO2 as COMPLEX_ZERO,
|
|
550
|
-
Complex2 as Complex,
|
|
551
|
-
DenseMatrix2 as DenseMatrix,
|
|
552
|
-
FRACTION_ONE,
|
|
553
|
-
FRACTION_ZERO,
|
|
554
|
-
Fraction2 as Fraction,
|
|
555
|
-
I2 as I,
|
|
556
|
-
Infinity_,
|
|
557
|
-
LN10,
|
|
558
|
-
LN2,
|
|
559
|
-
LOG10E,
|
|
560
|
-
LOG2E,
|
|
561
|
-
NaN_,
|
|
562
|
-
SQRT1_2,
|
|
563
|
-
SQRT2,
|
|
564
|
-
SparseMatrix2 as SparseMatrix,
|
|
565
|
-
abs,
|
|
566
|
-
acos,
|
|
567
|
-
add,
|
|
568
|
-
all,
|
|
569
|
-
arg,
|
|
570
|
-
asin,
|
|
571
|
-
atan,
|
|
572
|
-
atan2,
|
|
573
|
-
bignumber,
|
|
574
|
-
ceil,
|
|
575
|
-
complex,
|
|
576
|
-
computePool,
|
|
577
|
-
conj,
|
|
578
|
-
cos,
|
|
579
|
-
create,
|
|
580
|
-
det,
|
|
581
|
-
divide,
|
|
582
|
-
e,
|
|
583
|
-
exp,
|
|
584
|
-
floor,
|
|
585
|
-
fraction,
|
|
586
|
-
gcd,
|
|
587
|
-
i,
|
|
588
|
-
identity,
|
|
589
|
-
im,
|
|
590
|
-
isBigNumber_,
|
|
591
|
-
isComplex_,
|
|
592
|
-
isFraction_,
|
|
593
|
-
isMatrix,
|
|
594
|
-
isNumber_,
|
|
595
|
-
lcm,
|
|
596
|
-
log,
|
|
597
|
-
matrix,
|
|
598
|
-
max,
|
|
599
|
-
mean,
|
|
600
|
-
min,
|
|
601
|
-
multiply,
|
|
602
|
-
ones,
|
|
603
|
-
phi,
|
|
604
|
-
pi,
|
|
605
|
-
pow,
|
|
606
|
-
re,
|
|
607
|
-
round,
|
|
608
|
-
shims,
|
|
609
|
-
sin,
|
|
610
|
-
size,
|
|
611
|
-
sparse,
|
|
612
|
-
sqrt,
|
|
613
|
-
std,
|
|
614
|
-
subtract,
|
|
615
|
-
sum,
|
|
616
|
-
tan,
|
|
617
|
-
tau,
|
|
618
|
-
transpose,
|
|
619
|
-
variance,
|
|
620
|
-
zeros
|
|
621
|
-
};
|
|
374
|
+
const all = { ...mathFunctions };
|
|
375
|
+
//#endregion
|
|
376
|
+
export { BIGNUMBER_E, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_ZERO, BigNumber, COMPLEX_ONE, COMPLEX_ZERO, Complex, DenseMatrix, FRACTION_ONE, FRACTION_ZERO, Fraction, I, Infinity_, LN10, LN2, LOG10E, LOG2E, NaN_, SQRT1_2, SQRT2, SparseMatrix, abs, acos, add, all, arg, asin, atan, atan2, bignumber, ceil, complex, computePool, conj, cos, create, det, divide, e, exp, floor, fraction, gcd, i, identity, im, isBigNumber_, isComplex_, isFraction_, isMatrix, isNumber_, lcm, log, matrix, max, mean, min, multiply, ones, phi, pi, pow, re, round, shims, sin, size, sparse, sqrt, std, subtract, sum, tan, tau, transpose, variance, zeros };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielsimonjr/mathts-compat",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.31",
|
|
4
4
|
"description": "mathjs compatibility layer for MathTS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,22 +16,33 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "
|
|
20
|
-
"dev": "
|
|
19
|
+
"build": "tsdown src/index.ts --format esm && tsc -p tsconfig.dts.json",
|
|
20
|
+
"dev": "tsdown src/index.ts --format esm --watch --on-success \"tsc -p tsconfig.dts.json\"",
|
|
21
21
|
"typecheck": "tsc --noEmit && tsc -p tsconfig.test.json",
|
|
22
22
|
"test": "bun test --isolate --timeout 30000",
|
|
23
23
|
"test:coverage": "bun test --isolate --timeout 30000 --coverage",
|
|
24
|
-
"build:prod": "
|
|
24
|
+
"build:prod": "tsdown src/index.ts --format esm --minify && tsc -p tsconfig.dts.json"
|
|
25
|
+
},
|
|
26
|
+
"tsdown": {
|
|
27
|
+
"fixedExtension": false,
|
|
28
|
+
"dts": false,
|
|
29
|
+
"outputOptions": {
|
|
30
|
+
"comments": {
|
|
31
|
+
"legal": true,
|
|
32
|
+
"annotation": true,
|
|
33
|
+
"jsdoc": false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
25
36
|
},
|
|
26
37
|
"dependencies": {
|
|
27
38
|
"@danielsimonjr/mathts-core": "^0.18.0",
|
|
28
|
-
"@danielsimonjr/mathts-functions": "^0.
|
|
39
|
+
"@danielsimonjr/mathts-functions": "^0.69.0",
|
|
29
40
|
"@danielsimonjr/mathts-matrix": "^0.7.8",
|
|
30
41
|
"@danielsimonjr/mathts-parallel": "^0.6.10"
|
|
31
42
|
},
|
|
32
43
|
"devDependencies": {
|
|
33
44
|
"@types/node": "^26.4.0",
|
|
34
|
-
"
|
|
45
|
+
"tsdown": "^0.23.0",
|
|
35
46
|
"typescript": "^7.0.2",
|
|
36
47
|
"vitest": "^5.0.0"
|
|
37
48
|
},
|