@danielsimonjr/mathts-compat 0.4.29 → 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.
Files changed (2) hide show
  1. package/dist/index.js +316 -561
  2. package/package.json +20 -9
package/dist/index.js CHANGED
@@ -1,621 +1,376 @@
1
- // src/shims.ts
2
- import {
3
- Complex,
4
- Fraction,
5
- BigNumber,
6
- I,
7
- COMPLEX_ZERO,
8
- isComplex,
9
- isFraction,
10
- isBigNumber,
11
- isNumber,
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
- if (numerator === void 0) {
63
- return new Fraction(0, 1);
64
- }
65
- if (numerator instanceof Fraction) {
66
- return numerator;
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
- if (value === void 0) {
78
- return BigNumber.fromNumber(0);
79
- }
80
- if (value instanceof BigNumber) {
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
- if (data === void 0) {
90
- return DenseMatrix.zeros(0, 0);
91
- }
92
- if (data instanceof DenseMatrix || data instanceof SparseMatrix) {
93
- return data;
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
- if (data === void 0) {
103
- return SparseMatrix.zeros(0, 0);
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
- var isMatrixLike = (x) => x instanceof DenseMatrix || Array.isArray(x) && x.length > 0 && Array.isArray(x[0]);
108
- var toDenseMatrix = (x) => x instanceof DenseMatrix ? x : DenseMatrix.fromArray(x);
109
- var unwrap = (r) => r instanceof DenseMatrix ? r.toArray() : r;
110
- var applyArithmetic = (scalarFn, matrixFn, a, b) => {
111
- if (isMatrixLike(a) || isMatrixLike(b)) {
112
- const aa = isMatrixLike(a) ? toDenseMatrix(a) : a;
113
- const bb = isMatrixLike(b) ? toDenseMatrix(b) : b;
114
- return unwrap(matrixFn(aa, bb));
115
- }
116
- return scalarFn(a, b);
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
- var makeArithmetic = (scalarFn, matrixFn) => (...args) => {
119
- if (args.length === 0) {
120
- throw new TypeError("Too few arguments (expected at least 1)");
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
- var add = makeArithmetic(
128
- _add,
129
- _matAdd
130
- );
131
- var subtract = makeArithmetic(
132
- _subtract,
133
- _matSubtract
134
- );
135
- var multiply = makeArithmetic(
136
- _multiply,
137
- _matMultiply
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
- return Math.asin(x);
66
+ return Math.asin(x);
150
67
  }
151
68
  function acos(x) {
152
- return Math.acos(x);
69
+ return Math.acos(x);
153
70
  }
154
71
  function atan(x) {
155
- return Math.atan(x);
72
+ return Math.atan(x);
156
73
  }
157
74
  function atan2(y, x) {
158
- return Math.atan2(y, x);
75
+ return Math.atan2(y, x);
159
76
  }
160
- var sum = _sum;
161
- var mean = _mean;
77
+ const sum = sum$1;
78
+ const mean = mean$1;
162
79
  function toNumericArray(data) {
163
- if (data instanceof DenseMatrix) return data.toArray().flat(Infinity);
164
- if (Array.isArray(data)) return data.flat(Infinity);
165
- return [data];
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
- const arr = toNumericArray(data);
169
- const n = arr.length;
170
- if (n === 0) return NaN;
171
- const mu = arr.reduce((s, x) => s + x, 0) / n;
172
- const ss = arr.reduce((s, x) => s + (x - mu) * (x - mu), 0);
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
- return Math.sqrt(variance(data, normalization));
92
+ return Math.sqrt(variance(data, normalization));
178
93
  }
179
- var min = _min;
180
- var max = _max;
181
- var gcd = _gcd;
182
- var lcm = _lcm;
183
- var round = _round;
184
- var floor = _floor;
185
- var ceil = _ceil;
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
- if (!isComplex(c)) {
188
- throw new TypeError("Expected Complex number");
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
- if (typeof c === "number") return c;
194
- if (isComplex(c)) return c.re;
195
- throw new TypeError("Expected Complex or number");
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
- if (typeof c === "number") return 0;
199
- if (isComplex(c)) return c.im;
200
- throw new TypeError("Expected Complex or number");
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
- if (!isComplex(c)) {
204
- throw new TypeError("Expected Complex number");
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
- if (Array.isArray(m)) {
210
- return DenseMatrix.fromArray(m).transpose().toArray();
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
- const matrix2 = Array.isArray(m) ? DenseMatrix.fromArray(m) : m;
216
- if (!(matrix2 instanceof DenseMatrix)) {
217
- throw new TypeError("Expected DenseMatrix or 2D array");
218
- }
219
- if (matrix2.rows !== matrix2.cols) {
220
- throw new Error("Determinant requires a square matrix");
221
- }
222
- const n = matrix2.rows;
223
- if (n === 0) return 1;
224
- if (n === 1) return matrix2.get(0, 0);
225
- if (n === 2) {
226
- return matrix2.get(0, 0) * matrix2.get(1, 1) - matrix2.get(0, 1) * matrix2.get(1, 0);
227
- }
228
- if (n === 3) {
229
- const a = matrix2.get(0, 0), b = matrix2.get(0, 1), c = matrix2.get(0, 2);
230
- const d = matrix2.get(1, 0), e2 = matrix2.get(1, 1), f = matrix2.get(1, 2);
231
- const g = matrix2.get(2, 0), h = matrix2.get(2, 1), i2 = matrix2.get(2, 2);
232
- return a * (e2 * i2 - f * h) - b * (d * i2 - f * g) + c * (d * h - e2 * g);
233
- }
234
- const lu = [];
235
- for (let i2 = 0; i2 < n; i2++) {
236
- lu[i2] = [];
237
- for (let j = 0; j < n; j++) {
238
- lu[i2][j] = matrix2.get(i2, j);
239
- }
240
- }
241
- let swaps = 0;
242
- for (let k = 0; k < n - 1; k++) {
243
- let maxVal = Math.abs(lu[k][k]);
244
- let maxRow = k;
245
- for (let i2 = k + 1; i2 < n; i2++) {
246
- if (Math.abs(lu[i2][k]) > maxVal) {
247
- maxVal = Math.abs(lu[i2][k]);
248
- maxRow = i2;
249
- }
250
- }
251
- if (maxVal < 1e-12) {
252
- return 0;
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
- return DenseMatrix.identity(n);
165
+ return DenseMatrix$1.identity(n);
273
166
  }
274
167
  function zeros(rows, cols) {
275
- if (cols === void 0) {
276
- return new Array(rows).fill(0);
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
- if (cols === void 0) {
282
- return new Array(rows).fill(1);
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
- if (Array.isArray(m)) {
288
- return [m.length, m[0]?.length ?? 0];
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
- return isComplex(x);
180
+ return isComplex(x);
294
181
  }
295
182
  function isFraction_(x) {
296
- return isFraction(x);
183
+ return isFraction(x);
297
184
  }
298
185
  function isBigNumber_(x) {
299
- return isBigNumber(x);
186
+ return isBigNumber(x);
300
187
  }
301
188
  function isNumber_(x) {
302
- return isNumber(x);
189
+ return isNumber(x);
303
190
  }
304
191
  function isMatrix(x) {
305
- return x instanceof DenseMatrix || x instanceof SparseMatrix;
192
+ return x instanceof DenseMatrix$1 || x instanceof SparseMatrix$1;
306
193
  }
307
- var i = I;
308
- var pi = Math.PI;
309
- var e = Math.E;
310
- var phi = (1 + Math.sqrt(5)) / 2;
311
- var tau = 2 * Math.PI;
312
- var LN2 = CORE_LN2;
313
- var LN10 = CORE_LN10;
314
- var LOG2E = CORE_LOG2E;
315
- var LOG10E = CORE_LOG10E;
316
- var SQRT2 = CORE_SQRT2;
317
- var SQRT1_2 = CORE_SQRT1_2;
318
- var Infinity_ = Infinity;
319
- var NaN_ = NaN;
320
- var shims = {
321
- // Type creation
322
- complex,
323
- fraction,
324
- bignumber,
325
- matrix,
326
- sparse,
327
- // Arithmetic
328
- add,
329
- subtract,
330
- multiply,
331
- divide,
332
- pow,
333
- sqrt,
334
- abs,
335
- exp,
336
- log,
337
- // Trigonometry
338
- sin,
339
- cos,
340
- tan,
341
- asin,
342
- acos,
343
- atan,
344
- atan2,
345
- // Statistics
346
- sum,
347
- mean,
348
- std,
349
- variance,
350
- min,
351
- max,
352
- // Number theory
353
- gcd,
354
- lcm,
355
- // Rounding
356
- round,
357
- floor,
358
- ceil,
359
- // Complex-specific
360
- conj,
361
- re,
362
- im,
363
- arg,
364
- // Matrix-specific
365
- transpose,
366
- det,
367
- identity,
368
- zeros,
369
- ones,
370
- size,
371
- // Type checking
372
- isComplex: isComplex_,
373
- isFraction: isFraction_,
374
- isBigNumber: isBigNumber_,
375
- isNumber: isNumber_,
376
- isMatrix,
377
- // Constants
378
- i,
379
- pi,
380
- e,
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
- // src/chain.ts
269
+ //#endregion
270
+ //#region src/chain.ts
394
271
  function createChain(math) {
395
- function chain(value) {
396
- const base = {
397
- done: () => value,
398
- valueOf: () => value,
399
- toString: () => String(value)
400
- };
401
- return new Proxy(base, {
402
- get(target, prop) {
403
- if (prop in target || typeof prop === "symbol") {
404
- return target[prop];
405
- }
406
- const fn = math[prop];
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
- // src/index.ts
418
- import * as mathFunctions from "@danielsimonjr/mathts-functions";
419
- import {
420
- Complex as Complex2,
421
- Fraction as Fraction2,
422
- BigNumber as BigNumber2,
423
- I as I2,
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, config2 = {}) {
443
- const currentConfig = { ...defaultConfig, ...config2 };
444
- if (Object.keys(config2).length > 0) {
445
- mathFunctions.config(config2);
446
- }
447
- const instance = {
448
- // Full @danielsimonjr/mathts-functions namespace — det, integrate, eigs,
449
- // simplify, and the rest. The compat-specific shims below overlay it.
450
- ...factories,
451
- // Configuration — forwards to the shared functions runtime config so it
452
- // actually DRIVES behavior (e.g. `config({ matrix: 'Array' })` changes the
453
- // return type of matrix-producing ops). `currentConfig` mirrors it for the
454
- // read path and seeds the functions config with this instance's overrides.
455
- config: (newConfig) => {
456
- const merged = mathFunctions.config(newConfig);
457
- Object.assign(currentConfig, merged);
458
- return { ...currentConfig };
459
- },
460
- // Type creation
461
- complex: shims.complex,
462
- fraction: shims.fraction,
463
- bignumber: shims.bignumber,
464
- matrix: shims.matrix,
465
- sparse: shims.sparse,
466
- // Arithmetic
467
- add: shims.add,
468
- subtract: shims.subtract,
469
- multiply: shims.multiply,
470
- divide: shims.divide,
471
- pow: shims.pow,
472
- sqrt: shims.sqrt,
473
- abs: shims.abs,
474
- exp: shims.exp,
475
- log: shims.log,
476
- // Trigonometry
477
- sin: shims.sin,
478
- cos: shims.cos,
479
- tan: shims.tan,
480
- asin: shims.asin,
481
- acos: shims.acos,
482
- atan: shims.atan,
483
- atan2: shims.atan2,
484
- // Statistics
485
- sum: shims.sum,
486
- mean: shims.mean,
487
- std: shims.std,
488
- variance: shims.variance,
489
- min: shims.min,
490
- max: shims.max,
491
- // Number theory
492
- gcd: shims.gcd,
493
- lcm: shims.lcm,
494
- // Rounding
495
- round: shims.round,
496
- floor: shims.floor,
497
- ceil: shims.ceil,
498
- // Complex-specific
499
- conj: shims.conj,
500
- re: shims.re,
501
- im: shims.im,
502
- arg: shims.arg,
503
- // Matrix-specific
504
- transpose: shims.transpose,
505
- det: shims.det,
506
- identity: shims.identity,
507
- zeros: shims.zeros,
508
- ones: shims.ones,
509
- size: shims.size,
510
- // Type checking
511
- isComplex: shims.isComplex,
512
- isFraction: shims.isFraction,
513
- isBigNumber: shims.isBigNumber,
514
- isNumber: shims.isNumber,
515
- isMatrix: shims.isMatrix,
516
- // Constants
517
- i: shims.i,
518
- pi: shims.pi,
519
- e: shims.e,
520
- phi: shims.phi,
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
- var all = {
540
- ...mathFunctions
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.29",
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": "tsup src/index.ts --format esm --clean && tsc -p tsconfig.dts.json",
20
- "dev": "tsup src/index.ts --format esm --watch --onSuccess \"tsc -p tsconfig.dts.json\"",
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": "tsup src/index.ts --format esm --clean --minify --treeshake && tsc -p tsconfig.dts.json"
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
- "@danielsimonjr/mathts-core": "^0.17.0",
28
- "@danielsimonjr/mathts-functions": "^0.68.1",
29
- "@danielsimonjr/mathts-matrix": "^0.7.7",
30
- "@danielsimonjr/mathts-parallel": "^0.6.9"
38
+ "@danielsimonjr/mathts-core": "^0.18.0",
39
+ "@danielsimonjr/mathts-functions": "^0.69.0",
40
+ "@danielsimonjr/mathts-matrix": "^0.7.8",
41
+ "@danielsimonjr/mathts-parallel": "^0.6.10"
31
42
  },
32
43
  "devDependencies": {
33
44
  "@types/node": "^26.4.0",
34
- "tsup": "^8.0.0",
45
+ "tsdown": "^0.23.0",
35
46
  "typescript": "^7.0.2",
36
47
  "vitest": "^5.0.0"
37
48
  },