@danielsimonjr/mathts-core 0.19.0 → 0.21.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.
Files changed (40) hide show
  1. package/README.md +30 -5
  2. package/dist/collection.d.ts +35 -23
  3. package/dist/collection.d.ts.map +1 -1
  4. package/dist/index.d.ts +4 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +121 -17
  7. package/dist/internal.d.ts +3 -2
  8. package/dist/internal.d.ts.map +1 -1
  9. package/dist/internal.js +161 -2
  10. package/dist/numeric/rng.d.ts +88 -0
  11. package/dist/numeric/rng.d.ts.map +1 -0
  12. package/dist/numeric/strides.d.ts +18 -0
  13. package/dist/numeric/strides.d.ts.map +1 -0
  14. package/dist/object.d.ts +20 -2
  15. package/dist/object.d.ts.map +1 -1
  16. package/dist/shared.d.ts +19 -0
  17. package/dist/shared.d.ts.map +1 -1
  18. package/dist/switch.d.ts +2 -4
  19. package/dist/switch.d.ts.map +1 -1
  20. package/dist/types/bignumber.d.ts +7 -0
  21. package/dist/types/bignumber.d.ts.map +1 -1
  22. package/dist/types/complex.d.ts +20 -18
  23. package/dist/types/complex.d.ts.map +1 -1
  24. package/dist/types/fraction.d.ts +5 -0
  25. package/dist/types/fraction.d.ts.map +1 -1
  26. package/dist/types/si-dimension-vector.d.ts +62 -7
  27. package/dist/types/si-dimension-vector.d.ts.map +1 -1
  28. package/dist/types/unit/Unit.d.ts.map +1 -1
  29. package/dist/types/unit/index.d.ts +2 -2
  30. package/dist/types/unit/index.d.ts.map +1 -1
  31. package/dist/types/unit/unit-table.d.ts +12 -0
  32. package/dist/types/unit/unit-table.d.ts.map +1 -1
  33. package/dist/types/unit.d.ts +2 -2
  34. package/dist/types/unit.d.ts.map +1 -1
  35. package/dist/{unit-l_r8z5Fv.js → unit-D3yD3jbu.js} +106 -65
  36. package/dist/wasm-as-header.d.ts +17 -0
  37. package/dist/wasm-as-header.d.ts.map +1 -0
  38. package/dist/wasm-loader.d.ts +33 -1
  39. package/dist/wasm-loader.d.ts.map +1 -1
  40. package/package.json +2 -1
package/README.md CHANGED
@@ -11,10 +11,11 @@ npm install @danielsimonjr/mathts-core
11
11
  ## Usage
12
12
 
13
13
  ```typescript
14
- import { DEFAULT_CONFIG, isNumber, isMatrix, VERSION } from '@danielsimonjr/mathts-core';
14
+ import { DEFAULT_CONFIG, isNumber, isMatrix } from '@danielsimonjr/mathts-core';
15
+ import { DenseMatrix } from '@danielsimonjr/mathts-matrix';
15
16
 
16
- // Default configuration
17
- const config = { ...DEFAULT_CONFIG, backend: 'wasm' };
17
+ // Factory default configuration (MathTSConfig)
18
+ const config = { ...DEFAULT_CONFIG, preferredBackend: 'wasm' };
18
19
 
19
20
  // Type guards
20
21
  console.log(isNumber(42)); // true
@@ -23,7 +24,12 @@ console.log(
23
24
  [1, 2],
24
25
  [3, 4],
25
26
  ])
26
- ); // true
27
+ ); // false — nested arrays are not matrices
28
+ const m = DenseMatrix.fromArray([
29
+ [1, 2],
30
+ [3, 4],
31
+ ]);
32
+ console.log(isMatrix(m)); // true
27
33
  ```
28
34
 
29
35
  ## API
@@ -34,12 +40,31 @@ console.log(
34
40
  - `NumericType` - Numeric precision types
35
41
  - `MathTSConfig` - Configuration interface
36
42
 
43
+ ### SI dimension vectors
44
+
45
+ `toSiDimensionVector` returns exact `Fraction` exponents `[L, M, T, I, Θ, N, J]`; use
46
+ `vec.map((f) => f.toNumber())` when you need plain numbers (there is no
47
+ `toSiDimensionNumbers` helper). `fromSiDimensionVector` accepts `SiDimensionExponent`
48
+ (`number | Fraction`) and produces the length-10 `Unit` exponent array.
49
+
37
50
  ### Functions
38
51
 
52
+ - `createSeededRng(seed)` / `SeededRng` — forkable Mulberry32 stream (`next`, `nextInt`, `normal`, `fork`); number seeds match `mulberry32`, strings are FNV-1a UTF-8 (not cryptographically secure)
53
+
54
+ ```ts
55
+ const rng = createSeededRng(42);
56
+ rng.next(); // 0.6011037519201636
57
+ rng.fork('a').next(); // 0.668102843221277
58
+ createSeededRng('a').seed; // -468965076
59
+ ```
60
+
61
+ - `mulberry32(seed)` — seeded Mulberry32 PRNG returning U[0, 1) samples (not cryptographically secure)
62
+ - `boxMuller(u1, u2)` — Box–Muller pair of N(0, 1) samples from two uniforms
63
+ - `rowMajorStrides(shape)` — row-major stride vector for a dense tensor shape
39
64
  - `DEFAULT_CONFIG` - Default configuration object
40
65
  - `isNumber(value)` - Type guard for numbers
41
66
  - `isComplex(value)` - Type guard for complex numbers
42
- - `isMatrix(value)` - Type guard for matrices
67
+ - `isMatrix(value)` - Type guard for matrix-like objects (`rows`, `cols`, `get`, `type`)
43
68
 
44
69
  ## License
45
70
 
@@ -1,3 +1,4 @@
1
+ import { type NestedArray } from './array.js';
1
2
  interface Matrix<T = unknown> {
2
3
  forEach(callback: (value: T) => void, skipZeros: boolean, recurse: boolean): void;
3
4
  map<U>(callback: (value: T) => U, skipZeros: boolean, recurse: boolean): Matrix<U>;
@@ -19,35 +20,46 @@ interface SparseMatrix<T = unknown> {
19
20
  */
20
21
  export declare function containsCollections(array: unknown[]): boolean;
21
22
  /**
22
- * Recursively loop over all elements in a given multi dimensional array
23
- * and invoke the callback on each of the elements.
24
- * @param array - Array or Matrix to iterate over
25
- * @param callback - The callback method is invoked with one parameter: the current element in the array
23
+ * Recursively loop over all elements in a given multi-dimensional array or matrix
24
+ * and invoke the callback on each scalar leaf.
25
+ *
26
+ * Nested arrays are first-class inputs: `deepForEach([[1, 2], 3], fn)` visits `1`, `2`, then `3`.
27
+ * For a matrix argument, recursion follows `forEach` with `recurse: true`.
28
+ *
29
+ * @param array - Nested array or matrix to iterate over
30
+ * @param callback - Invoked once per scalar element
26
31
  */
27
- export declare function deepForEach<T>(array: T[] | Matrix<T>, callback: (value: T) => void): void;
32
+ export declare function deepForEach<T>(array: NestedArray<T> | Matrix<T>, callback: (value: T) => void): void;
28
33
  /**
29
- * Execute the callback function element wise for each element in array and any
30
- * nested array
31
- * Returns an array with the results
32
- * @param array - Array or Matrix to map over
33
- * @param callback - The callback is called with two parameters:
34
- * value1 and value2, which contain the current
35
- * element of both arrays.
36
- * @param skipZeros - Invoke callback function for non-zero values only.
34
+ * Map a callback over every scalar in a nested array or matrix, preserving structure.
35
+ *
36
+ * When `skipZeros` is `true`, numeric zero leaves are kept as the original value (`T`);
37
+ * other leaves become `callback(value)` (`U`), so the result type is `NestedArray<T | U>`
38
+ * or `Matrix<T | U>`. When `skipZeros` is omitted or `false`, every leaf is mapped to `U`.
37
39
  *
38
- * @return Mapped result
40
+ * @param array - Nested array or matrix to map over
41
+ * @param callback - Applied to each scalar element
42
+ * @param skipZeros - When true, skip the callback for zero values (zeros stay as `T`)
43
+ * @returns A nested array or matrix with the same shape as the input
39
44
  */
40
- export declare function deepMap<T, U>(array: T[] | Matrix<T>, callback: (value: T) => U, skipZeros?: boolean): U[] | Matrix<U>;
45
+ export declare function deepMap<T, U>(array: Matrix<T>, callback: (value: T) => U, skipZeros: true): Matrix<T | U>;
46
+ export declare function deepMap<T, U>(array: NestedArray<T>, callback: (value: T) => U, skipZeros: true): NestedArray<T | U>;
47
+ export declare function deepMap<T, U>(array: Matrix<T>, callback: (value: T) => U, skipZeros?: false): Matrix<U>;
48
+ export declare function deepMap<T, U>(array: NestedArray<T>, callback: (value: T) => U, skipZeros?: false): NestedArray<U>;
41
49
  /**
42
- * Reduce a given matrix or array to a new matrix or
43
- * array with one less dimension, applying the given
44
- * callback in the selected dimension.
45
- * @param mat - Array or Matrix to reduce
46
- * @param dim - Dimension to reduce
47
- * @param callback - Callback function
48
- * @return Reduced result
50
+ * Reduce a nested array or matrix along one dimension.
51
+ *
52
+ * For a one-dimensional nested array and `dim === 0`, the result is a **scalar** (`U`), not a
53
+ * one-element array — e.g. `reduce([1, 2, 3], 0, add)` is `6`. Higher-rank inputs return a
54
+ * nested array with one fewer effective dimension; matrices return a new matrix.
55
+ *
56
+ * @param mat - Nested array or matrix to reduce
57
+ * @param dim - Zero-based dimension index (must be in range for `arraySize(mat)`)
58
+ * @param callback - Fold function `(accumulator, value) => newAccumulator`
59
+ * @returns Scalar, nested array, or matrix depending on rank and `dim`
49
60
  */
50
- export declare function reduce<T, U>(mat: T[] | Matrix<T>, dim: number, callback: (acc: U | T, val: T) => U): U[] | Matrix<U>;
61
+ export declare function reduce<T, U>(mat: Matrix<T>, dim: number, callback: (acc: U | T, val: T) => U): Matrix<U>;
62
+ export declare function reduce<T, U>(mat: NestedArray<T>, dim: number, callback: (acc: U | T, val: T) => U): U | NestedArray<U>;
51
63
  /**
52
64
  * Scatter function for sparse matrix operations
53
65
  * @param a - Sparse matrix
@@ -1 +1 @@
1
- {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAqBA,UAAU,MAAM,CAAC,CAAC,GAAG,OAAO;IAC1B,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAClF,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACnF,IAAI,IAAI,MAAM,EAAE,CAAC;IACjB,OAAO,IAAI,CAAC,EAAE,CAAC;IACf,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAChD,QAAQ,IAAI,MAAM,GAAG,SAAS,CAAC;CAChC;AAED,UAAU,YAAY,CAAC,CAAC,GAAG,OAAO;IAChC,OAAO,EAAE,CAAC,EAAE,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAA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EAAE,CAAC,KAAK,CAAC,GAClC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AA4DtB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAClB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EAAE,EACX,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EACb,CAAC,EAAE,MAAM,EAAE,EACX,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EAAE,EAChB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,EACrB,OAAO,CAAC,EAAE,OAAO,EACjB,MAAM,CAAC,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,CAAC,GACR,IAAI,CA8DN"}
package/dist/index.d.ts CHANGED
@@ -17,10 +17,10 @@ export { addScalar, subtractScalar, multiplyScalar, divideScalar, pow, abs, fix,
17
17
  export type { NumericScalar } from './arithmetic/scalar.js';
18
18
  export { Unit, isUnit as isUnitValue, DimensionMismatchError, UnitParseError, DIMENSIONLESS, dim, } from './types/unit.js';
19
19
  export type { Dimensions, UnitDef, UnitInstance } from './types/unit.js';
20
- export { UNIT_EXACT_SCALE, PI_EXACT_SCALE, LN2_EXACT_SCALE, NAMED_IRRATIONALS, namedIrrationalScale, irrationalPower, isRationalScale, decimalExactScale, exactScaleOf, binaryExactScale, ratioExactScale, multiplyExactScales, divideExactScales, powerExactScale, addExactScales, exactScalesEqual, exactScaleToNumber, clearExactScaleNumberCache, exactScaleNumberCacheSize, formatExactScale, readScaleExpression, NAMED_SCALES, UNIT_ROWS, UNIT_ROW_ALIASES, namedExactScale, readUnitScale, getUnitRow, unitRowExactScale, unitRowValue, unitRowExactOffset, UNIT_PREFIX_SETS, unitPrefixExactScale, getUnitPrefix, } from './types/unit.js';
20
+ export { UNIT_EXACT_SCALE, PI_EXACT_SCALE, LN2_EXACT_SCALE, NAMED_IRRATIONALS, namedIrrationalScale, irrationalPower, isRationalScale, decimalExactScale, exactScaleOf, binaryExactScale, ratioExactScale, multiplyExactScales, divideExactScales, powerExactScale, addExactScales, exactScalesEqual, exactScaleToNumber, clearExactScaleNumberCache, exactScaleNumberCacheSize, formatExactScale, readScaleExpression, NAMED_SCALES, UNIT_ROWS, UNIT_ROW_ALIASES, REFUSED_UNIT_SPELLINGS, namedExactScale, readUnitScale, getUnitRow, unitRowExactScale, unitRowValue, unitRowExactOffset, UNIT_PREFIX_SETS, unitPrefixExactScale, getUnitPrefix, } from './types/unit.js';
21
21
  export type { ExactScale, IrrationalName, IrrationalPowers, UnitRow, UnitBaseKey, UnitPrefixSetKey, UnitPrefix, } from './types/unit.js';
22
22
  export { UNIT_DIMENSION_LENGTH, SI_DIMENSION_LENGTH, toSiDimensions, toSiDimensionVector, fromSiDimensions, fromSiDimensionVector, } from './types/unit.js';
23
- export type { SiDimensionVector, SiDimensionOptions } from './types/unit.js';
23
+ export type { SiDimensionVector, SiDimensionOptions, SiDimensionExponent } from './types/unit.js';
24
24
  export { BASE_UNITS, DERIVED_UNITS, ALL_UNITS, UNIT_ALIASES, getUnitDef, } from './types/unit-definitions.js';
25
25
  export { SI_PREFIXES, BEST_PREFIXES, getPrefix } from './types/unit-prefixes.js';
26
26
  export { mathTyped, createMathTSTyped, typed, create, createTypedFunction, TypeRegistry, MATHTS_TYPES, MATHTS_CONVERSIONS, isNumber, isBoolean, isString, isBigInt, isArray, isFunction, isObject, isNull, isUndefined, isMatrix, isDenseMatrix, isSparseMatrix, isUnit, initTypedWasm, isTypedWasmAvailable, registerNativeTypes, } from './typed/index.js';
@@ -29,4 +29,6 @@ export { FunctionRegistry, createFactory, registry, math, DEFAULT_CONFIG, } from
29
29
  export type { MathTSConfig, FactoryFunction, FactoryDependencies, FactoryImport, } from './factory/index.js';
30
30
  export declare const VERSION: string;
31
31
  export { pairwiseSum, neumaierSum, norm2, pairwiseDot, scaledDistance, neumaierCumsum, sumSquaredDeviations, } from './numeric/stable.js';
32
+ export { mulberry32, boxMuller, createSeededRng, type SeededRng } from './numeric/rng.js';
33
+ export { rowMajorStrides } from './numeric/strides.js';
32
34
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,YAAY,EACV,WAAW,EACX,MAAM,EACN,WAAW,EACX,WAAW,EACX,aAAa,EACb,OAAO,EACP,QAAQ,EACR,SAAS,EACT,UAAU,EACV,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,OAAO,EACP,SAAS,EACT,CAAC,EACD,YAAY,EACZ,WAAW,EACX,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAClE,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,GACV,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG9E,OAAO,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG3F,OAAO,EACL,QAAQ,EACR,UAAU,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,SAAS,EACT,WAAW,EACX,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb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EAGZ,YAAY,EACZ,kBAAkB,EAGlB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EAGX,QAAQ,EACR,aAAa,EACb,cAAc,EAGd,MAAM,EAGN,aAAa,EACb,oBAAoB,EAGpB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,aAAa,EACb,aAAa,EACb,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAW5B,eAAO,MAAM,OAAO,EAAE,MAAwB,CAAC;AAI/C,OAAO,EACL,WAAW,EACX,WAAW,EACX,KAAK,EACL,WAAW,EACX,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
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-l_r8z5Fv.js";
1
+ import { $ as BIGNUMBER_LN10, A as formatExactScale, B as abs, Bn as Complex, C as clearExactScaleNumberCache, D as exactScaleOf, E as exactScaleNumberCacheSize, F as powerExactScale, Fn as isUnit$1, G as isNumeric, H as divideScalar, Hn as isComplex, I as ratioExactScale, J as pow, K as multiplyScalar, L as readScaleExpression, Ln as COMPLEX_NEG_ONE, M as isRationalScale, N as multiplyExactScales, O as exactScaleToNumber, P as namedIrrationalScale, Q as BIGNUMBER_E, R as DimensionMismatchError, Rn as COMPLEX_ONE, S as binaryExactScale, T as divideExactScales, U as equal, V as addScalar, Vn as I, W as fix, X as subtractScalar, Xt as format, Y as round, _ as LN2_EXACT_SCALE, a as REFUSED_UNIT_SPELLINGS, at as BIGNUMBER_ZERO, b as UNIT_EXACT_SCALE, c as UNIT_ROW_ALIASES, ct as FRACTION_HALF, d as namedExactScale, dt as FRACTION_QUARTER, et as BIGNUMBER_LN2, f as readUnitScale, ft as FRACTION_THIRD, g as unitRowValue, gn as isBigNumber$2, h as unitRowExactScale, hn as isBigInt$1, ht as isFraction, i as NAMED_SCALES, it as BIGNUMBER_TEN, j as irrationalPower, k as exactScalesEqual, l as getUnitPrefix, lt as FRACTION_NEG_ONE, m as unitRowExactOffset, mt as Fraction, nn as nearlyEqual, nt as BIGNUMBER_ONE, o as UNIT_PREFIX_SETS, on as sign, ot as BigNumber, p as unitPrefixExactScale, pt as FRACTION_ZERO, q as number, rt as BIGNUMBER_PI, s as UNIT_ROWS, st as isBigNumber, t as Unit, tt as BIGNUMBER_NEG_ONE, u as getUnitRow, ut as FRACTION_ONE, v as NAMED_IRRATIONALS, vt as factory, w as decimalExactScale, x as addExactScales, y as PI_EXACT_SCALE, z as UnitParseError, zn as COMPLEX_ZERO } from "./unit-D3yD3jbu.js";
2
2
  import typed, { create } from "typed-function";
3
3
  const createRangeClass = /* #__PURE__ */ factory("Range", [], () => {
4
4
  class Range {
@@ -580,6 +580,15 @@ const EXTRA_INDEXES = [
580
580
  function assertFinite(label, value) {
581
581
  if (typeof value !== "number" || !Number.isFinite(value)) throw new TypeError(`${label} must be a finite number`);
582
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);
591
+ }
583
592
  function assertUnitVector(vector) {
584
593
  if (vector.length !== 10) throw new TypeError(`dimension vector must have length 10`);
585
594
  for (let i = 0; i < vector.length; i++) assertFinite(`dimension vector[${i}]`, vector[i]);
@@ -604,13 +613,13 @@ function toSiDimensions(vector, options) {
604
613
  function toSiDimensionVector(vector, options) {
605
614
  const d = toSiDimensions(vector, options);
606
615
  return [
607
- d.length,
608
- d.mass,
609
- d.time,
610
- d.current,
611
- d.temperature,
612
- d.amount,
613
- d.luminosity
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)
614
623
  ];
615
624
  }
616
625
  function fromSiDimensions(dimensions) {
@@ -639,14 +648,20 @@ function fromSiDimensions(dimensions) {
639
648
  }
640
649
  function fromSiDimensionVector(vector) {
641
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
+ });
642
657
  return fromSiDimensions({
643
- length: vector[0],
644
- mass: vector[1],
645
- time: vector[2],
646
- current: vector[3],
647
- temperature: vector[4],
648
- amount: vector[5],
649
- luminosity: vector[6]
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]
650
665
  });
651
666
  }
652
667
  //#endregion
@@ -1302,7 +1317,96 @@ function neumaierCumsum(xs, out) {
1302
1317
  }
1303
1318
  }
1304
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
1305
1409
  //#region src/index.ts
1306
- const VERSION = "0.19.0";
1410
+ const VERSION = "0.21.0";
1307
1411
  //#endregion
1308
- 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, clearExactScaleNumberCache, create, createFactory, createMathTSTyped, createRangeClass, 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, multiplyExactScales, multiplyScalar, namedExactScale, namedIrrationalScale, neumaierCumsum, neumaierSum, norm2, number, pairwiseDot, pairwiseSum, pow, powerExactScale, ratioExactScale, readScaleExpression, readUnitScale, registerNativeTypes, registry, round, scaledDistance, subtractScalar, sumSquaredDeviations, toSiDimensionVector, toSiDimensions, typed, unitPrefixExactScale, unitRowExactOffset, unitRowExactScale, unitRowValue };
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, REFUSED_UNIT_SPELLINGS, 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 };
@@ -22,7 +22,7 @@ export { IndexError, createIndexError } from './error/IndexError.js';
22
22
  export * from './factory.js';
23
23
  export { format as formatGeneric, stringify, escape, compareText, type GeneralFormatOptions, } from './string.js';
24
24
  export { format as formatBigNumber, toEngineering as toEngineeringBigNumber, toExponential as toExponentialBigNumber, toFixed as toFixedBigNumber, type BigNumberValue, } from './bignumber-formatter.js';
25
- export type * from './types/unit/unit-types.js';
25
+ export type { ComplexValue, ComplexConstructor, BigNumberConstructor, FractionConstructor, FractionValue, Numeric, PrefixDef, PrefixTable, BaseUnitDef, UnitDef, UnitComponent, UnitSystemEntry, UnitSystem, UnitJSON, ConverterFn, TypeConverters, ParseOptions, UnitFormatOptions, CreateUnitOptions, CreateUnitDefObject, UnitConfig, SubtractScalar, ScalarBinaryOp, ScalarUnaryOp, UnitDependencies, UnitInstance, UnitConstructor, } from './types/unit/unit-types.js';
26
26
  export { createUnitClass, unitDependencies, Unit as CoreUnit } from './types/unit/index.js';
27
27
  export type { NestedArray, IdentifiedValue } from './array.js';
28
28
  export { arraySize, validate, validateIndexSourceSize, validateIndex, isEmptyIndex, resize, reshape, processSizesWildcard, squeeze, unsqueeze, flatten, map, forEach, filter, filterRegExp, join, identify, generalize, getArrayDataType, last, initial, concat, broadcastSizes, checkBroadcastingRules, broadcastTo, broadcastArrays, stretch, get as getArrayElement, deepMap as deepMapArray, deepForEach as deepForEachArray, clone as cloneArray, } from './array.js';
@@ -30,5 +30,6 @@ export { containsCollections, deepMap, deepForEach, reduce, scatter } from './co
30
30
  export { _switch } from './switch.js';
31
31
  export { ObjectWrappingMap, PartitionedMap, createEmptyMap, createMap, toObject, assign as assignMap, isObjectWrappingMap, } from './map.js';
32
32
  export type { LoadingMetrics, WasmManifest } from './types/wasm-loader.js';
33
- export { sha384OfBuffer, loadWasmManifest, verifyWasmIntegrity, resolvePackagedWasm, defaultWasmLocation, } from './wasm-loader.js';
33
+ export { sha384OfBuffer, loadWasmManifest, verifyWasmIntegrity, resolvePackagedWasm, defaultWasmLocation, WasmModuleLoader, } from './wasm-loader.js';
34
+ export { allocAsHeader } from './wasm-as-header.js';
34
35
  //# sourceMappingURL=internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC1E,YAAY,EAAE,gBAAgB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AEtC,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,SAAS,EACT,QAAQ,EACR,MAAM,IAAI,SAAS,EACnB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAOlB,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAe3E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/internal.js CHANGED
@@ -1,4 +1,4 @@
1
- import { $t as log1p, An as isRegExp, At as isLegacyFactory, Bt as warnOnce, Cn as isIndex, Ct as canDefineProperty, Dn as isNumber, Dt as deepStrictEqual, En as isNull, Et as deepFlatten, Fn as typeOf, Ft as set, Gt as copysign, Ht as asinh, It as traverse, Jt as expm1, Kt as cosh, Lt as endsWith, Mn as isString, Mt as mapObject, Nn as isUndefined, Nt as pick, On as isObject, Ot as extend, Pn as isUnit, Pt as pickShallow, Qt as log10, Rt as hasOwnProperty, Sn as isFunction, St as MathjsError, Tn as isMatrix, Tt as deepExtend, Ut as atanh, Vt as acosh, Wt as cbrt, X as DEFAULT_CONFIG, Xt as isInteger, Yt as format, Zt as isPowZeroAtInfinity, _n as isCollection, _t as factory, an as sign, bn as isDenseMatrix, bt as sortFactories, cn as tanh, dn as toFixed, en as log2, fn as toPrecision, gn as isBoolean, gt as create, hn as isBigNumber, ht as assertDependencies, in as safeNumberType, jn as isSparseMatrix, jt as lazy, kn as isRange, kt as get, ln as toEngineering, mn as isBigInt, n as unitDependencies, nn as normalizeFormatOptions, on as sinh, pn as isArray, qt as digits, r as createUnitClass, rn as roundDigits, sn as splitNumber, t as Unit, tn as nearlyEqual, un as toExponential, vn as isComplex, vt as isFactory, wn as isMap, wt as clone, xn as isFraction, xt as stripOptionalNotation, yn as isDate, yt as isOptionalDependency, zt as memoize } from "./unit-l_r8z5Fv.js";
1
+ import { $t as log10, An as isRange, At as get, Bt as memoize, Cn as isFunction, Ct as MathjsError, Dn as isNull, Dt as deepFlatten, En as isMatrix, Et as deepExtend, Fn as isUnit, Ft as pickShallow, Gt as cbrt, Ht as acosh, In as typeOf, It as set, Jt as digits, Kt as copysign, Lt as traverse, Mn as isSparseMatrix, Mt as lazy, Nn as isString, Nt as mapObject, On as isNumber, Ot as deepStrictEqual, Pn as isUndefined, Pt as pick, Qt as isPowZeroAtInfinity, Rt as endsWith, Sn as isFraction, St as stripOptionalNotation, Tn as isMap, Tt as clone, Ut as asinh, Vt as warnOnce, Wt as atanh, Xt as format, Yt as expm1, Z as DEFAULT_CONFIG, Zt as isInteger, _n as isBoolean, _t as create, an as safeNumberType, bn as isDate, bt as isOptionalDependency, cn as splitNumber, dn as toExponential, en as log1p, fn as toFixed, gn as isBigNumber, gt as assertDependencies, hn as isBigInt, in as roundDigits, jn as isRegExp, jt as isLegacyFactory, kn as isObject, kt as extend, ln as tanh, mn as isArray, n as unitDependencies, nn as nearlyEqual, on as sign, pn as toPrecision, qt as cosh, r as createUnitClass, rn as normalizeFormatOptions, sn as sinh, t as Unit, tn as log2, un as toEngineering, vn as isCollection, vt as factory, wn as isIndex, wt as canDefineProperty, xn as isDenseMatrix, xt as sortFactories, yn as isComplex, yt as isFactory, zt as hasOwnProperty } from "./unit-D3yD3jbu.js";
2
2
  //#region src/error/DimensionError.ts
3
3
  var DimensionError = class DimensionError extends RangeError {
4
4
  actual;
@@ -984,5 +984,164 @@ async function defaultWasmLocation(metaUrl, wasmFile, opts) {
984
984
  }
985
985
  return join(dirname(fileURLToPath(metaUrl)), "wasm", wasmFile);
986
986
  }
987
+ var WasmModuleLoader = class {
988
+ wasmModule = null;
989
+ compiledModule = null;
990
+ loading = null;
991
+ isNode;
992
+ lastMetrics = null;
993
+ constructor() {
994
+ this.isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
995
+ }
996
+ async load(wasmPath) {
997
+ if (this.wasmModule) return this.wasmModule;
998
+ if (this.loading) return this.loading;
999
+ this.loading = this.loadModule(wasmPath);
1000
+ try {
1001
+ this.wasmModule = await this.loading;
1002
+ } catch (error) {
1003
+ this.compiledModule = null;
1004
+ throw error;
1005
+ } finally {
1006
+ this.loading = null;
1007
+ }
1008
+ return this.wasmModule;
1009
+ }
1010
+ async loadModule(wasmPath) {
1011
+ const path = wasmPath || await this.getDefaultWasmPath();
1012
+ const totalStart = performance.now();
1013
+ if (this.compiledModule) {
1014
+ const instStart = performance.now();
1015
+ const instance = await WebAssembly.instantiate(this.compiledModule, this.getImports());
1016
+ this.lastMetrics = {
1017
+ fileReadMs: 0,
1018
+ compileMs: 0,
1019
+ instantiateMs: performance.now() - instStart,
1020
+ totalMs: performance.now() - totalStart,
1021
+ fromCache: true
1022
+ };
1023
+ return instance.exports;
1024
+ }
1025
+ if (this.isNode) return this.loadNodeWasm(path, totalStart);
1026
+ return this.loadBrowserWasm(path, totalStart);
1027
+ }
1028
+ async precompile(wasmPath) {
1029
+ if (this.compiledModule) return;
1030
+ const path = wasmPath || await this.getDefaultWasmPath();
1031
+ const startTime = performance.now();
1032
+ if (this.isNode) {
1033
+ const fs = await import("fs");
1034
+ const { promisify } = await import("util");
1035
+ const buffer = await promisify(fs.readFile)(path);
1036
+ await verifyWasmIntegrity(buffer, path);
1037
+ this.compiledModule = await WebAssembly.compile(buffer);
1038
+ } else {
1039
+ const manifest = await loadWasmManifest(path);
1040
+ if (!manifest && typeof WebAssembly.compileStreaming === "function") this.compiledModule = await WebAssembly.compileStreaming(fetch(path));
1041
+ else {
1042
+ const buffer = await (await fetch(path)).arrayBuffer();
1043
+ await verifyWasmIntegrity(buffer, path, { manifest });
1044
+ this.compiledModule = await WebAssembly.compile(buffer);
1045
+ }
1046
+ }
1047
+ this.lastMetrics = {
1048
+ fileReadMs: 0,
1049
+ compileMs: performance.now() - startTime,
1050
+ instantiateMs: 0,
1051
+ totalMs: performance.now() - startTime,
1052
+ fromCache: false
1053
+ };
1054
+ }
1055
+ async loadNodeWasm(path, totalStart) {
1056
+ const fs = await import("fs");
1057
+ const { promisify } = await import("util");
1058
+ const readFile = promisify(fs.readFile);
1059
+ const readStart = performance.now();
1060
+ const buffer = await readFile(path);
1061
+ const readEnd = performance.now();
1062
+ await verifyWasmIntegrity(buffer, path);
1063
+ const compileStart = performance.now();
1064
+ this.compiledModule = await WebAssembly.compile(buffer);
1065
+ const compileEnd = performance.now();
1066
+ const instStart = performance.now();
1067
+ const instance = await WebAssembly.instantiate(this.compiledModule, this.getImports());
1068
+ const instEnd = performance.now();
1069
+ this.lastMetrics = {
1070
+ fileReadMs: readEnd - readStart,
1071
+ compileMs: compileEnd - compileStart,
1072
+ instantiateMs: instEnd - instStart,
1073
+ totalMs: performance.now() - totalStart,
1074
+ fromCache: false
1075
+ };
1076
+ return instance.exports;
1077
+ }
1078
+ async loadBrowserWasm(path, totalStart) {
1079
+ const manifest = await loadWasmManifest(path);
1080
+ if (!manifest && typeof WebAssembly.instantiateStreaming === "function") {
1081
+ const instStart = performance.now();
1082
+ const result = await WebAssembly.instantiateStreaming(fetch(path), this.getImports());
1083
+ this.compiledModule = result.module;
1084
+ this.lastMetrics = {
1085
+ fileReadMs: 0,
1086
+ compileMs: 0,
1087
+ instantiateMs: performance.now() - instStart,
1088
+ totalMs: performance.now() - totalStart,
1089
+ fromCache: false
1090
+ };
1091
+ return result.instance.exports;
1092
+ }
1093
+ const readStart = performance.now();
1094
+ const buffer = await (await fetch(path)).arrayBuffer();
1095
+ const readEnd = performance.now();
1096
+ await verifyWasmIntegrity(buffer, path, { manifest });
1097
+ const compileStart = performance.now();
1098
+ this.compiledModule = await WebAssembly.compile(buffer);
1099
+ const compileEnd = performance.now();
1100
+ const instStart = performance.now();
1101
+ const instance = await WebAssembly.instantiate(this.compiledModule, this.getImports());
1102
+ const instEnd = performance.now();
1103
+ this.lastMetrics = {
1104
+ fileReadMs: readEnd - readStart,
1105
+ compileMs: compileEnd - compileStart,
1106
+ instantiateMs: instEnd - instStart,
1107
+ totalMs: performance.now() - totalStart,
1108
+ fromCache: false
1109
+ };
1110
+ return instance.exports;
1111
+ }
1112
+ getImports() {
1113
+ return {
1114
+ env: {
1115
+ abort: (msg, file, line, column) => {
1116
+ console.error("WASM abort", {
1117
+ msg,
1118
+ file,
1119
+ line,
1120
+ column
1121
+ });
1122
+ throw new Error("WASM abort");
1123
+ },
1124
+ seed: () => Date.now()
1125
+ },
1126
+ Math,
1127
+ Date
1128
+ };
1129
+ }
1130
+ };
1131
+ //#endregion
1132
+ //#region src/wasm-as-header.ts
1133
+ function allocAsHeader(mod, byteLength, typeId) {
1134
+ const bufferPtr = mod.__pin(mod.__new(byteLength, 1)) >>> 0;
1135
+ const headerPtr = mod.__new(12, typeId) >>> 0;
1136
+ mod.__pin(headerPtr);
1137
+ const dv = new DataView(mod.memory.buffer);
1138
+ dv.setUint32(headerPtr + 0, bufferPtr, true);
1139
+ dv.setUint32(headerPtr + 4, bufferPtr, true);
1140
+ dv.setUint32(headerPtr + 8, byteLength, true);
1141
+ return {
1142
+ headerPtr,
1143
+ bufferPtr
1144
+ };
1145
+ }
987
1146
  //#endregion
988
- export { Unit as CoreUnit, DEFAULT_CONFIG, DimensionError, IndexError, MathjsError, ObjectWrappingMap, PartitionedMap, _switch, acosh, arraySize, asinh, assertDependencies, assign as assignMap, atanh, broadcastArrays, broadcastSizes, broadcastTo, canDefineProperty, cbrt, checkBroadcastingRules, clone, clone$1 as cloneArray, compareText, concat, containsCollections, copysign, cosh, create, createEmptyMap, createIndexError, createMap, createUnitClass, deepExtend, deepFlatten, deepForEach, deepForEach$1 as deepForEachArray, deepMap, deepMap$1 as deepMapArray, deepStrictEqual, defaultWasmLocation, digits, endsWith, escape, expm1, extend, factory, filter, filterRegExp, flatten, forEach, format, format$1 as formatBigNumber, format$2 as formatGeneric, generalize, get, getArrayDataType, get$1 as getArrayElement, hasOwnProperty, identify, initial, isArray, isBigInt, isBigNumber, isBoolean, isCollection, isComplex, isDate, isDenseMatrix, isEmptyIndex, isFactory, isFraction, isFunction, isIndex, isInteger, isLegacyFactory, isMap, isMatrix, isNull, isNumber, isObject, isObjectWrappingMap, isOptionalDependency, isPowZeroAtInfinity, isRange, isRegExp, isSparseMatrix, isString, isUndefined, isUnit, join, last, lazy, loadWasmManifest, log10, log1p, log2, map, mapObject, memoize, nearlyEqual, normalizeFormatOptions, pick, pickShallow, processSizesWildcard, reduce, reshape, resize, resolvePackagedWasm, roundDigits, safeNumberType, scatter, set, sha384OfBuffer, sign, sinh, sortFactories, splitNumber, squeeze, stretch, stringify, stripOptionalNotation, tanh, toEngineering, toEngineering$1 as toEngineeringBigNumber, toExponential, toExponential$1 as toExponentialBigNumber, toFixed, toFixed$1 as toFixedBigNumber, toObject, toPrecision, traverse, typeOf, unitDependencies, unsqueeze, validate, validateIndex, validateIndexSourceSize, verifyWasmIntegrity, warnOnce };
1147
+ export { Unit as CoreUnit, DEFAULT_CONFIG, DimensionError, IndexError, MathjsError, ObjectWrappingMap, PartitionedMap, WasmModuleLoader, _switch, acosh, allocAsHeader, arraySize, asinh, assertDependencies, assign as assignMap, atanh, broadcastArrays, broadcastSizes, broadcastTo, canDefineProperty, cbrt, checkBroadcastingRules, clone, clone$1 as cloneArray, compareText, concat, containsCollections, copysign, cosh, create, createEmptyMap, createIndexError, createMap, createUnitClass, deepExtend, deepFlatten, deepForEach, deepForEach$1 as deepForEachArray, deepMap, deepMap$1 as deepMapArray, deepStrictEqual, defaultWasmLocation, digits, endsWith, escape, expm1, extend, factory, filter, filterRegExp, flatten, forEach, format, format$1 as formatBigNumber, format$2 as formatGeneric, generalize, get, getArrayDataType, get$1 as getArrayElement, hasOwnProperty, identify, initial, isArray, isBigInt, isBigNumber, isBoolean, isCollection, isComplex, isDate, isDenseMatrix, isEmptyIndex, isFactory, isFraction, isFunction, isIndex, isInteger, isLegacyFactory, isMap, isMatrix, isNull, isNumber, isObject, isObjectWrappingMap, isOptionalDependency, isPowZeroAtInfinity, isRange, isRegExp, isSparseMatrix, isString, isUndefined, isUnit, join, last, lazy, loadWasmManifest, log10, log1p, log2, map, mapObject, memoize, nearlyEqual, normalizeFormatOptions, pick, pickShallow, processSizesWildcard, reduce, reshape, resize, resolvePackagedWasm, roundDigits, safeNumberType, scatter, set, sha384OfBuffer, sign, sinh, sortFactories, splitNumber, squeeze, stretch, stringify, stripOptionalNotation, tanh, toEngineering, toEngineering$1 as toEngineeringBigNumber, toExponential, toExponential$1 as toExponentialBigNumber, toFixed, toFixed$1 as toFixedBigNumber, toObject, toPrecision, traverse, typeOf, unitDependencies, unsqueeze, validate, validateIndex, validateIndexSourceSize, verifyWasmIntegrity, warnOnce };