@danielsimonjr/mathts-core 0.18.1 → 0.20.0
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/README.md +30 -5
- package/dist/collection.d.ts +35 -23
- package/dist/collection.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1348 -1534
- package/dist/internal.d.ts +3 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1021 -1514
- package/dist/numeric/rng.d.ts +88 -0
- package/dist/numeric/rng.d.ts.map +1 -0
- package/dist/numeric/strides.d.ts +18 -0
- package/dist/numeric/strides.d.ts.map +1 -0
- package/dist/object.d.ts +20 -2
- package/dist/object.d.ts.map +1 -1
- package/dist/shared.d.ts +19 -0
- package/dist/shared.d.ts.map +1 -1
- package/dist/switch.d.ts +2 -4
- package/dist/switch.d.ts.map +1 -1
- package/dist/types/bignumber.d.ts +7 -0
- package/dist/types/bignumber.d.ts.map +1 -1
- package/dist/types/complex.d.ts +20 -18
- package/dist/types/complex.d.ts.map +1 -1
- package/dist/types/fraction.d.ts +5 -0
- package/dist/types/fraction.d.ts.map +1 -1
- package/dist/types/si-dimension-vector.d.ts +62 -7
- package/dist/types/si-dimension-vector.d.ts.map +1 -1
- package/dist/types/unit/Unit.d.ts.map +1 -1
- package/dist/types/unit/index.d.ts +1 -1
- package/dist/types/unit/index.d.ts.map +1 -1
- package/dist/types/unit/unit-table.d.ts +8 -2
- package/dist/types/unit/unit-table.d.ts.map +1 -1
- package/dist/types/unit/unit-types.d.ts +10 -0
- package/dist/types/unit/unit-types.d.ts.map +1 -1
- package/dist/types/unit.d.ts +1 -1
- package/dist/types/unit.d.ts.map +1 -1
- package/dist/unit-Dul_E1rh.js +5946 -0
- package/dist/wasm-as-header.d.ts +17 -0
- package/dist/wasm-as-header.d.ts.map +1 -0
- package/dist/wasm-loader.d.ts +33 -1
- package/dist/wasm-loader.d.ts.map +1 -1
- package/package.json +6 -5
- package/dist/chunk-36FOYJAP.js +0 -6091
package/dist/index.js
CHANGED
|
@@ -1,1598 +1,1412 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
min() {
|
|
246
|
-
const size = this.size()[0];
|
|
247
|
-
if (size > 0) {
|
|
248
|
-
if (this.step > 0) {
|
|
249
|
-
return this.start;
|
|
250
|
-
} else {
|
|
251
|
-
return this.start + (size - 1) * this.step;
|
|
252
|
-
}
|
|
253
|
-
} else {
|
|
254
|
-
return void 0;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Calculate the maximum value in the range
|
|
259
|
-
* @memberof Range
|
|
260
|
-
* @return max
|
|
261
|
-
*/
|
|
262
|
-
max() {
|
|
263
|
-
const size = this.size()[0];
|
|
264
|
-
if (size > 0) {
|
|
265
|
-
if (this.step > 0) {
|
|
266
|
-
return this.start + (size - 1) * this.step;
|
|
267
|
-
} else {
|
|
268
|
-
return this.start;
|
|
269
|
-
}
|
|
270
|
-
} else {
|
|
271
|
-
return void 0;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Execute a callback function for each value in the range.
|
|
276
|
-
* @memberof Range
|
|
277
|
-
* @param callback - The callback method is invoked with three
|
|
278
|
-
* parameters: the value of the element, the index
|
|
279
|
-
* of the element, and the Range being traversed.
|
|
280
|
-
*/
|
|
281
|
-
forEach(callback) {
|
|
282
|
-
let x = this.start;
|
|
283
|
-
const step = this.step;
|
|
284
|
-
const end = this.end;
|
|
285
|
-
let i = 0;
|
|
286
|
-
if (step > 0) {
|
|
287
|
-
while (x < end) {
|
|
288
|
-
callback(x, [i], this);
|
|
289
|
-
x += step;
|
|
290
|
-
i++;
|
|
291
|
-
}
|
|
292
|
-
} else if (step < 0) {
|
|
293
|
-
while (x > end) {
|
|
294
|
-
callback(x, [i], this);
|
|
295
|
-
x += step;
|
|
296
|
-
i++;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Execute a callback function for each value in the Range, and return the
|
|
302
|
-
* results as an array
|
|
303
|
-
* @memberof Range
|
|
304
|
-
* @param callback - The callback method is invoked with three
|
|
305
|
-
* parameters: the value of the element, the index
|
|
306
|
-
* of the element, and the Matrix being traversed.
|
|
307
|
-
* @returns array
|
|
308
|
-
*/
|
|
309
|
-
map(callback) {
|
|
310
|
-
const array = [];
|
|
311
|
-
this.forEach((value, index) => {
|
|
312
|
-
array[index[0]] = callback(value, index, this);
|
|
313
|
-
});
|
|
314
|
-
return array;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Create an Array with a copy of the Ranges data
|
|
318
|
-
* @memberof Range
|
|
319
|
-
* @returns array
|
|
320
|
-
*/
|
|
321
|
-
toArray() {
|
|
322
|
-
const array = [];
|
|
323
|
-
this.forEach(function(value, index) {
|
|
324
|
-
array[index[0]] = value;
|
|
325
|
-
});
|
|
326
|
-
return array;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Get the primitive value of the Range, a one dimensional array
|
|
330
|
-
* @memberof Range
|
|
331
|
-
* @returns array
|
|
332
|
-
*/
|
|
333
|
-
valueOf() {
|
|
334
|
-
if (this._cache !== null && this.start === this._cacheStart && this.end === this._cacheEnd && this.step === this._cacheStep) {
|
|
335
|
-
return this._cache;
|
|
336
|
-
}
|
|
337
|
-
this._cache = this.toArray();
|
|
338
|
-
this._cacheStart = this.start;
|
|
339
|
-
this._cacheEnd = this.end;
|
|
340
|
-
this._cacheStep = this.step;
|
|
341
|
-
return this._cache;
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Get a string representation of the range, with optional formatting options.
|
|
345
|
-
* Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
|
|
346
|
-
* @memberof Range
|
|
347
|
-
* @param options - Optional. Formatting options. See
|
|
348
|
-
* lib/utils/number:format for a
|
|
349
|
-
* description of the available
|
|
350
|
-
* options.
|
|
351
|
-
* @returns str
|
|
352
|
-
*/
|
|
353
|
-
format(options) {
|
|
354
|
-
let str = format(this.start, options);
|
|
355
|
-
if (this.step !== 1) {
|
|
356
|
-
str += ":" + format(this.step, options);
|
|
357
|
-
}
|
|
358
|
-
str += ":" + format(this.end, options);
|
|
359
|
-
return str;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Get a string representation of the range.
|
|
363
|
-
* @memberof Range
|
|
364
|
-
* @returns
|
|
365
|
-
*/
|
|
366
|
-
toString() {
|
|
367
|
-
return this.format();
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Get a JSON representation of the range
|
|
371
|
-
* @memberof Range
|
|
372
|
-
* @returns Returns a JSON object structured as:
|
|
373
|
-
* `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
|
|
374
|
-
*/
|
|
375
|
-
toJSON() {
|
|
376
|
-
return {
|
|
377
|
-
mathjs: "Range",
|
|
378
|
-
start: this.start,
|
|
379
|
-
end: this.end,
|
|
380
|
-
step: this.step
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Instantiate a Range from a JSON object
|
|
385
|
-
* @memberof Range
|
|
386
|
-
* @param json - A JSON object structured as:
|
|
387
|
-
* `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
|
|
388
|
-
* @return
|
|
389
|
-
*/
|
|
390
|
-
static fromJSON(json) {
|
|
391
|
-
return new Range2(json.start, json.end, json.step);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return Range2;
|
|
395
|
-
},
|
|
396
|
-
{ isClass: true }
|
|
397
|
-
);
|
|
398
|
-
var Range = createRangeClass({});
|
|
399
|
-
|
|
400
|
-
// src/types/dual-rules.ts
|
|
401
|
-
var DUAL_UNARY_RULES = {
|
|
402
|
-
exp: { primal: Math.exp, deriv: (_x, y) => y },
|
|
403
|
-
expm1: { primal: Math.expm1, deriv: (_x, y) => y + 1 },
|
|
404
|
-
log: { primal: Math.log, deriv: (x) => 1 / x },
|
|
405
|
-
log2: { primal: Math.log2, deriv: (x) => 1 / (x * Math.LN2) },
|
|
406
|
-
log10: { primal: Math.log10, deriv: (x) => 1 / (x * Math.LN10) },
|
|
407
|
-
log1p: { primal: Math.log1p, deriv: (x) => 1 / (1 + x) },
|
|
408
|
-
sin: { primal: Math.sin, deriv: (x) => Math.cos(x) },
|
|
409
|
-
cos: { primal: Math.cos, deriv: (x) => -Math.sin(x) },
|
|
410
|
-
tan: { primal: Math.tan, deriv: (x) => 1 / (Math.cos(x) * Math.cos(x)) },
|
|
411
|
-
asin: { primal: Math.asin, deriv: (x) => 1 / Math.sqrt(1 - x * x) },
|
|
412
|
-
acos: { primal: Math.acos, deriv: (x) => -1 / Math.sqrt(1 - x * x) },
|
|
413
|
-
atan: { primal: Math.atan, deriv: (x) => 1 / (1 + x * x) },
|
|
414
|
-
sinh: { primal: Math.sinh, deriv: (x) => Math.cosh(x) },
|
|
415
|
-
cosh: { primal: Math.cosh, deriv: (x) => Math.sinh(x) },
|
|
416
|
-
tanh: { primal: Math.tanh, deriv: (_x, y) => 1 - y * y },
|
|
417
|
-
asinh: { primal: Math.asinh, deriv: (x) => 1 / Math.sqrt(x * x + 1) },
|
|
418
|
-
acosh: { primal: Math.acosh, deriv: (x) => 1 / Math.sqrt(x * x - 1) },
|
|
419
|
-
atanh: { primal: Math.atanh, deriv: (x) => 1 / (1 - x * x) },
|
|
420
|
-
sqrt: { primal: Math.sqrt, deriv: (_x, y) => 1 / (2 * y) },
|
|
421
|
-
cbrt: { primal: Math.cbrt, deriv: (_x, y) => 1 / (3 * y * y) },
|
|
422
|
-
square: { primal: (x) => x * x, deriv: (x) => 2 * x },
|
|
423
|
-
reciprocal: { primal: (x) => 1 / x, deriv: (x) => -1 / (x * x) },
|
|
424
|
-
abs: { primal: Math.abs, deriv: (x) => Math.sign(x) },
|
|
425
|
-
sign: { primal: Math.sign, deriv: () => 0 }
|
|
1
|
+
import { $ as BIGNUMBER_LN2, A as irrationalPower, B as addScalar, Bn as I, C as decimalExactScale, D as exactScaleToNumber, E as exactScaleOf, F as ratioExactScale, G as multiplyScalar, H as equal, I as readScaleExpression, In as COMPLEX_NEG_ONE, J as round, K as number, L as DimensionMismatchError, Ln as COMPLEX_ONE, M as multiplyExactScales, N as namedIrrationalScale, O as exactScalesEqual, P as powerExactScale, Pn as isUnit$1, Q as BIGNUMBER_LN10, R as UnitParseError, Rn as COMPLEX_ZERO, S as clearExactScaleNumberCache, T as exactScaleNumberCacheSize, U as fix, V as divideScalar, Vn as isComplex, W as isNumeric, Y as subtractScalar, Yt as format, Z as BIGNUMBER_E, _ as NAMED_IRRATIONALS, _t as factory, a as UNIT_PREFIX_SETS, an as sign, at as BigNumber, b as addExactScales, c as getUnitPrefix, ct as FRACTION_NEG_ONE, d as readUnitScale, dt as FRACTION_THIRD, et as BIGNUMBER_NEG_ONE, f as unitPrefixExactScale, ft as FRACTION_ZERO, g as LN2_EXACT_SCALE, h as unitRowValue, hn as isBigNumber$2, i as NAMED_SCALES, it as BIGNUMBER_ZERO, j as isRationalScale, k as formatExactScale, l as getUnitRow, lt as FRACTION_ONE, m as unitRowExactScale, mn as isBigInt$1, mt as isFraction, nt as BIGNUMBER_PI, o as UNIT_ROWS, ot as isBigNumber, p as unitRowExactOffset, pt as Fraction, q as pow, rt as BIGNUMBER_TEN, s as UNIT_ROW_ALIASES, st as FRACTION_HALF, t as Unit, tn as nearlyEqual, tt as BIGNUMBER_ONE, u as namedExactScale, ut as FRACTION_QUARTER, v as PI_EXACT_SCALE, w as divideExactScales, x as binaryExactScale, y as UNIT_EXACT_SCALE, z as abs, zn as Complex } from "./unit-Dul_E1rh.js";
|
|
2
|
+
import typed, { create } from "typed-function";
|
|
3
|
+
const createRangeClass = /* #__PURE__ */ factory("Range", [], () => {
|
|
4
|
+
class Range {
|
|
5
|
+
type = "Range";
|
|
6
|
+
isRange = true;
|
|
7
|
+
start;
|
|
8
|
+
end;
|
|
9
|
+
step;
|
|
10
|
+
_cache = null;
|
|
11
|
+
_cacheStart;
|
|
12
|
+
_cacheEnd;
|
|
13
|
+
_cacheStep;
|
|
14
|
+
constructor(start, end, step) {
|
|
15
|
+
if (!(this instanceof Range)) throw new SyntaxError("Constructor must be called with the new operator");
|
|
16
|
+
const hasStart = start !== null && start !== void 0;
|
|
17
|
+
const hasEnd = end !== null && end !== void 0;
|
|
18
|
+
const hasStep = step !== null && step !== void 0;
|
|
19
|
+
let startValue = 0;
|
|
20
|
+
let endValue = 0;
|
|
21
|
+
let stepValue = 1;
|
|
22
|
+
if (hasStart) {
|
|
23
|
+
if (isBigNumber$2(start)) startValue = start.toNumber();
|
|
24
|
+
else if (typeof start !== "number" && !isBigInt$1(start)) throw new TypeError("Parameter start must be a number or bigint");
|
|
25
|
+
else startValue = start;
|
|
26
|
+
}
|
|
27
|
+
if (hasEnd) {
|
|
28
|
+
if (isBigNumber$2(end)) endValue = end.toNumber();
|
|
29
|
+
else if (typeof end !== "number" && !isBigInt$1(end)) throw new TypeError("Parameter end must be a number or bigint");
|
|
30
|
+
else endValue = end;
|
|
31
|
+
}
|
|
32
|
+
if (hasStep) {
|
|
33
|
+
if (isBigNumber$2(step)) stepValue = step.toNumber();
|
|
34
|
+
else if (typeof step !== "number" && !isBigInt$1(step)) throw new TypeError("Parameter step must be a number or bigint");
|
|
35
|
+
else stepValue = step;
|
|
36
|
+
}
|
|
37
|
+
this.start = hasStart ? parseFloat(startValue.toString()) : 0;
|
|
38
|
+
this.end = hasEnd ? parseFloat(endValue.toString()) : 0;
|
|
39
|
+
this.step = hasStep ? parseFloat(stepValue.toString()) : 1;
|
|
40
|
+
if (hasStep && nearlyEqual(this.step, 0)) throw new Error("Step must not be zero");
|
|
41
|
+
}
|
|
42
|
+
static parse(str) {
|
|
43
|
+
if (typeof str !== "string") return null;
|
|
44
|
+
const nums = str.split(":").map(function(arg) {
|
|
45
|
+
return parseFloat(arg);
|
|
46
|
+
});
|
|
47
|
+
if (nums.some(function(num) {
|
|
48
|
+
return isNaN(num);
|
|
49
|
+
})) return null;
|
|
50
|
+
switch (nums.length) {
|
|
51
|
+
case 2: return new Range(nums[0], nums[1]);
|
|
52
|
+
case 3: return new Range(nums[0], nums[2], nums[1]);
|
|
53
|
+
default: return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
clone() {
|
|
57
|
+
return new Range(this.start, this.end, this.step);
|
|
58
|
+
}
|
|
59
|
+
size() {
|
|
60
|
+
let len = 0;
|
|
61
|
+
const start = this.start;
|
|
62
|
+
const step = this.step;
|
|
63
|
+
const diff = this.end - start;
|
|
64
|
+
if (sign(step) === sign(diff)) len = Math.ceil(diff / step);
|
|
65
|
+
else if (diff === 0) len = 0;
|
|
66
|
+
if (isNaN(len)) len = 0;
|
|
67
|
+
return [len];
|
|
68
|
+
}
|
|
69
|
+
min() {
|
|
70
|
+
const size = this.size()[0];
|
|
71
|
+
if (size > 0) {
|
|
72
|
+
if (this.step > 0) return this.start;
|
|
73
|
+
else return this.start + (size - 1) * this.step;
|
|
74
|
+
} else return;
|
|
75
|
+
}
|
|
76
|
+
max() {
|
|
77
|
+
const size = this.size()[0];
|
|
78
|
+
if (size > 0) {
|
|
79
|
+
if (this.step > 0) return this.start + (size - 1) * this.step;
|
|
80
|
+
else return this.start;
|
|
81
|
+
} else return;
|
|
82
|
+
}
|
|
83
|
+
forEach(callback) {
|
|
84
|
+
let x = this.start;
|
|
85
|
+
const step = this.step;
|
|
86
|
+
const end = this.end;
|
|
87
|
+
let i = 0;
|
|
88
|
+
if (step > 0) while (x < end) {
|
|
89
|
+
callback(x, [i], this);
|
|
90
|
+
x += step;
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
else if (step < 0) while (x > end) {
|
|
94
|
+
callback(x, [i], this);
|
|
95
|
+
x += step;
|
|
96
|
+
i++;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
map(callback) {
|
|
100
|
+
const array = [];
|
|
101
|
+
this.forEach((value, index) => {
|
|
102
|
+
array[index[0]] = callback(value, index, this);
|
|
103
|
+
});
|
|
104
|
+
return array;
|
|
105
|
+
}
|
|
106
|
+
toArray() {
|
|
107
|
+
const array = [];
|
|
108
|
+
this.forEach(function(value, index) {
|
|
109
|
+
array[index[0]] = value;
|
|
110
|
+
});
|
|
111
|
+
return array;
|
|
112
|
+
}
|
|
113
|
+
valueOf() {
|
|
114
|
+
if (this._cache !== null && this.start === this._cacheStart && this.end === this._cacheEnd && this.step === this._cacheStep) return this._cache;
|
|
115
|
+
this._cache = this.toArray();
|
|
116
|
+
this._cacheStart = this.start;
|
|
117
|
+
this._cacheEnd = this.end;
|
|
118
|
+
this._cacheStep = this.step;
|
|
119
|
+
return this._cache;
|
|
120
|
+
}
|
|
121
|
+
format(options) {
|
|
122
|
+
let str = format(this.start, options);
|
|
123
|
+
if (this.step !== 1) str += ":" + format(this.step, options);
|
|
124
|
+
str += ":" + format(this.end, options);
|
|
125
|
+
return str;
|
|
126
|
+
}
|
|
127
|
+
toString() {
|
|
128
|
+
return this.format();
|
|
129
|
+
}
|
|
130
|
+
toJSON() {
|
|
131
|
+
return {
|
|
132
|
+
mathjs: "Range",
|
|
133
|
+
start: this.start,
|
|
134
|
+
end: this.end,
|
|
135
|
+
step: this.step
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
static fromJSON(json) {
|
|
139
|
+
return new Range(json.start, json.end, json.step);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return Range;
|
|
143
|
+
}, { isClass: true });
|
|
144
|
+
const Range = createRangeClass({});
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/types/dual-rules.ts
|
|
147
|
+
const DUAL_UNARY_RULES = {
|
|
148
|
+
exp: {
|
|
149
|
+
primal: Math.exp,
|
|
150
|
+
deriv: (_x, y) => y
|
|
151
|
+
},
|
|
152
|
+
expm1: {
|
|
153
|
+
primal: Math.expm1,
|
|
154
|
+
deriv: (_x, y) => y + 1
|
|
155
|
+
},
|
|
156
|
+
log: {
|
|
157
|
+
primal: Math.log,
|
|
158
|
+
deriv: (x) => 1 / x
|
|
159
|
+
},
|
|
160
|
+
log2: {
|
|
161
|
+
primal: Math.log2,
|
|
162
|
+
deriv: (x) => 1 / (x * Math.LN2)
|
|
163
|
+
},
|
|
164
|
+
log10: {
|
|
165
|
+
primal: Math.log10,
|
|
166
|
+
deriv: (x) => 1 / (x * Math.LN10)
|
|
167
|
+
},
|
|
168
|
+
log1p: {
|
|
169
|
+
primal: Math.log1p,
|
|
170
|
+
deriv: (x) => 1 / (1 + x)
|
|
171
|
+
},
|
|
172
|
+
sin: {
|
|
173
|
+
primal: Math.sin,
|
|
174
|
+
deriv: (x) => Math.cos(x)
|
|
175
|
+
},
|
|
176
|
+
cos: {
|
|
177
|
+
primal: Math.cos,
|
|
178
|
+
deriv: (x) => -Math.sin(x)
|
|
179
|
+
},
|
|
180
|
+
tan: {
|
|
181
|
+
primal: Math.tan,
|
|
182
|
+
deriv: (x) => 1 / (Math.cos(x) * Math.cos(x))
|
|
183
|
+
},
|
|
184
|
+
asin: {
|
|
185
|
+
primal: Math.asin,
|
|
186
|
+
deriv: (x) => 1 / Math.sqrt(1 - x * x)
|
|
187
|
+
},
|
|
188
|
+
acos: {
|
|
189
|
+
primal: Math.acos,
|
|
190
|
+
deriv: (x) => -1 / Math.sqrt(1 - x * x)
|
|
191
|
+
},
|
|
192
|
+
atan: {
|
|
193
|
+
primal: Math.atan,
|
|
194
|
+
deriv: (x) => 1 / (1 + x * x)
|
|
195
|
+
},
|
|
196
|
+
sinh: {
|
|
197
|
+
primal: Math.sinh,
|
|
198
|
+
deriv: (x) => Math.cosh(x)
|
|
199
|
+
},
|
|
200
|
+
cosh: {
|
|
201
|
+
primal: Math.cosh,
|
|
202
|
+
deriv: (x) => Math.sinh(x)
|
|
203
|
+
},
|
|
204
|
+
tanh: {
|
|
205
|
+
primal: Math.tanh,
|
|
206
|
+
deriv: (_x, y) => 1 - y * y
|
|
207
|
+
},
|
|
208
|
+
asinh: {
|
|
209
|
+
primal: Math.asinh,
|
|
210
|
+
deriv: (x) => 1 / Math.sqrt(x * x + 1)
|
|
211
|
+
},
|
|
212
|
+
acosh: {
|
|
213
|
+
primal: Math.acosh,
|
|
214
|
+
deriv: (x) => 1 / Math.sqrt(x * x - 1)
|
|
215
|
+
},
|
|
216
|
+
atanh: {
|
|
217
|
+
primal: Math.atanh,
|
|
218
|
+
deriv: (x) => 1 / (1 - x * x)
|
|
219
|
+
},
|
|
220
|
+
sqrt: {
|
|
221
|
+
primal: Math.sqrt,
|
|
222
|
+
deriv: (_x, y) => 1 / (2 * y)
|
|
223
|
+
},
|
|
224
|
+
cbrt: {
|
|
225
|
+
primal: Math.cbrt,
|
|
226
|
+
deriv: (_x, y) => 1 / (3 * y * y)
|
|
227
|
+
},
|
|
228
|
+
square: {
|
|
229
|
+
primal: (x) => x * x,
|
|
230
|
+
deriv: (x) => 2 * x
|
|
231
|
+
},
|
|
232
|
+
reciprocal: {
|
|
233
|
+
primal: (x) => 1 / x,
|
|
234
|
+
deriv: (x) => -1 / (x * x)
|
|
235
|
+
},
|
|
236
|
+
abs: {
|
|
237
|
+
primal: Math.abs,
|
|
238
|
+
deriv: (x) => Math.sign(x)
|
|
239
|
+
},
|
|
240
|
+
sign: {
|
|
241
|
+
primal: Math.sign,
|
|
242
|
+
deriv: () => 0
|
|
243
|
+
}
|
|
426
244
|
};
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
var Dual = class
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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
|
-
return this.unary(DUAL_UNARY_RULES.sinh);
|
|
507
|
-
}
|
|
508
|
-
cosh() {
|
|
509
|
-
return this.unary(DUAL_UNARY_RULES.cosh);
|
|
510
|
-
}
|
|
511
|
-
tanh() {
|
|
512
|
-
return this.unary(DUAL_UNARY_RULES.tanh);
|
|
513
|
-
}
|
|
514
|
-
toString() {
|
|
515
|
-
return `Dual(${this.value}, ${this.deriv})`;
|
|
516
|
-
}
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/types/dual.ts
|
|
247
|
+
var Dual = class Dual {
|
|
248
|
+
value;
|
|
249
|
+
deriv;
|
|
250
|
+
constructor(value, deriv = 0) {
|
|
251
|
+
this.value = value;
|
|
252
|
+
this.deriv = deriv;
|
|
253
|
+
}
|
|
254
|
+
static constant(v) {
|
|
255
|
+
return new Dual(v, 0);
|
|
256
|
+
}
|
|
257
|
+
static variable(v) {
|
|
258
|
+
return new Dual(v, 1);
|
|
259
|
+
}
|
|
260
|
+
add(o) {
|
|
261
|
+
return new Dual(this.value + o.value, this.deriv + o.deriv);
|
|
262
|
+
}
|
|
263
|
+
sub(o) {
|
|
264
|
+
return new Dual(this.value - o.value, this.deriv - o.deriv);
|
|
265
|
+
}
|
|
266
|
+
mul(o) {
|
|
267
|
+
return new Dual(this.value * o.value, this.deriv * o.value + this.value * o.deriv);
|
|
268
|
+
}
|
|
269
|
+
div(o) {
|
|
270
|
+
const d = (this.deriv * o.value - this.value * o.deriv) / (o.value * o.value);
|
|
271
|
+
return new Dual(this.value / o.value, d);
|
|
272
|
+
}
|
|
273
|
+
neg() {
|
|
274
|
+
return new Dual(-this.value, -this.deriv);
|
|
275
|
+
}
|
|
276
|
+
powConst(k) {
|
|
277
|
+
return new Dual(Math.pow(this.value, k), this.deriv * k * Math.pow(this.value, k - 1));
|
|
278
|
+
}
|
|
279
|
+
pow(o) {
|
|
280
|
+
const v = Math.pow(this.value, o.value);
|
|
281
|
+
const d = v * (o.deriv * Math.log(this.value) + o.value * this.deriv / this.value);
|
|
282
|
+
return new Dual(v, d);
|
|
283
|
+
}
|
|
284
|
+
unary(rule) {
|
|
285
|
+
const y = rule.primal(this.value);
|
|
286
|
+
return new Dual(y, this.deriv * rule.deriv(this.value, y));
|
|
287
|
+
}
|
|
288
|
+
sin() {
|
|
289
|
+
return this.unary(DUAL_UNARY_RULES.sin);
|
|
290
|
+
}
|
|
291
|
+
cos() {
|
|
292
|
+
return this.unary(DUAL_UNARY_RULES.cos);
|
|
293
|
+
}
|
|
294
|
+
tan() {
|
|
295
|
+
return this.unary(DUAL_UNARY_RULES.tan);
|
|
296
|
+
}
|
|
297
|
+
exp() {
|
|
298
|
+
return this.unary(DUAL_UNARY_RULES.exp);
|
|
299
|
+
}
|
|
300
|
+
log() {
|
|
301
|
+
return this.unary(DUAL_UNARY_RULES.log);
|
|
302
|
+
}
|
|
303
|
+
sqrt() {
|
|
304
|
+
return this.unary(DUAL_UNARY_RULES.sqrt);
|
|
305
|
+
}
|
|
306
|
+
square() {
|
|
307
|
+
return this.unary(DUAL_UNARY_RULES.square);
|
|
308
|
+
}
|
|
309
|
+
abs() {
|
|
310
|
+
return this.unary(DUAL_UNARY_RULES.abs);
|
|
311
|
+
}
|
|
312
|
+
sinh() {
|
|
313
|
+
return this.unary(DUAL_UNARY_RULES.sinh);
|
|
314
|
+
}
|
|
315
|
+
cosh() {
|
|
316
|
+
return this.unary(DUAL_UNARY_RULES.cosh);
|
|
317
|
+
}
|
|
318
|
+
tanh() {
|
|
319
|
+
return this.unary(DUAL_UNARY_RULES.tanh);
|
|
320
|
+
}
|
|
321
|
+
toString() {
|
|
322
|
+
return `Dual(${this.value}, ${this.deriv})`;
|
|
323
|
+
}
|
|
517
324
|
};
|
|
518
325
|
function isDual(x) {
|
|
519
|
-
|
|
326
|
+
return x instanceof Dual;
|
|
520
327
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/constants.ts
|
|
330
|
+
const PI = Math.PI;
|
|
331
|
+
const E = Math.E;
|
|
332
|
+
const TAU = 2 * Math.PI;
|
|
333
|
+
const PHI = (1 + Math.sqrt(5)) / 2;
|
|
334
|
+
const SQRT2 = Math.SQRT2;
|
|
335
|
+
const SQRT1_2 = Math.SQRT1_2;
|
|
336
|
+
const LN2 = Math.LN2;
|
|
337
|
+
const LN10 = Math.LN10;
|
|
338
|
+
const LOG2E = Math.LOG2E;
|
|
339
|
+
const LOG10E = Math.LOG10E;
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/types/unit-definitions.ts
|
|
342
|
+
const DIMENSIONLESS = Object.freeze({
|
|
343
|
+
length: 0,
|
|
344
|
+
mass: 0,
|
|
345
|
+
time: 0,
|
|
346
|
+
current: 0,
|
|
347
|
+
temperature: 0,
|
|
348
|
+
amount: 0,
|
|
349
|
+
luminosity: 0
|
|
543
350
|
});
|
|
544
351
|
function dim(partial) {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
352
|
+
return {
|
|
353
|
+
length: partial.length ?? 0,
|
|
354
|
+
mass: partial.mass ?? 0,
|
|
355
|
+
time: partial.time ?? 0,
|
|
356
|
+
current: partial.current ?? 0,
|
|
357
|
+
temperature: partial.temperature ?? 0,
|
|
358
|
+
amount: partial.amount ?? 0,
|
|
359
|
+
luminosity: partial.luminosity ?? 0
|
|
360
|
+
};
|
|
554
361
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
362
|
+
const BASE_UNITS = {
|
|
363
|
+
m: {
|
|
364
|
+
multiplier: 1,
|
|
365
|
+
dimensions: dim({ length: 1 }),
|
|
366
|
+
prefixable: true
|
|
367
|
+
},
|
|
368
|
+
kg: {
|
|
369
|
+
multiplier: 1,
|
|
370
|
+
dimensions: dim({ mass: 1 })
|
|
371
|
+
},
|
|
372
|
+
s: {
|
|
373
|
+
multiplier: 1,
|
|
374
|
+
dimensions: dim({ time: 1 }),
|
|
375
|
+
prefixable: true
|
|
376
|
+
},
|
|
377
|
+
A: {
|
|
378
|
+
multiplier: 1,
|
|
379
|
+
dimensions: dim({ current: 1 }),
|
|
380
|
+
prefixable: true
|
|
381
|
+
},
|
|
382
|
+
K: {
|
|
383
|
+
multiplier: 1,
|
|
384
|
+
dimensions: dim({ temperature: 1 }),
|
|
385
|
+
prefixable: true
|
|
386
|
+
},
|
|
387
|
+
mol: {
|
|
388
|
+
multiplier: 1,
|
|
389
|
+
dimensions: dim({ amount: 1 }),
|
|
390
|
+
prefixable: true
|
|
391
|
+
},
|
|
392
|
+
cd: {
|
|
393
|
+
multiplier: 1,
|
|
394
|
+
dimensions: dim({ luminosity: 1 }),
|
|
395
|
+
prefixable: true
|
|
396
|
+
}
|
|
565
397
|
};
|
|
566
|
-
function tableUnit(
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
398
|
+
function tableUnit(name, dimensions, prefixable) {
|
|
399
|
+
const row = getUnitRow(name);
|
|
400
|
+
if (row === void 0) throw new Error(`unit-definitions: '${name}' is not in the unit table`);
|
|
401
|
+
const scale = readUnitScale(row.scale);
|
|
402
|
+
const def = {
|
|
403
|
+
multiplier: exactScaleToNumber(scale),
|
|
404
|
+
dimensions
|
|
405
|
+
};
|
|
406
|
+
if (row.offset !== void 0) def.offset = exactScaleToNumber(multiplyExactScales(scale, readUnitScale(row.offset)));
|
|
407
|
+
if (prefixable) def.prefixable = true;
|
|
408
|
+
return def;
|
|
576
409
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
410
|
+
const DERIVED_UNITS = {
|
|
411
|
+
ft: tableUnit("ft", dim({ length: 1 })),
|
|
412
|
+
foot: tableUnit("foot", dim({ length: 1 })),
|
|
413
|
+
in: tableUnit("in", dim({ length: 1 })),
|
|
414
|
+
inch: tableUnit("inch", dim({ length: 1 })),
|
|
415
|
+
yd: tableUnit("yd", dim({ length: 1 })),
|
|
416
|
+
yard: tableUnit("yard", dim({ length: 1 })),
|
|
417
|
+
mi: tableUnit("mi", dim({ length: 1 })),
|
|
418
|
+
mile: tableUnit("mile", dim({ length: 1 })),
|
|
419
|
+
g: tableUnit("g", dim({ mass: 1 }), true),
|
|
420
|
+
lb: tableUnit("lb", dim({ mass: 1 })),
|
|
421
|
+
lbm: tableUnit("lbm", dim({ mass: 1 })),
|
|
422
|
+
oz: tableUnit("oz", dim({ mass: 1 })),
|
|
423
|
+
ton: tableUnit("ton", dim({ mass: 1 })),
|
|
424
|
+
tonne: tableUnit("tonne", dim({ mass: 1 })),
|
|
425
|
+
min: tableUnit("min", dim({ time: 1 })),
|
|
426
|
+
h: tableUnit("h", dim({ time: 1 })),
|
|
427
|
+
hr: tableUnit("hr", dim({ time: 1 })),
|
|
428
|
+
day: tableUnit("day", dim({ time: 1 })),
|
|
429
|
+
week: tableUnit("week", dim({ time: 1 })),
|
|
430
|
+
year: tableUnit("year", dim({ time: 1 })),
|
|
431
|
+
degC: tableUnit("degC", dim({ temperature: 1 })),
|
|
432
|
+
degF: tableUnit("degF", dim({ temperature: 1 })),
|
|
433
|
+
degR: tableUnit("degR", dim({ temperature: 1 })),
|
|
434
|
+
rad: tableUnit("rad", dim({}), true),
|
|
435
|
+
deg: tableUnit("deg", dim({})),
|
|
436
|
+
grad: tableUnit("grad", dim({})),
|
|
437
|
+
N: tableUnit("N", dim({
|
|
438
|
+
length: 1,
|
|
439
|
+
mass: 1,
|
|
440
|
+
time: -2
|
|
441
|
+
}), true),
|
|
442
|
+
dyn: tableUnit("dyn", dim({
|
|
443
|
+
length: 1,
|
|
444
|
+
mass: 1,
|
|
445
|
+
time: -2
|
|
446
|
+
})),
|
|
447
|
+
lbf: tableUnit("lbf", dim({
|
|
448
|
+
length: 1,
|
|
449
|
+
mass: 1,
|
|
450
|
+
time: -2
|
|
451
|
+
})),
|
|
452
|
+
J: tableUnit("J", dim({
|
|
453
|
+
length: 2,
|
|
454
|
+
mass: 1,
|
|
455
|
+
time: -2
|
|
456
|
+
}), true),
|
|
457
|
+
erg: tableUnit("erg", dim({
|
|
458
|
+
length: 2,
|
|
459
|
+
mass: 1,
|
|
460
|
+
time: -2
|
|
461
|
+
})),
|
|
462
|
+
cal: tableUnit("cal", dim({
|
|
463
|
+
length: 2,
|
|
464
|
+
mass: 1,
|
|
465
|
+
time: -2
|
|
466
|
+
})),
|
|
467
|
+
eV: tableUnit("eV", dim({
|
|
468
|
+
length: 2,
|
|
469
|
+
mass: 1,
|
|
470
|
+
time: -2
|
|
471
|
+
}), true),
|
|
472
|
+
BTU: tableUnit("BTU", dim({
|
|
473
|
+
length: 2,
|
|
474
|
+
mass: 1,
|
|
475
|
+
time: -2
|
|
476
|
+
})),
|
|
477
|
+
W: tableUnit("W", dim({
|
|
478
|
+
length: 2,
|
|
479
|
+
mass: 1,
|
|
480
|
+
time: -3
|
|
481
|
+
}), true),
|
|
482
|
+
hp: tableUnit("hp", dim({
|
|
483
|
+
length: 2,
|
|
484
|
+
mass: 1,
|
|
485
|
+
time: -3
|
|
486
|
+
})),
|
|
487
|
+
Pa: tableUnit("Pa", dim({
|
|
488
|
+
length: -1,
|
|
489
|
+
mass: 1,
|
|
490
|
+
time: -2
|
|
491
|
+
}), true),
|
|
492
|
+
bar: tableUnit("bar", dim({
|
|
493
|
+
length: -1,
|
|
494
|
+
mass: 1,
|
|
495
|
+
time: -2
|
|
496
|
+
}), true),
|
|
497
|
+
atm: tableUnit("atm", dim({
|
|
498
|
+
length: -1,
|
|
499
|
+
mass: 1,
|
|
500
|
+
time: -2
|
|
501
|
+
})),
|
|
502
|
+
psi: tableUnit("psi", dim({
|
|
503
|
+
length: -1,
|
|
504
|
+
mass: 1,
|
|
505
|
+
time: -2
|
|
506
|
+
})),
|
|
507
|
+
torr: tableUnit("torr", dim({
|
|
508
|
+
length: -1,
|
|
509
|
+
mass: 1,
|
|
510
|
+
time: -2
|
|
511
|
+
})),
|
|
512
|
+
mmHg: tableUnit("mmHg", dim({
|
|
513
|
+
length: -1,
|
|
514
|
+
mass: 1,
|
|
515
|
+
time: -2
|
|
516
|
+
})),
|
|
517
|
+
C: tableUnit("C", dim({
|
|
518
|
+
time: 1,
|
|
519
|
+
current: 1
|
|
520
|
+
}), true),
|
|
521
|
+
V: tableUnit("V", dim({
|
|
522
|
+
length: 2,
|
|
523
|
+
mass: 1,
|
|
524
|
+
time: -3,
|
|
525
|
+
current: -1
|
|
526
|
+
}), true),
|
|
527
|
+
ohm: tableUnit("ohm", dim({
|
|
528
|
+
length: 2,
|
|
529
|
+
mass: 1,
|
|
530
|
+
time: -3,
|
|
531
|
+
current: -2
|
|
532
|
+
}), true),
|
|
533
|
+
Ω: tableUnit("ohm", dim({
|
|
534
|
+
length: 2,
|
|
535
|
+
mass: 1,
|
|
536
|
+
time: -3,
|
|
537
|
+
current: -2
|
|
538
|
+
}), true),
|
|
539
|
+
F: tableUnit("F", dim({
|
|
540
|
+
length: -2,
|
|
541
|
+
mass: -1,
|
|
542
|
+
time: 4,
|
|
543
|
+
current: 2
|
|
544
|
+
}), true),
|
|
545
|
+
H: tableUnit("H", dim({
|
|
546
|
+
length: 2,
|
|
547
|
+
mass: 1,
|
|
548
|
+
time: -2,
|
|
549
|
+
current: -2
|
|
550
|
+
}), true),
|
|
551
|
+
Hz: tableUnit("Hz", dim({ time: -1 }), true),
|
|
552
|
+
L: tableUnit("L", dim({ length: 3 }), true),
|
|
553
|
+
l: tableUnit("l", dim({ length: 3 }), true),
|
|
554
|
+
gal: tableUnit("gal", dim({ length: 3 })),
|
|
555
|
+
ha: tableUnit("hectare", dim({ length: 2 })),
|
|
556
|
+
acre: tableUnit("acre", dim({ length: 2 }))
|
|
557
|
+
};
|
|
558
|
+
const ALL_UNITS = {
|
|
559
|
+
...BASE_UNITS,
|
|
560
|
+
...DERIVED_UNITS
|
|
659
561
|
};
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
"\xB0": "deg"
|
|
666
|
-
// The Unicode micro sign is handled in prefixes; °K is non-standard.
|
|
562
|
+
const UNIT_ALIASES = {
|
|
563
|
+
"°C": "degC",
|
|
564
|
+
"°F": "degF",
|
|
565
|
+
"°R": "degR",
|
|
566
|
+
"°": "deg"
|
|
667
567
|
};
|
|
668
|
-
function getUnitDef(
|
|
669
|
-
|
|
568
|
+
function getUnitDef(name) {
|
|
569
|
+
return ALL_UNITS[name];
|
|
670
570
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region src/types/si-dimension-vector.ts
|
|
573
|
+
const UNIT_DIMENSION_LENGTH = 10;
|
|
574
|
+
const SI_DIMENSION_LENGTH = 7;
|
|
575
|
+
const EXTRA_INDEXES = [
|
|
576
|
+
7,
|
|
577
|
+
8,
|
|
578
|
+
9
|
|
579
|
+
];
|
|
676
580
|
function assertFinite(label, value) {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
581
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new TypeError(`${label} must be a finite number`);
|
|
582
|
+
}
|
|
583
|
+
function numberToFractionExponent(value, label = "exponent") {
|
|
584
|
+
assertFinite(label, value);
|
|
585
|
+
if (Number.isInteger(value)) return new Fraction(BigInt(value), 1n);
|
|
586
|
+
return Fraction.fromNumber(value);
|
|
587
|
+
}
|
|
588
|
+
function siExponentToFraction(value, label = "exponent") {
|
|
589
|
+
if (isFraction(value)) return value;
|
|
590
|
+
return numberToFractionExponent(value, label);
|
|
680
591
|
}
|
|
681
592
|
function assertUnitVector(vector) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
for (let i = 0; i < vector.length; i++) {
|
|
686
|
-
assertFinite(`dimension vector[${i}]`, vector[i]);
|
|
687
|
-
}
|
|
593
|
+
if (vector.length !== 10) throw new TypeError(`dimension vector must have length 10`);
|
|
594
|
+
for (let i = 0; i < vector.length; i++) assertFinite(`dimension vector[${i}]`, vector[i]);
|
|
688
595
|
}
|
|
689
596
|
function rejectExtra(vector, options) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
if (vector[index] !== 0) {
|
|
693
|
-
throw new RangeError(
|
|
694
|
-
`dimension vector has a nonzero angle, bit, or solid-angle exponent at index ${index}; pass { ignoreExtra: true } to drop it`
|
|
695
|
-
);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
597
|
+
if (options?.ignoreExtra) return;
|
|
598
|
+
for (const index of EXTRA_INDEXES) if (vector[index] !== 0) throw new RangeError(`dimension vector has a nonzero angle, bit, or solid-angle exponent at index ${index}; pass { ignoreExtra: true } to drop it`);
|
|
698
599
|
}
|
|
699
600
|
function toSiDimensions(vector, options) {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
601
|
+
assertUnitVector(vector);
|
|
602
|
+
rejectExtra(vector, options);
|
|
603
|
+
return {
|
|
604
|
+
length: vector[1],
|
|
605
|
+
mass: vector[0],
|
|
606
|
+
time: vector[2],
|
|
607
|
+
current: vector[3],
|
|
608
|
+
temperature: vector[4],
|
|
609
|
+
amount: vector[6],
|
|
610
|
+
luminosity: vector[5]
|
|
611
|
+
};
|
|
711
612
|
}
|
|
712
613
|
function toSiDimensionVector(vector, options) {
|
|
713
|
-
|
|
714
|
-
|
|
614
|
+
const d = toSiDimensions(vector, options);
|
|
615
|
+
return [
|
|
616
|
+
numberToFractionExponent(d.length),
|
|
617
|
+
numberToFractionExponent(d.mass),
|
|
618
|
+
numberToFractionExponent(d.time),
|
|
619
|
+
numberToFractionExponent(d.current),
|
|
620
|
+
numberToFractionExponent(d.temperature),
|
|
621
|
+
numberToFractionExponent(d.amount),
|
|
622
|
+
numberToFractionExponent(d.luminosity)
|
|
623
|
+
];
|
|
715
624
|
}
|
|
716
625
|
function fromSiDimensions(dimensions) {
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
0
|
|
740
|
-
];
|
|
626
|
+
const fields = [
|
|
627
|
+
["mass", dimensions.mass],
|
|
628
|
+
["length", dimensions.length],
|
|
629
|
+
["time", dimensions.time],
|
|
630
|
+
["current", dimensions.current],
|
|
631
|
+
["temperature", dimensions.temperature],
|
|
632
|
+
["luminosity", dimensions.luminosity],
|
|
633
|
+
["amount", dimensions.amount]
|
|
634
|
+
];
|
|
635
|
+
for (const [name, value] of fields) assertFinite(`dimensions.${name}`, value);
|
|
636
|
+
return [
|
|
637
|
+
dimensions.mass,
|
|
638
|
+
dimensions.length,
|
|
639
|
+
dimensions.time,
|
|
640
|
+
dimensions.current,
|
|
641
|
+
dimensions.temperature,
|
|
642
|
+
dimensions.luminosity,
|
|
643
|
+
dimensions.amount,
|
|
644
|
+
0,
|
|
645
|
+
0,
|
|
646
|
+
0
|
|
647
|
+
];
|
|
741
648
|
}
|
|
742
649
|
function fromSiDimensionVector(vector) {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
650
|
+
if (vector.length !== 7) throw new TypeError(`SI dimension vector must have length 7 [L, M, T, I, Θ, N, J]`);
|
|
651
|
+
const nums = vector.map((component, i) => {
|
|
652
|
+
const label = `SI dimension vector[${i}]`;
|
|
653
|
+
const n = siExponentToFraction(component, label).toNumber();
|
|
654
|
+
assertFinite(label, n);
|
|
655
|
+
return n;
|
|
656
|
+
});
|
|
657
|
+
return fromSiDimensions({
|
|
658
|
+
length: nums[0],
|
|
659
|
+
mass: nums[1],
|
|
660
|
+
time: nums[2],
|
|
661
|
+
current: nums[3],
|
|
662
|
+
temperature: nums[4],
|
|
663
|
+
amount: nums[5],
|
|
664
|
+
luminosity: nums[6]
|
|
665
|
+
});
|
|
757
666
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/types/unit-prefixes.ts
|
|
669
|
+
const SI_PREFIXES = (() => {
|
|
670
|
+
const prefixes = {};
|
|
671
|
+
const short = UNIT_PREFIX_SETS.SHORT;
|
|
672
|
+
for (const name of Object.keys(short)) {
|
|
673
|
+
if (name === "") continue;
|
|
674
|
+
prefixes[name] = exactScaleToNumber(unitPrefixExactScale(short[name]));
|
|
675
|
+
}
|
|
676
|
+
prefixes["µ"] = prefixes.u;
|
|
677
|
+
return prefixes;
|
|
769
678
|
})();
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
679
|
+
const BEST_PREFIXES = [
|
|
680
|
+
"Y",
|
|
681
|
+
"Z",
|
|
682
|
+
"E",
|
|
683
|
+
"P",
|
|
684
|
+
"T",
|
|
685
|
+
"G",
|
|
686
|
+
"M",
|
|
687
|
+
"k",
|
|
688
|
+
"",
|
|
689
|
+
"m",
|
|
690
|
+
"u",
|
|
691
|
+
"n",
|
|
692
|
+
"p",
|
|
693
|
+
"f",
|
|
694
|
+
"a",
|
|
695
|
+
"z",
|
|
696
|
+
"y"
|
|
788
697
|
];
|
|
789
|
-
function getPrefix(
|
|
790
|
-
|
|
698
|
+
function getPrefix(name) {
|
|
699
|
+
return SI_PREFIXES[name];
|
|
791
700
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
var wasmAvailable = false;
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region src/typed/mathts-typed.ts
|
|
703
|
+
let wasmInitialized = false;
|
|
704
|
+
let wasmAvailable = false;
|
|
797
705
|
async function initTypedWasm(options = {}) {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
706
|
+
if (wasmInitialized) return wasmAvailable;
|
|
707
|
+
try {
|
|
708
|
+
if (typeof typed.init === "function") {
|
|
709
|
+
await typed.init({ preferWasm: options.preferWasm ?? true });
|
|
710
|
+
wasmAvailable = typed.isWasmEnabled?.() ?? false;
|
|
711
|
+
}
|
|
712
|
+
} catch {
|
|
713
|
+
wasmAvailable = false;
|
|
714
|
+
}
|
|
715
|
+
wasmInitialized = true;
|
|
716
|
+
return wasmAvailable;
|
|
809
717
|
}
|
|
810
718
|
function isTypedWasmAvailable() {
|
|
811
|
-
|
|
719
|
+
return typed.isWasmEnabled?.() ?? wasmAvailable;
|
|
812
720
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
721
|
+
const isNumber = (x) => typeof x === "number";
|
|
722
|
+
const isBoolean = (x) => typeof x === "boolean";
|
|
723
|
+
const isString = (x) => typeof x === "string";
|
|
724
|
+
const isBigInt = (x) => typeof x === "bigint";
|
|
725
|
+
const isArray = (x) => Array.isArray(x);
|
|
726
|
+
const isFunction = (x) => typeof x === "function";
|
|
727
|
+
const isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
728
|
+
const isNull = (x) => x === null;
|
|
729
|
+
const isUndefined = (x) => x === void 0;
|
|
730
|
+
const isFloat64Array = (x) => x instanceof Float64Array;
|
|
731
|
+
const isFloat32Array = (x) => x instanceof Float32Array;
|
|
732
|
+
const isInt32Array = (x) => x instanceof Int32Array;
|
|
733
|
+
const isUint32Array = (x) => x instanceof Uint32Array;
|
|
734
|
+
const isUint8Array = (x) => x instanceof Uint8Array;
|
|
735
|
+
const isComplex$1 = (x) => isComplex(x);
|
|
736
|
+
const isFraction$1 = (x) => isFraction(x);
|
|
737
|
+
const isBigNumber$1 = (x) => isBigNumber(x);
|
|
738
|
+
const isMatrix = (x) => isObject(x) && "rows" in x && "cols" in x && "get" in x && typeof x.type === "string";
|
|
739
|
+
const isDenseMatrix = (x) => isMatrix(x) && x.type === "DenseMatrix";
|
|
740
|
+
const isSparseMatrix = (x) => isMatrix(x) && x.type === "SparseMatrix";
|
|
741
|
+
const isUnit = (x) => {
|
|
742
|
+
if (!isObject(x)) return false;
|
|
743
|
+
const o = x;
|
|
744
|
+
if (typeof o.type !== "string") return false;
|
|
745
|
+
if (o.type === "Unit" && "value" in o && "dimensions" in o) return true;
|
|
746
|
+
if ("value" in o && "unit" in o) return true;
|
|
747
|
+
return false;
|
|
840
748
|
};
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
749
|
+
const MATHTS_TYPES = [
|
|
750
|
+
{
|
|
751
|
+
name: "bigint",
|
|
752
|
+
test: isBigInt
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
name: "Complex",
|
|
756
|
+
test: isComplex$1
|
|
757
|
+
},
|
|
758
|
+
{
|
|
759
|
+
name: "Fraction",
|
|
760
|
+
test: isFraction$1
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
name: "BigNumber",
|
|
764
|
+
test: isBigNumber$1
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
name: "Float64Array",
|
|
768
|
+
test: isFloat64Array
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
name: "Float32Array",
|
|
772
|
+
test: isFloat32Array
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
name: "Int32Array",
|
|
776
|
+
test: isInt32Array
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
name: "Uint32Array",
|
|
780
|
+
test: isUint32Array
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
name: "Uint8Array",
|
|
784
|
+
test: isUint8Array
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
name: "DenseMatrix",
|
|
788
|
+
test: isDenseMatrix
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
name: "SparseMatrix",
|
|
792
|
+
test: isSparseMatrix
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
name: "Matrix",
|
|
796
|
+
test: isMatrix
|
|
797
|
+
},
|
|
798
|
+
{
|
|
799
|
+
name: "Unit",
|
|
800
|
+
test: isUnit
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
name: "Dual",
|
|
804
|
+
test: isDual
|
|
805
|
+
}
|
|
862
806
|
];
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
const result = [];
|
|
1006
|
-
for (let i = 0; i < matrix.rows; i++) {
|
|
1007
|
-
result[i] = [];
|
|
1008
|
-
for (let j = 0; j < matrix.cols; j++) {
|
|
1009
|
-
result[i][j] = matrix.get(i, j);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
return result;
|
|
1013
|
-
}
|
|
1014
|
-
},
|
|
1015
|
-
{
|
|
1016
|
-
from: "DenseMatrix",
|
|
1017
|
-
to: "SparseMatrix",
|
|
1018
|
-
convert: (m) => {
|
|
1019
|
-
return { ...m, type: "SparseMatrix" };
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
807
|
+
const MATHTS_CONVERSIONS = [
|
|
808
|
+
{
|
|
809
|
+
from: "number",
|
|
810
|
+
to: "Complex",
|
|
811
|
+
convert: (n) => Complex.fromNumber(n)
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
from: "Fraction",
|
|
815
|
+
to: "Complex",
|
|
816
|
+
convert: (f) => Complex.fromNumber(f.toNumber())
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
from: "BigNumber",
|
|
820
|
+
to: "Complex",
|
|
821
|
+
convert: (bn) => Complex.fromNumber(bn.valueOf())
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
from: "string",
|
|
825
|
+
to: "Complex",
|
|
826
|
+
convert: (s) => Complex.parse(s)
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
from: "number",
|
|
830
|
+
to: "Fraction",
|
|
831
|
+
convert: (n) => Fraction.fromNumber(n)
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
from: "bigint",
|
|
835
|
+
to: "Fraction",
|
|
836
|
+
convert: (n) => new Fraction(n, 1n)
|
|
837
|
+
},
|
|
838
|
+
{
|
|
839
|
+
from: "string",
|
|
840
|
+
to: "Fraction",
|
|
841
|
+
convert: (s) => Fraction.parse(s)
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
from: "number",
|
|
845
|
+
to: "BigNumber",
|
|
846
|
+
convert: (n) => BigNumber.fromNumber(n)
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
from: "bigint",
|
|
850
|
+
to: "BigNumber",
|
|
851
|
+
convert: (n) => BigNumber.fromBigInt(n)
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
from: "Fraction",
|
|
855
|
+
to: "BigNumber",
|
|
856
|
+
convert: (f) => BigNumber.fromNumber(f.toNumber())
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
from: "string",
|
|
860
|
+
to: "BigNumber",
|
|
861
|
+
convert: (s) => BigNumber.parse(s)
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
from: "boolean",
|
|
865
|
+
to: "number",
|
|
866
|
+
convert: (b) => b ? 1 : 0
|
|
867
|
+
},
|
|
868
|
+
{
|
|
869
|
+
from: "string",
|
|
870
|
+
to: "number",
|
|
871
|
+
convert: (s) => {
|
|
872
|
+
const n = parseFloat(s);
|
|
873
|
+
if (isNaN(n)) throw new Error(`Cannot convert "${s}" to number`);
|
|
874
|
+
return n;
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
{
|
|
878
|
+
from: "bigint",
|
|
879
|
+
to: "number",
|
|
880
|
+
convert: (n) => Number(n)
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
from: "Fraction",
|
|
884
|
+
to: "number",
|
|
885
|
+
convert: (f) => f.toNumber()
|
|
886
|
+
},
|
|
887
|
+
{
|
|
888
|
+
from: "BigNumber",
|
|
889
|
+
to: "number",
|
|
890
|
+
convert: (bn) => bn.valueOf()
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
from: "number",
|
|
894
|
+
to: "bigint",
|
|
895
|
+
convert: (n) => BigInt(Math.trunc(n))
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
from: "Fraction",
|
|
899
|
+
to: "bigint",
|
|
900
|
+
convert: (f) => f.trunc().numerator
|
|
901
|
+
},
|
|
902
|
+
{
|
|
903
|
+
from: "BigNumber",
|
|
904
|
+
to: "bigint",
|
|
905
|
+
convert: (bn) => bn.toBigInt()
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
from: "string",
|
|
909
|
+
to: "bigint",
|
|
910
|
+
convert: (s) => BigInt(s)
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
from: "Array",
|
|
914
|
+
to: "Matrix",
|
|
915
|
+
convert: (a) => {
|
|
916
|
+
const arr = a;
|
|
917
|
+
return {
|
|
918
|
+
rows: arr.length,
|
|
919
|
+
cols: arr[0]?.length ?? 0,
|
|
920
|
+
data: arr.flat(),
|
|
921
|
+
type: "DenseMatrix",
|
|
922
|
+
get: (r, c) => arr[r]?.[c]
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
from: "Matrix",
|
|
928
|
+
to: "Array",
|
|
929
|
+
convert: (m) => {
|
|
930
|
+
const matrix = m;
|
|
931
|
+
const result = [];
|
|
932
|
+
for (let i = 0; i < matrix.rows; i++) {
|
|
933
|
+
result[i] = [];
|
|
934
|
+
for (let j = 0; j < matrix.cols; j++) result[i][j] = matrix.get(i, j);
|
|
935
|
+
}
|
|
936
|
+
return result;
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
{
|
|
940
|
+
from: "DenseMatrix",
|
|
941
|
+
to: "SparseMatrix",
|
|
942
|
+
convert: (m) => {
|
|
943
|
+
return {
|
|
944
|
+
...m,
|
|
945
|
+
type: "SparseMatrix"
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
}
|
|
1022
949
|
];
|
|
1023
950
|
function createMathTSTyped() {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
} else {
|
|
1030
|
-
instance.addTypes(MATHTS_TYPES, "any");
|
|
1031
|
-
}
|
|
1032
|
-
instance.addConversions(MATHTS_CONVERSIONS);
|
|
1033
|
-
return instance;
|
|
951
|
+
const instance = create();
|
|
952
|
+
if (typeof instance.addType === "function") for (const typeDef of MATHTS_TYPES) instance.addType(typeDef);
|
|
953
|
+
else instance.addTypes(MATHTS_TYPES, "any");
|
|
954
|
+
instance.addConversions(MATHTS_CONVERSIONS);
|
|
955
|
+
return instance;
|
|
1034
956
|
}
|
|
1035
|
-
|
|
957
|
+
const mathTyped = createMathTSTyped();
|
|
1036
958
|
var TypeRegistry = class {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
*/
|
|
1082
|
-
build() {
|
|
1083
|
-
if (!this.instance) {
|
|
1084
|
-
const inst = create();
|
|
1085
|
-
inst.addTypes(Array.from(this.types.values()), "any");
|
|
1086
|
-
inst.addConversions(Array.from(this.conversions.values()));
|
|
1087
|
-
this.instance = inst;
|
|
1088
|
-
}
|
|
1089
|
-
return this.instance;
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* Clear all registered types and conversions
|
|
1093
|
-
*/
|
|
1094
|
-
clear() {
|
|
1095
|
-
this.types.clear();
|
|
1096
|
-
this.conversions.clear();
|
|
1097
|
-
this.instance = null;
|
|
1098
|
-
}
|
|
959
|
+
types = /* @__PURE__ */ new Map();
|
|
960
|
+
conversions = /* @__PURE__ */ new Map();
|
|
961
|
+
instance = null;
|
|
962
|
+
registerType(name, test) {
|
|
963
|
+
this.types.set(name, {
|
|
964
|
+
name,
|
|
965
|
+
test
|
|
966
|
+
});
|
|
967
|
+
this.instance = null;
|
|
968
|
+
return this;
|
|
969
|
+
}
|
|
970
|
+
registerConversion(from, to, convert) {
|
|
971
|
+
const key = `${from}->${to}`;
|
|
972
|
+
this.conversions.set(key, {
|
|
973
|
+
from,
|
|
974
|
+
to,
|
|
975
|
+
convert
|
|
976
|
+
});
|
|
977
|
+
this.instance = null;
|
|
978
|
+
return this;
|
|
979
|
+
}
|
|
980
|
+
hasType(name) {
|
|
981
|
+
return this.types.has(name);
|
|
982
|
+
}
|
|
983
|
+
hasConversion(from, to) {
|
|
984
|
+
return this.conversions.has(`${from}->${to}`);
|
|
985
|
+
}
|
|
986
|
+
getTypeNames() {
|
|
987
|
+
return Array.from(this.types.keys());
|
|
988
|
+
}
|
|
989
|
+
build() {
|
|
990
|
+
if (!this.instance) {
|
|
991
|
+
const inst = create();
|
|
992
|
+
inst.addTypes(Array.from(this.types.values()), "any");
|
|
993
|
+
inst.addConversions(Array.from(this.conversions.values()));
|
|
994
|
+
this.instance = inst;
|
|
995
|
+
}
|
|
996
|
+
return this.instance;
|
|
997
|
+
}
|
|
998
|
+
clear() {
|
|
999
|
+
this.types.clear();
|
|
1000
|
+
this.conversions.clear();
|
|
1001
|
+
this.instance = null;
|
|
1002
|
+
}
|
|
1099
1003
|
};
|
|
1100
|
-
function createTypedFunction(
|
|
1101
|
-
|
|
1004
|
+
function createTypedFunction(name, signatures, typedInstance = mathTyped) {
|
|
1005
|
+
return typedInstance(name, signatures);
|
|
1102
1006
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1007
|
+
//#endregion
|
|
1008
|
+
//#region src/typed/type-bridge.ts
|
|
1009
|
+
let registered = false;
|
|
1106
1010
|
function registerNativeTypes() {
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
enumerable: false,
|
|
1146
|
-
configurable: false
|
|
1147
|
-
});
|
|
1148
|
-
}
|
|
1149
|
-
if (!("type" in BigNumber.prototype)) {
|
|
1150
|
-
Object.defineProperty(BigNumber.prototype, "type", {
|
|
1151
|
-
value: "BigNumber",
|
|
1152
|
-
writable: false,
|
|
1153
|
-
enumerable: false,
|
|
1154
|
-
configurable: false
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1011
|
+
if (registered) return;
|
|
1012
|
+
registered = true;
|
|
1013
|
+
if (!("isComplex" in Complex.prototype)) Object.defineProperty(Complex.prototype, "isComplex", {
|
|
1014
|
+
value: true,
|
|
1015
|
+
writable: false,
|
|
1016
|
+
enumerable: false,
|
|
1017
|
+
configurable: false
|
|
1018
|
+
});
|
|
1019
|
+
if (!("type" in Complex.prototype)) Object.defineProperty(Complex.prototype, "type", {
|
|
1020
|
+
value: "Complex",
|
|
1021
|
+
writable: false,
|
|
1022
|
+
enumerable: false,
|
|
1023
|
+
configurable: false
|
|
1024
|
+
});
|
|
1025
|
+
if (!("isFraction" in Fraction.prototype)) Object.defineProperty(Fraction.prototype, "isFraction", {
|
|
1026
|
+
value: true,
|
|
1027
|
+
writable: false,
|
|
1028
|
+
enumerable: false,
|
|
1029
|
+
configurable: false
|
|
1030
|
+
});
|
|
1031
|
+
if (!("type" in Fraction.prototype)) Object.defineProperty(Fraction.prototype, "type", {
|
|
1032
|
+
value: "Fraction",
|
|
1033
|
+
writable: false,
|
|
1034
|
+
enumerable: false,
|
|
1035
|
+
configurable: false
|
|
1036
|
+
});
|
|
1037
|
+
if (!("isBigNumber" in BigNumber.prototype)) Object.defineProperty(BigNumber.prototype, "isBigNumber", {
|
|
1038
|
+
value: true,
|
|
1039
|
+
writable: false,
|
|
1040
|
+
enumerable: false,
|
|
1041
|
+
configurable: false
|
|
1042
|
+
});
|
|
1043
|
+
if (!("type" in BigNumber.prototype)) Object.defineProperty(BigNumber.prototype, "type", {
|
|
1044
|
+
value: "BigNumber",
|
|
1045
|
+
writable: false,
|
|
1046
|
+
enumerable: false,
|
|
1047
|
+
configurable: false
|
|
1048
|
+
});
|
|
1157
1049
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1050
|
+
//#endregion
|
|
1051
|
+
//#region src/factory/factory.ts
|
|
1052
|
+
const DEFAULT_CONFIG = {
|
|
1053
|
+
precision: 64,
|
|
1054
|
+
matrix: "Matrix",
|
|
1055
|
+
number: "number",
|
|
1056
|
+
randomSeed: null,
|
|
1057
|
+
epsilon: 1e-12,
|
|
1058
|
+
preferredBackend: "auto",
|
|
1059
|
+
wasmThreshold: 1e3,
|
|
1060
|
+
gpuThreshold: 1e5,
|
|
1061
|
+
parallelEnabled: true,
|
|
1062
|
+
parallelThreshold: 5e4
|
|
1171
1063
|
};
|
|
1172
1064
|
var FunctionRegistry = class {
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
return this.factories.has(name2);
|
|
1230
|
-
}
|
|
1231
|
-
/**
|
|
1232
|
-
* Get all registered function names
|
|
1233
|
-
*/
|
|
1234
|
-
names() {
|
|
1235
|
-
return Array.from(this.factories.keys());
|
|
1236
|
-
}
|
|
1237
|
-
/**
|
|
1238
|
-
* Update configuration
|
|
1239
|
-
*/
|
|
1240
|
-
updateConfig(config) {
|
|
1241
|
-
this.dependencies.config = { ...this.dependencies.config, ...config };
|
|
1242
|
-
this.instances.clear();
|
|
1243
|
-
}
|
|
1244
|
-
/**
|
|
1245
|
-
* Get current configuration
|
|
1246
|
-
*/
|
|
1247
|
-
getConfig() {
|
|
1248
|
-
return { ...this.dependencies.config };
|
|
1249
|
-
}
|
|
1065
|
+
factories = /* @__PURE__ */ new Map();
|
|
1066
|
+
instances = /* @__PURE__ */ new Map();
|
|
1067
|
+
dependencies;
|
|
1068
|
+
creating = /* @__PURE__ */ new Set();
|
|
1069
|
+
constructor(config = {}, typed = mathTyped) {
|
|
1070
|
+
this.dependencies = {
|
|
1071
|
+
config: {
|
|
1072
|
+
...DEFAULT_CONFIG,
|
|
1073
|
+
...config
|
|
1074
|
+
},
|
|
1075
|
+
typed
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
register(factory) {
|
|
1079
|
+
this.factories.set(factory.name, factory);
|
|
1080
|
+
}
|
|
1081
|
+
registerAll(factories) {
|
|
1082
|
+
for (const factory of factories) this.register(factory);
|
|
1083
|
+
}
|
|
1084
|
+
get(name) {
|
|
1085
|
+
const existing = this.instances.get(name);
|
|
1086
|
+
if (existing) return existing;
|
|
1087
|
+
if (this.creating.has(name)) throw new Error(`Circular dependency detected: ${name}`);
|
|
1088
|
+
const factory = this.factories.get(name);
|
|
1089
|
+
if (!factory) throw new Error(`Unknown function: ${name}`);
|
|
1090
|
+
this.creating.add(name);
|
|
1091
|
+
try {
|
|
1092
|
+
const deps = { ...this.dependencies };
|
|
1093
|
+
for (const depName of factory.dependencies) {
|
|
1094
|
+
if (depName === "config" || depName === "typed") continue;
|
|
1095
|
+
deps[depName] = this.get(depName);
|
|
1096
|
+
}
|
|
1097
|
+
const fn = factory.factory(deps);
|
|
1098
|
+
this.instances.set(name, fn);
|
|
1099
|
+
this.dependencies[name] = fn;
|
|
1100
|
+
return fn;
|
|
1101
|
+
} finally {
|
|
1102
|
+
this.creating.delete(name);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
has(name) {
|
|
1106
|
+
return this.factories.has(name);
|
|
1107
|
+
}
|
|
1108
|
+
names() {
|
|
1109
|
+
return Array.from(this.factories.keys());
|
|
1110
|
+
}
|
|
1111
|
+
updateConfig(config) {
|
|
1112
|
+
this.dependencies.config = {
|
|
1113
|
+
...this.dependencies.config,
|
|
1114
|
+
...config
|
|
1115
|
+
};
|
|
1116
|
+
this.instances.clear();
|
|
1117
|
+
}
|
|
1118
|
+
getConfig() {
|
|
1119
|
+
return { ...this.dependencies.config };
|
|
1120
|
+
}
|
|
1250
1121
|
};
|
|
1251
|
-
function createFactory(
|
|
1252
|
-
|
|
1122
|
+
function createFactory(name, dependencies, factory) {
|
|
1123
|
+
return {
|
|
1124
|
+
name,
|
|
1125
|
+
dependencies,
|
|
1126
|
+
factory
|
|
1127
|
+
};
|
|
1253
1128
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
/**
|
|
1261
|
-
* Register a factory function
|
|
1262
|
-
*/
|
|
1263
|
-
register: (factory2) => registry.register(factory2),
|
|
1264
|
-
/**
|
|
1265
|
-
* Get configuration
|
|
1266
|
-
*/
|
|
1267
|
-
config: () => registry.getConfig(),
|
|
1268
|
-
/**
|
|
1269
|
-
* Update configuration
|
|
1270
|
-
*/
|
|
1271
|
-
configure: (config) => registry.updateConfig(config)
|
|
1129
|
+
const registry = new FunctionRegistry();
|
|
1130
|
+
const math = {
|
|
1131
|
+
get: (name) => registry.get(name),
|
|
1132
|
+
register: (factory) => registry.register(factory),
|
|
1133
|
+
config: () => registry.getConfig(),
|
|
1134
|
+
configure: (config) => registry.updateConfig(config)
|
|
1272
1135
|
};
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1136
|
+
//#endregion
|
|
1137
|
+
//#region src/numeric/stable.ts
|
|
1138
|
+
const PAIRWISE_BLOCK = 128;
|
|
1276
1139
|
function pairwiseSum(xs, start = 0, end = xs.length) {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1140
|
+
const n = end - start;
|
|
1141
|
+
if (n <= PAIRWISE_BLOCK) {
|
|
1142
|
+
let s0 = 0;
|
|
1143
|
+
let s1 = 0;
|
|
1144
|
+
let s2 = 0;
|
|
1145
|
+
let s3 = 0;
|
|
1146
|
+
let s4 = 0;
|
|
1147
|
+
let s5 = 0;
|
|
1148
|
+
let s6 = 0;
|
|
1149
|
+
let s7 = 0;
|
|
1150
|
+
let i = start;
|
|
1151
|
+
const limit = start + (n - n % 8);
|
|
1152
|
+
for (; i < limit; i += 8) {
|
|
1153
|
+
s0 += xs[i];
|
|
1154
|
+
s1 += xs[i + 1];
|
|
1155
|
+
s2 += xs[i + 2];
|
|
1156
|
+
s3 += xs[i + 3];
|
|
1157
|
+
s4 += xs[i + 4];
|
|
1158
|
+
s5 += xs[i + 5];
|
|
1159
|
+
s6 += xs[i + 6];
|
|
1160
|
+
s7 += xs[i + 7];
|
|
1161
|
+
}
|
|
1162
|
+
let tail = 0;
|
|
1163
|
+
for (; i < end; i++) tail += xs[i];
|
|
1164
|
+
return s0 + s1 + (s2 + s3) + (s4 + s5 + (s6 + s7)) + tail;
|
|
1165
|
+
}
|
|
1166
|
+
const half = (n >> 1) - (n >> 1) % 8;
|
|
1167
|
+
return pairwiseSum(xs, start, start + half) + pairwiseSum(xs, start + half, end);
|
|
1305
1168
|
}
|
|
1306
1169
|
function neumaierSum(xs) {
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1170
|
+
let sum = 0;
|
|
1171
|
+
let c = 0;
|
|
1172
|
+
for (let i = 0; i < xs.length; i++) {
|
|
1173
|
+
const x = xs[i];
|
|
1174
|
+
const t = sum + x;
|
|
1175
|
+
c += Math.abs(sum) >= Math.abs(x) ? sum - t + x : x - t + sum;
|
|
1176
|
+
sum = t;
|
|
1177
|
+
}
|
|
1178
|
+
return sum + c;
|
|
1316
1179
|
}
|
|
1317
1180
|
function norm2(xs) {
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1181
|
+
let scale = 0;
|
|
1182
|
+
let ssq = 1;
|
|
1183
|
+
for (let i = 0; i < xs.length; i++) {
|
|
1184
|
+
const x = xs[i];
|
|
1185
|
+
if (x === 0) continue;
|
|
1186
|
+
if (Number.isNaN(x)) return NaN;
|
|
1187
|
+
const ax = Math.abs(x);
|
|
1188
|
+
if (scale < ax) {
|
|
1189
|
+
const r = scale / ax;
|
|
1190
|
+
ssq = 1 + ssq * r * r;
|
|
1191
|
+
scale = ax;
|
|
1192
|
+
} else {
|
|
1193
|
+
const r = ax / scale;
|
|
1194
|
+
ssq += r * r;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
return scale === 0 ? 0 : scale * Math.sqrt(ssq);
|
|
1335
1198
|
}
|
|
1336
1199
|
function pairwiseDot(a, b, start = 0, end = a.length) {
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1200
|
+
const n = end - start;
|
|
1201
|
+
if (n <= PAIRWISE_BLOCK) {
|
|
1202
|
+
let s0 = 0;
|
|
1203
|
+
let s1 = 0;
|
|
1204
|
+
let s2 = 0;
|
|
1205
|
+
let s3 = 0;
|
|
1206
|
+
let s4 = 0;
|
|
1207
|
+
let s5 = 0;
|
|
1208
|
+
let s6 = 0;
|
|
1209
|
+
let s7 = 0;
|
|
1210
|
+
let i = start;
|
|
1211
|
+
const limit = start + (n - n % 8);
|
|
1212
|
+
for (; i < limit; i += 8) {
|
|
1213
|
+
s0 += a[i] * b[i];
|
|
1214
|
+
s1 += a[i + 1] * b[i + 1];
|
|
1215
|
+
s2 += a[i + 2] * b[i + 2];
|
|
1216
|
+
s3 += a[i + 3] * b[i + 3];
|
|
1217
|
+
s4 += a[i + 4] * b[i + 4];
|
|
1218
|
+
s5 += a[i + 5] * b[i + 5];
|
|
1219
|
+
s6 += a[i + 6] * b[i + 6];
|
|
1220
|
+
s7 += a[i + 7] * b[i + 7];
|
|
1221
|
+
}
|
|
1222
|
+
let tail = 0;
|
|
1223
|
+
for (; i < end; i++) tail += a[i] * b[i];
|
|
1224
|
+
return s0 + s1 + (s2 + s3) + (s4 + s5 + (s6 + s7)) + tail;
|
|
1225
|
+
}
|
|
1226
|
+
const half = (n >> 1) - (n >> 1) % 8;
|
|
1227
|
+
return pairwiseDot(a, b, start, start + half) + pairwiseDot(a, b, start + half, end);
|
|
1365
1228
|
}
|
|
1366
1229
|
function scaledDistance(a, b) {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1230
|
+
let scale = 0;
|
|
1231
|
+
let ssq = 1;
|
|
1232
|
+
for (let i = 0; i < a.length; i++) {
|
|
1233
|
+
const d = a[i] - b[i];
|
|
1234
|
+
if (d === 0) continue;
|
|
1235
|
+
if (Number.isNaN(d)) return NaN;
|
|
1236
|
+
const ad = Math.abs(d);
|
|
1237
|
+
if (scale < ad) {
|
|
1238
|
+
const r = scale / ad;
|
|
1239
|
+
ssq = 1 + ssq * r * r;
|
|
1240
|
+
scale = ad;
|
|
1241
|
+
} else {
|
|
1242
|
+
const r = ad / scale;
|
|
1243
|
+
ssq += r * r;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return scale === 0 ? 0 : scale * Math.sqrt(ssq);
|
|
1384
1247
|
}
|
|
1385
1248
|
function sumSquaredDeviations(xs) {
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
return corrected < 0 ? 0 : corrected;
|
|
1249
|
+
const n = xs.length;
|
|
1250
|
+
if (n < 2) return 0;
|
|
1251
|
+
const { sumD, sumDD } = pairwiseDeviationSums(xs, pairwiseSum(xs) / n, 0, n);
|
|
1252
|
+
const corrected = sumDD - sumD * sumD / n;
|
|
1253
|
+
return corrected < 0 ? 0 : corrected;
|
|
1392
1254
|
}
|
|
1393
1255
|
function pairwiseDeviationSums(xs, mean, start, end) {
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1256
|
+
const n = end - start;
|
|
1257
|
+
if (n <= PAIRWISE_BLOCK) {
|
|
1258
|
+
let d0 = 0, d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0, d7 = 0;
|
|
1259
|
+
let q0 = 0, q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0, q6 = 0, q7 = 0;
|
|
1260
|
+
let i = start;
|
|
1261
|
+
const limit = start + (n - n % 8);
|
|
1262
|
+
for (; i < limit; i += 8) {
|
|
1263
|
+
const a0 = xs[i] - mean;
|
|
1264
|
+
const a1 = xs[i + 1] - mean;
|
|
1265
|
+
const a2 = xs[i + 2] - mean;
|
|
1266
|
+
const a3 = xs[i + 3] - mean;
|
|
1267
|
+
const a4 = xs[i + 4] - mean;
|
|
1268
|
+
const a5 = xs[i + 5] - mean;
|
|
1269
|
+
const a6 = xs[i + 6] - mean;
|
|
1270
|
+
const a7 = xs[i + 7] - mean;
|
|
1271
|
+
d0 += a0;
|
|
1272
|
+
q0 += a0 * a0;
|
|
1273
|
+
d1 += a1;
|
|
1274
|
+
q1 += a1 * a1;
|
|
1275
|
+
d2 += a2;
|
|
1276
|
+
q2 += a2 * a2;
|
|
1277
|
+
d3 += a3;
|
|
1278
|
+
q3 += a3 * a3;
|
|
1279
|
+
d4 += a4;
|
|
1280
|
+
q4 += a4 * a4;
|
|
1281
|
+
d5 += a5;
|
|
1282
|
+
q5 += a5 * a5;
|
|
1283
|
+
d6 += a6;
|
|
1284
|
+
q6 += a6 * a6;
|
|
1285
|
+
d7 += a7;
|
|
1286
|
+
q7 += a7 * a7;
|
|
1287
|
+
}
|
|
1288
|
+
let tailD = 0;
|
|
1289
|
+
let tailDD = 0;
|
|
1290
|
+
for (; i < end; i++) {
|
|
1291
|
+
const a = xs[i] - mean;
|
|
1292
|
+
tailD += a;
|
|
1293
|
+
tailDD += a * a;
|
|
1294
|
+
}
|
|
1295
|
+
return {
|
|
1296
|
+
sumD: d0 + d1 + (d2 + d3) + (d4 + d5 + (d6 + d7)) + tailD,
|
|
1297
|
+
sumDD: q0 + q1 + (q2 + q3) + (q4 + q5 + (q6 + q7)) + tailDD
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
const half = (n >> 1) - (n >> 1) % 8;
|
|
1301
|
+
const left = pairwiseDeviationSums(xs, mean, start, start + half);
|
|
1302
|
+
const right = pairwiseDeviationSums(xs, mean, start + half, end);
|
|
1303
|
+
return {
|
|
1304
|
+
sumD: left.sumD + right.sumD,
|
|
1305
|
+
sumDD: left.sumDD + right.sumDD
|
|
1306
|
+
};
|
|
1442
1307
|
}
|
|
1443
1308
|
function neumaierCumsum(xs, out) {
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1309
|
+
let sum = 0;
|
|
1310
|
+
let c = 0;
|
|
1311
|
+
for (let i = 0; i < xs.length; i++) {
|
|
1312
|
+
const x = xs[i];
|
|
1313
|
+
const t = sum + x;
|
|
1314
|
+
c += Math.abs(sum) >= Math.abs(x) ? sum - t + x : x - t + sum;
|
|
1315
|
+
sum = t;
|
|
1316
|
+
out[i] = sum + c;
|
|
1317
|
+
}
|
|
1453
1318
|
}
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
isBigInt2 as isBigInt,
|
|
1549
|
-
isBigNumber2 as isBigNumber,
|
|
1550
|
-
isBoolean,
|
|
1551
|
-
isComplex,
|
|
1552
|
-
isDenseMatrix,
|
|
1553
|
-
isDual,
|
|
1554
|
-
isFraction,
|
|
1555
|
-
isFunction,
|
|
1556
|
-
isMatrix,
|
|
1557
|
-
isNull,
|
|
1558
|
-
isNumber,
|
|
1559
|
-
isNumeric,
|
|
1560
|
-
isObject,
|
|
1561
|
-
isRationalScale,
|
|
1562
|
-
isSparseMatrix,
|
|
1563
|
-
isString,
|
|
1564
|
-
isTypedWasmAvailable,
|
|
1565
|
-
isUndefined,
|
|
1566
|
-
isUnit2 as isUnit,
|
|
1567
|
-
isUnit as isUnitValue,
|
|
1568
|
-
math,
|
|
1569
|
-
mathTyped,
|
|
1570
|
-
multiplyExactScales,
|
|
1571
|
-
multiplyScalar,
|
|
1572
|
-
namedExactScale,
|
|
1573
|
-
namedIrrationalScale,
|
|
1574
|
-
neumaierCumsum,
|
|
1575
|
-
neumaierSum,
|
|
1576
|
-
norm2,
|
|
1577
|
-
number,
|
|
1578
|
-
pairwiseDot,
|
|
1579
|
-
pairwiseSum,
|
|
1580
|
-
pow,
|
|
1581
|
-
powerExactScale,
|
|
1582
|
-
ratioExactScale,
|
|
1583
|
-
readScaleExpression,
|
|
1584
|
-
readUnitScale,
|
|
1585
|
-
registerNativeTypes,
|
|
1586
|
-
registry,
|
|
1587
|
-
round,
|
|
1588
|
-
scaledDistance,
|
|
1589
|
-
subtractScalar,
|
|
1590
|
-
sumSquaredDeviations,
|
|
1591
|
-
toSiDimensionVector,
|
|
1592
|
-
toSiDimensions,
|
|
1593
|
-
typed,
|
|
1594
|
-
unitPrefixExactScale,
|
|
1595
|
-
unitRowExactOffset,
|
|
1596
|
-
unitRowExactScale,
|
|
1597
|
-
unitRowValue
|
|
1598
|
-
};
|
|
1319
|
+
//#endregion
|
|
1320
|
+
//#region src/numeric/rng.ts
|
|
1321
|
+
function mulberry32(seed) {
|
|
1322
|
+
let s = seed | 0;
|
|
1323
|
+
return () => {
|
|
1324
|
+
s = s + 1831565813 | 0;
|
|
1325
|
+
let z = s;
|
|
1326
|
+
z = Math.imul(z ^ z >>> 15, z | 1);
|
|
1327
|
+
z ^= z + Math.imul(z ^ z >>> 7, z | 61);
|
|
1328
|
+
z = (z ^ z >>> 14) >>> 0;
|
|
1329
|
+
return z / 4294967296;
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
function boxMuller(u1, u2) {
|
|
1333
|
+
const r = Math.sqrt(-2 * Math.log(u1 === 0 ? Number.EPSILON : u1));
|
|
1334
|
+
const theta = 2 * Math.PI * u2;
|
|
1335
|
+
return [r * Math.cos(theta), r * Math.sin(theta)];
|
|
1336
|
+
}
|
|
1337
|
+
const FNV_OFFSET = 2166136261;
|
|
1338
|
+
const FNV_PRIME = 16777619;
|
|
1339
|
+
function fnv1a32(bytes) {
|
|
1340
|
+
let h = FNV_OFFSET;
|
|
1341
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
1342
|
+
h ^= bytes[i];
|
|
1343
|
+
h = Math.imul(h, FNV_PRIME) >>> 0;
|
|
1344
|
+
}
|
|
1345
|
+
return h >>> 0;
|
|
1346
|
+
}
|
|
1347
|
+
const textEncoder = new TextEncoder();
|
|
1348
|
+
function coerceSeedInt(seed) {
|
|
1349
|
+
if (typeof seed === "number") return seed | 0;
|
|
1350
|
+
if (typeof seed === "string") return fnv1a32(textEncoder.encode(seed)) | 0;
|
|
1351
|
+
throw new TypeError("seed must be a number or a string");
|
|
1352
|
+
}
|
|
1353
|
+
function mixFork(parentSeed, label) {
|
|
1354
|
+
const payload = [
|
|
1355
|
+
parentSeed >>> 0 & 255,
|
|
1356
|
+
parentSeed >>> 8 & 255,
|
|
1357
|
+
parentSeed >>> 16 & 255,
|
|
1358
|
+
parentSeed >>> 24 & 255
|
|
1359
|
+
];
|
|
1360
|
+
if (typeof label === "number") {
|
|
1361
|
+
const n = label | 0;
|
|
1362
|
+
payload.push(0, n >>> 0 & 255, n >>> 8 & 255, n >>> 16 & 255, n >>> 24 & 255);
|
|
1363
|
+
} else if (typeof label === "string") {
|
|
1364
|
+
payload.push(1);
|
|
1365
|
+
for (const b of textEncoder.encode(label)) payload.push(b);
|
|
1366
|
+
} else throw new TypeError("fork label must be a string or a number");
|
|
1367
|
+
return fnv1a32(new Uint8Array(payload)) | 0;
|
|
1368
|
+
}
|
|
1369
|
+
function makeSeededRng(seedInt) {
|
|
1370
|
+
const uniform = mulberry32(seedInt);
|
|
1371
|
+
let spare = null;
|
|
1372
|
+
return Object.freeze({
|
|
1373
|
+
seed: seedInt,
|
|
1374
|
+
next: () => uniform(),
|
|
1375
|
+
nextInt(maxExclusive) {
|
|
1376
|
+
if (!Number.isInteger(maxExclusive) || maxExclusive < 1 || maxExclusive > 4294967296) throw new RangeError("maxExclusive must be an integer in [1, 4294967296]");
|
|
1377
|
+
return Math.floor(uniform() * maxExclusive);
|
|
1378
|
+
},
|
|
1379
|
+
normal() {
|
|
1380
|
+
if (spare !== null) {
|
|
1381
|
+
const z = spare;
|
|
1382
|
+
spare = null;
|
|
1383
|
+
return z;
|
|
1384
|
+
}
|
|
1385
|
+
const pair = boxMuller(uniform(), uniform());
|
|
1386
|
+
spare = pair[1];
|
|
1387
|
+
return pair[0];
|
|
1388
|
+
},
|
|
1389
|
+
fork(label) {
|
|
1390
|
+
return makeSeededRng(mixFork(seedInt, label));
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
function createSeededRng(seed) {
|
|
1395
|
+
return makeSeededRng(coerceSeedInt(seed));
|
|
1396
|
+
}
|
|
1397
|
+
//#endregion
|
|
1398
|
+
//#region src/numeric/strides.ts
|
|
1399
|
+
function rowMajorStrides(shape) {
|
|
1400
|
+
const strides = new Array(shape.length);
|
|
1401
|
+
let acc = 1;
|
|
1402
|
+
for (let k = shape.length - 1; k >= 0; k--) {
|
|
1403
|
+
strides[k] = acc;
|
|
1404
|
+
acc *= shape[k];
|
|
1405
|
+
}
|
|
1406
|
+
return strides;
|
|
1407
|
+
}
|
|
1408
|
+
//#endregion
|
|
1409
|
+
//#region src/index.ts
|
|
1410
|
+
const VERSION = "0.20.0";
|
|
1411
|
+
//#endregion
|
|
1412
|
+
export { ALL_UNITS, BASE_UNITS, BEST_PREFIXES, BIGNUMBER_E, BIGNUMBER_LN10, BIGNUMBER_LN2, BIGNUMBER_NEG_ONE, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_TEN, BIGNUMBER_ZERO, BigNumber, COMPLEX_NEG_ONE, COMPLEX_ONE, COMPLEX_ZERO, Complex, DEFAULT_CONFIG, DERIVED_UNITS, DIMENSIONLESS, DUAL_UNARY_RULES, DimensionMismatchError, Dual, E, FRACTION_HALF, FRACTION_NEG_ONE, FRACTION_ONE, FRACTION_QUARTER, FRACTION_THIRD, FRACTION_ZERO, Fraction, FunctionRegistry, I, LN10, LN2, LN2_EXACT_SCALE, LOG10E, LOG2E, MATHTS_CONVERSIONS, MATHTS_TYPES, NAMED_IRRATIONALS, NAMED_SCALES, PHI, PI, PI_EXACT_SCALE, Range, SI_DIMENSION_LENGTH, SI_PREFIXES, SQRT1_2, SQRT2, TAU, TypeRegistry, UNIT_ALIASES, UNIT_DIMENSION_LENGTH, UNIT_EXACT_SCALE, UNIT_PREFIX_SETS, UNIT_ROWS, UNIT_ROW_ALIASES, Unit, UnitParseError, VERSION, abs, addExactScales, addScalar, binaryExactScale, boxMuller, clearExactScaleNumberCache, create, createFactory, createMathTSTyped, createRangeClass, createSeededRng, createTypedFunction, decimalExactScale, dim, divideExactScales, divideScalar, equal, exactScaleNumberCacheSize, exactScaleOf, exactScaleToNumber, exactScalesEqual, fix, formatExactScale, fromSiDimensionVector, fromSiDimensions, getPrefix, getUnitDef, getUnitPrefix, getUnitRow, initTypedWasm, irrationalPower, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isNumeric, isObject, isRationalScale, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, isUnit$1 as isUnitValue, math, mathTyped, mulberry32, multiplyExactScales, multiplyScalar, namedExactScale, namedIrrationalScale, neumaierCumsum, neumaierSum, norm2, number, pairwiseDot, pairwiseSum, pow, powerExactScale, ratioExactScale, readScaleExpression, readUnitScale, registerNativeTypes, registry, round, rowMajorStrides, scaledDistance, subtractScalar, sumSquaredDeviations, toSiDimensionVector, toSiDimensions, typed, unitPrefixExactScale, unitRowExactOffset, unitRowExactScale, unitRowValue };
|