@danielsimonjr/mathts-core 0.14.3 → 0.15.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/dist/arithmetic/scalar.d.ts +56 -0
- package/dist/arithmetic/scalar.d.ts.map +1 -0
- package/dist/array.d.ts +253 -0
- package/dist/array.d.ts.map +1 -0
- package/dist/bignumber-formatter.d.ts +135 -0
- package/dist/bignumber-formatter.d.ts.map +1 -0
- package/dist/collection.d.ts +67 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/constants.d.ts +30 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/customs.d.ts +44 -0
- package/dist/customs.d.ts.map +1 -0
- package/dist/error/DimensionError.d.ts +26 -0
- package/dist/error/DimensionError.d.ts.map +1 -0
- package/dist/error/IndexError.d.ts +33 -0
- package/dist/error/IndexError.d.ts.map +1 -0
- package/dist/error/MathjsError.d.ts +13 -0
- package/dist/error/MathjsError.d.ts.map +1 -0
- package/dist/factory/factory.d.ts +154 -0
- package/dist/factory/factory.d.ts.map +1 -0
- package/dist/factory/index.d.ts +6 -0
- package/dist/factory/index.d.ts.map +1 -0
- package/dist/factory.d.ts +112 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/index.d.ts +24 -2593
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -13
- package/dist/internal.d.ts +33 -1344
- package/dist/internal.d.ts.map +1 -0
- package/dist/is.d.ts +102 -0
- package/dist/is.d.ts.map +1 -0
- package/dist/map.d.ts +113 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/number.d.ts +314 -0
- package/dist/number.d.ts.map +1 -0
- package/dist/numeric/stable.d.ts +130 -0
- package/dist/numeric/stable.d.ts.map +1 -0
- package/dist/object.d.ts +119 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/shared.d.ts +41 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/string.d.ts +70 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/switch.d.ts +9 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/typed/index.d.ts +7 -0
- package/dist/typed/index.d.ts.map +1 -0
- package/dist/typed/mathts-typed.d.ts +246 -0
- package/dist/typed/mathts-typed.d.ts.map +1 -0
- package/dist/typed/type-bridge.d.ts +2 -0
- package/dist/typed/type-bridge.d.ts.map +1 -0
- package/dist/types/bignumber.d.ts +367 -0
- package/dist/types/bignumber.d.ts.map +1 -0
- package/dist/types/complex.d.ts +284 -0
- package/dist/types/complex.d.ts.map +1 -0
- package/dist/types/dual-rules.d.ts +129 -0
- package/dist/types/dual-rules.d.ts.map +1 -0
- package/dist/types/dual.d.ts +36 -0
- package/dist/types/dual.d.ts.map +1 -0
- package/dist/types/fraction.d.ts +215 -0
- package/dist/types/fraction.d.ts.map +1 -0
- package/dist/types/interfaces.d.ts +143 -0
- package/dist/types/interfaces.d.ts.map +1 -0
- package/dist/types/matrix/Range.d.ts +767 -0
- package/dist/types/matrix/Range.d.ts.map +1 -0
- package/dist/types/unit/Unit.d.ts +3 -0
- package/dist/types/unit/Unit.d.ts.map +1 -0
- package/dist/types/unit/dependencies.d.ts +4 -0
- package/dist/types/unit/dependencies.d.ts.map +1 -0
- package/dist/types/unit/errors.d.ts +18 -0
- package/dist/types/unit/errors.d.ts.map +1 -0
- package/dist/types/unit/index.d.ts +7 -0
- package/dist/types/unit/index.d.ts.map +1 -0
- package/dist/types/unit/unit-types.d.ts +231 -0
- package/dist/types/unit/unit-types.d.ts.map +1 -0
- package/dist/types/unit-definitions.d.ts +79 -0
- package/dist/types/unit-definitions.d.ts.map +1 -0
- package/dist/types/unit-prefixes.d.ts +29 -0
- package/dist/types/unit-prefixes.d.ts.map +1 -0
- package/dist/types/unit.d.ts +28 -0
- package/dist/types/unit.d.ts.map +1 -0
- package/dist/types/wasm-loader.d.ts +35 -0
- package/dist/types/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.d.ts +97 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/package.json +8 -8
- package/dist/index-B4LIOfHN.d.ts +0 -449
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numerically stable reduction primitives.
|
|
3
|
+
*
|
|
4
|
+
* Floating-point addition is not associative, so *how* you accumulate decides how much error you
|
|
5
|
+
* carry. These are the algorithms the established numerical stack uses, and the reason it is
|
|
6
|
+
* trusted.
|
|
7
|
+
*
|
|
8
|
+
* Measured on this repo's own reductions before these existed — 1e6 copies of `0.1`, exact answer
|
|
9
|
+
* 100000:
|
|
10
|
+
*
|
|
11
|
+
* | accumulation | relative error |
|
|
12
|
+
* | ------------------------------- | -------------- |
|
|
13
|
+
* | naive `s += x` | **1.3e-11** |
|
|
14
|
+
* | pairwise (this, = NumPy's algo) | **2.9e-16** |
|
|
15
|
+
* | Neumaier compensated (`fsum`) | **0** (exact) |
|
|
16
|
+
*
|
|
17
|
+
* NumPy 2.3.4 reports 2.9e-16 on the same input — we are now at parity. Before this, we were
|
|
18
|
+
* ~46,000× worse than NumPy on a bog-standard `sum`, and `mean`, `std`, `var` and every statistic
|
|
19
|
+
* inherit that error.
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Sum with **pairwise (cascade) summation** — the algorithm behind `np.sum`.
|
|
25
|
+
*
|
|
26
|
+
* Naive accumulation lets the running total grow large while the addends stay small, so each
|
|
27
|
+
* addition rounds off a little more of the total: error grows as **O(n)·ε**. Pairwise summation
|
|
28
|
+
* adds numbers of *comparable magnitude* by recursively halving the range, so error grows as
|
|
29
|
+
* **O(log n)·ε** — for n = 10⁶ that is the difference between ~1e-11 and ~1e-16.
|
|
30
|
+
*
|
|
31
|
+
* It costs the same number of additions as the naive loop. There is no speed/accuracy trade here;
|
|
32
|
+
* the naive version is simply worse.
|
|
33
|
+
*
|
|
34
|
+
* Not exact: for that, use {@link neumaierSum}. Pairwise is the right default because it is free.
|
|
35
|
+
*/
|
|
36
|
+
export declare function pairwiseSum(xs: ArrayLike<number>, start?: number, end?: number): number;
|
|
37
|
+
/**
|
|
38
|
+
* Sum with **Neumaier compensation** — correctly rounded for practical purposes, the equivalent
|
|
39
|
+
* of Python's `math.fsum`.
|
|
40
|
+
*
|
|
41
|
+
* Tracks the low-order bits that each addition throws away and folds them back in at the end. It
|
|
42
|
+
* recovers information that pairwise summation cannot: `[1e16, 1, -1e16]` sums to **1** here,
|
|
43
|
+
* while both naive and pairwise (and `np.sum`) give **0**, because the `1` is annihilated the
|
|
44
|
+
* moment it meets `1e16`.
|
|
45
|
+
*
|
|
46
|
+
* ~2-4× slower than {@link pairwiseSum}, so it is opt-in rather than the default. Reach for it
|
|
47
|
+
* when catastrophic cancellation is possible: near-zero results from large terms, long-running
|
|
48
|
+
* accumulators, conservation checks.
|
|
49
|
+
*
|
|
50
|
+
* (Neumaier's variant, not classic Kahan: Kahan loses the compensation when the *addend* is
|
|
51
|
+
* larger than the running sum, which is precisely the `1e16` case.)
|
|
52
|
+
*/
|
|
53
|
+
export declare function neumaierSum(xs: ArrayLike<number>): number;
|
|
54
|
+
/**
|
|
55
|
+
* Euclidean (2-)norm that does **not** overflow or underflow — BLAS's `dnrm2` scaling.
|
|
56
|
+
*
|
|
57
|
+
* The obvious `sqrt(Σxᵢ²)` squares before it adds, so it dies well inside the representable
|
|
58
|
+
* range: `‖[1e200, 1e200, 1e200, 1e200]‖` overflows to `Infinity` (the true answer, 2e200, is
|
|
59
|
+
* perfectly representable), and `‖[1e-200] × 4‖` **flushes to 0** — a silent wrong answer, which
|
|
60
|
+
* is worse.
|
|
61
|
+
*
|
|
62
|
+
* NumPy has this bug too: `np.linalg.norm([1e200]*4)` returns `inf` with an overflow warning.
|
|
63
|
+
* LAPACK does not, and neither do we.
|
|
64
|
+
*
|
|
65
|
+
* The fix is to carry a running scale: keep the largest magnitude seen out of the sum of squares,
|
|
66
|
+
* so the accumulator only ever holds ratios in [0, 1].
|
|
67
|
+
*/
|
|
68
|
+
export declare function norm2(xs: ArrayLike<number>): number;
|
|
69
|
+
/**
|
|
70
|
+
* Dot product `Σ aᵢ·bᵢ` with **pairwise (cascade) summation** of the products — the accuracy of
|
|
71
|
+
* {@link pairwiseSum} applied to a dot without materialising the product array.
|
|
72
|
+
*
|
|
73
|
+
* A naive `s += a[i]*b[i]` loop carries the same **O(n)·ε** error as a naive sum; measured against
|
|
74
|
+
* an exact reference on an ill-conditioned dot (large mean × small factor, n = 10⁶) it is ~18×
|
|
75
|
+
* worse than `np.dot`, which sums pairwise. This closes that gap — and, like {@link pairwiseSum},
|
|
76
|
+
* costs the same number of flops as the naive loop.
|
|
77
|
+
*
|
|
78
|
+
* The two ranges are assumed the same length; callers guard that. Reads only `[start, end)`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function pairwiseDot(a: ArrayLike<number>, b: ArrayLike<number>, start?: number, end?: number): number;
|
|
81
|
+
/**
|
|
82
|
+
* Euclidean distance `‖a − b‖₂` that does **not** overflow or underflow — {@link norm2}'s BLAS
|
|
83
|
+
* `dnrm2` scaling applied to the elementwise difference.
|
|
84
|
+
*
|
|
85
|
+
* `distance` is just a 2-norm, so the obvious `sqrt(Σ(aᵢ−bᵢ)²)` inherits norm's pathology: it
|
|
86
|
+
* squares before it adds, overflowing to `Infinity` and — the dangerous case — **flushing to a
|
|
87
|
+
* silent 0** for small differences well inside the representable range. NumPy's `linalg.norm` has
|
|
88
|
+
* the same bug; scaling on the largest *difference* seen avoids both. The scale tracks the residual
|
|
89
|
+
* `a − b`, not the inputs, so it stays accurate even when `a` and `b` are individually huge.
|
|
90
|
+
*
|
|
91
|
+
* The two ranges are assumed the same length; callers guard that.
|
|
92
|
+
*/
|
|
93
|
+
export declare function scaledDistance(a: ArrayLike<number>, b: ArrayLike<number>): number;
|
|
94
|
+
/**
|
|
95
|
+
* Sum of squared deviations from the mean, `Σ(xᵢ − x̄)²` — the **corrected two-pass** form, the
|
|
96
|
+
* numerator of a numerically stable variance.
|
|
97
|
+
*
|
|
98
|
+
* Variance is where large means bite: the deviations `xᵢ − x̄` can be O(1) while the values sit on
|
|
99
|
+
* a huge pedestal, so any error in `x̄` rides straight into every deviation. Two things fix it:
|
|
100
|
+
* 1. compute the mean with {@link pairwiseSum}, not a naive running total; and
|
|
101
|
+
* 2. subtract the residual mean-bias term `(Σd)²/n` — `Σd` is zero in exact arithmetic but not in
|
|
102
|
+
* floating point, and that leftover is exactly the systematic error a plain `Σd²` carries.
|
|
103
|
+
*
|
|
104
|
+
* Measured on 1e9-pedestal data: the plain naive two-pass (what shipped) lands ~1e-7 relative error;
|
|
105
|
+
* this lands ~1e-16 — better than `np.var`, which uses the uncorrected two-pass (~1e-13).
|
|
106
|
+
*
|
|
107
|
+
* The deviation vector is never materialised: both pairwise sums walk `xs` in
|
|
108
|
+
* registers, so variance/std no longer pay an extra n-long allocation.
|
|
109
|
+
*
|
|
110
|
+
* Divide the result by `n` (uncorrected), `n − 1` (unbiased/sample), or `n + 1` (biased) for the
|
|
111
|
+
* corresponding variance. Returns 0 for fewer than two elements.
|
|
112
|
+
*/
|
|
113
|
+
export declare function sumSquaredDeviations(xs: ArrayLike<number>): number;
|
|
114
|
+
/**
|
|
115
|
+
* Cumulative sum with **Neumaier compensation** — each prefix total is written to `out[i]` carrying
|
|
116
|
+
* the low-order bits a naive running sum throws away.
|
|
117
|
+
*
|
|
118
|
+
* A cumulative sum is an inherently sequential prefix scan, so pairwise summation does not apply:
|
|
119
|
+
* you need every intermediate total, not just the final one. `np.cumsum` therefore accumulates
|
|
120
|
+
* naively and its tail drifts by **O(n)·ε** (relErr ~1.3e-11 over 10⁶ terms). Carrying a running
|
|
121
|
+
* compensation costs a few extra flops per element, no extra memory, and makes every prefix exact
|
|
122
|
+
* for practical purposes — a strict improvement over NumPy where accumulated drift matters (e.g.
|
|
123
|
+
* integrating a signal).
|
|
124
|
+
*
|
|
125
|
+
* Writes `out[i]` for `i` in `[0, xs.length)`; `out` may be a `number[]` or a `Float64Array`.
|
|
126
|
+
*/
|
|
127
|
+
export declare function neumaierCumsum(xs: ArrayLike<number>, out: {
|
|
128
|
+
[index: number]: number;
|
|
129
|
+
}): void;
|
|
130
|
+
//# sourceMappingURL=stable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stable.d.ts","sourceRoot":"","sources":["../../src/numeric/stable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAWH;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,SAAI,EAAE,GAAG,SAAY,GAAG,MAAM,CAuCrF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAazD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAsBnD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,KAAK,SAAI,EACT,GAAG,SAAW,GACb,MAAM,CAoCR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAqBjF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAelE;AAiFD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,IAAI,CAW5F"}
|
package/dist/object.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { hasOwnProperty } from './shared.js';
|
|
2
|
+
/**
|
|
3
|
+
* Clone an object
|
|
4
|
+
*
|
|
5
|
+
* clone(x)
|
|
6
|
+
*
|
|
7
|
+
* Can clone any primitive type, array, and object.
|
|
8
|
+
* If x has a function clone, this function will be invoked to clone the object.
|
|
9
|
+
*
|
|
10
|
+
* @param {*} x
|
|
11
|
+
* @return {*} clone
|
|
12
|
+
*/
|
|
13
|
+
export declare function clone<T>(x: T): T;
|
|
14
|
+
/**
|
|
15
|
+
* Apply map to all properties of an object
|
|
16
|
+
* @param {Object} object
|
|
17
|
+
* @param {function} callback
|
|
18
|
+
* @return {Object} Returns a copy of the object with mapped properties
|
|
19
|
+
*/
|
|
20
|
+
export declare function mapObject<T, U>(object: Record<string, T>, callback: (value: T) => U): Record<string, U>;
|
|
21
|
+
/**
|
|
22
|
+
* Extend object a with the properties of object b
|
|
23
|
+
* @param {Object} a
|
|
24
|
+
* @param {Object} b
|
|
25
|
+
* @return {Object} a
|
|
26
|
+
*/
|
|
27
|
+
export declare function extend<T extends Record<string, unknown>, U extends Record<string, unknown>>(a: T, b: U): T & U;
|
|
28
|
+
/**
|
|
29
|
+
* Deep extend an object a with the properties of object b
|
|
30
|
+
* @param {Object} a
|
|
31
|
+
* @param {Object} b
|
|
32
|
+
* @returns {Object}
|
|
33
|
+
*/
|
|
34
|
+
export declare function deepExtend<T>(a: T, b: unknown): T;
|
|
35
|
+
/**
|
|
36
|
+
* Deep test equality of all fields in two pairs of arrays or objects.
|
|
37
|
+
* Compares values and functions strictly (ie. 2 is not the same as '2').
|
|
38
|
+
* @param {Array | Object} a
|
|
39
|
+
* @param {Array | Object} b
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
export declare function deepStrictEqual(a: unknown, b: unknown): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Recursively flatten a nested object.
|
|
45
|
+
* @param {Object} nestedObject
|
|
46
|
+
* @return {Object} Returns the flattened object
|
|
47
|
+
*/
|
|
48
|
+
export declare function deepFlatten(nestedObject: Record<string, unknown>): Record<string, unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Test whether the current JavaScript engine supports Object.defineProperty
|
|
51
|
+
* @returns {boolean} returns true if supported
|
|
52
|
+
*/
|
|
53
|
+
export declare function canDefineProperty(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Attach a lazy loading property to a constant.
|
|
56
|
+
* The given function `fn` is called once when the property is first requested.
|
|
57
|
+
*
|
|
58
|
+
* @param {Object} object Object where to add the property
|
|
59
|
+
* @param {string} prop Property name
|
|
60
|
+
* @param {Function} valueResolver Function returning the property value. Called
|
|
61
|
+
* without arguments.
|
|
62
|
+
*/
|
|
63
|
+
export declare function lazy<T>(object: Record<string, unknown>, prop: string, valueResolver: () => T): void;
|
|
64
|
+
/**
|
|
65
|
+
* Traverse a path into an object.
|
|
66
|
+
* When a namespace is missing, it will be created
|
|
67
|
+
* @param {Object} object
|
|
68
|
+
* @param {string | string[]} path A dot separated string like 'name.space'
|
|
69
|
+
* @return {Object} Returns the object at the end of the path
|
|
70
|
+
*/
|
|
71
|
+
export declare function traverse(object: Record<string, unknown>, path: string | string[]): Record<string, unknown>;
|
|
72
|
+
export { hasOwnProperty };
|
|
73
|
+
/**
|
|
74
|
+
* Test whether an object is a factory. a factory has fields:
|
|
75
|
+
*
|
|
76
|
+
* - factory: function (type: Object, config: Object, load: function, typed: function [, math: Object]) (required)
|
|
77
|
+
* - name: string (optional)
|
|
78
|
+
* - path: string A dot separated path (optional)
|
|
79
|
+
* - math: boolean If true (false by default), the math namespace is passed
|
|
80
|
+
* as fifth argument of the factory function
|
|
81
|
+
*
|
|
82
|
+
* @param {*} object
|
|
83
|
+
* @returns {boolean}
|
|
84
|
+
*/
|
|
85
|
+
export declare function isLegacyFactory(object: unknown): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Get a nested property from an object
|
|
88
|
+
* @param {Object} object
|
|
89
|
+
* @param {string | string[]} path
|
|
90
|
+
* @returns {Object}
|
|
91
|
+
*/
|
|
92
|
+
export declare function get(object: Record<string, unknown>, path: string | string[]): unknown;
|
|
93
|
+
/**
|
|
94
|
+
* Set a nested property in an object
|
|
95
|
+
* Mutates the object itself
|
|
96
|
+
* If the path doesn't exist, it will be created
|
|
97
|
+
* @param {Object} object
|
|
98
|
+
* @param {string | string[]} path
|
|
99
|
+
* @param {*} value
|
|
100
|
+
* @returns {Object}
|
|
101
|
+
*/
|
|
102
|
+
export declare function set<T extends Record<string, unknown>>(object: T, path: string | string[], value: unknown): T;
|
|
103
|
+
/**
|
|
104
|
+
* Create an object composed of the picked object properties
|
|
105
|
+
* @param {Object} object
|
|
106
|
+
* @param {string[]} properties
|
|
107
|
+
* @param {function} [transform] Optional value to transform a value when picking it
|
|
108
|
+
* @return {Object}
|
|
109
|
+
*/
|
|
110
|
+
export declare function pick(object: Record<string, unknown>, properties: string[], transform?: (value: unknown, key: string) => unknown): Record<string, unknown>;
|
|
111
|
+
/**
|
|
112
|
+
* Shallow version of pick, creating an object composed of the picked object properties
|
|
113
|
+
* but not for nested properties
|
|
114
|
+
* @param {Object} object
|
|
115
|
+
* @param {string[]} properties
|
|
116
|
+
* @return {Object}
|
|
117
|
+
*/
|
|
118
|
+
export declare function pickShallow(object: Record<string, unknown>, properties: string[]): Record<string, unknown>;
|
|
119
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAwChC;AAED;;;;;GAKG;AACH,wBAA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E1B;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAiBrF;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnD,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,KAAK,EAAE,OAAO,GACb,CAAC,CAyBH;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,UAAU,EAAE,MAAM,EAAE,EACpB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,GACnD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,UAAU,EAAE,MAAM,EAAE,GACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility functions used across core utility modules.
|
|
3
|
+
* This file must have ZERO imports from other core utility files
|
|
4
|
+
* to serve as the base of the dependency graph and break circular imports.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A safe hasOwnProperty
|
|
8
|
+
* @param {Object} object
|
|
9
|
+
* @param {string} property
|
|
10
|
+
*/
|
|
11
|
+
export declare function hasOwnProperty(object: unknown, property: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* True when `text` ends with `search`. (Equivalent to `String.prototype.endsWith`;
|
|
14
|
+
* kept as a named helper so relocated modules read the same as their mathjs origin.)
|
|
15
|
+
*/
|
|
16
|
+
export declare function endsWith(text: string, search: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Warn to the console at most once per distinct message, deduped for the process
|
|
19
|
+
* lifetime. Used for deprecation notices (e.g. `Unit.toNumber`).
|
|
20
|
+
*/
|
|
21
|
+
export declare const warnOnce: (...args: unknown[]) => void;
|
|
22
|
+
/** A function whose results are cached; clear the cache with `delete fn.cache`. */
|
|
23
|
+
export interface MemoizedFunction {
|
|
24
|
+
(...args: unknown[]): unknown;
|
|
25
|
+
cache?: Map<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Memoize a pure function, caching results in a `Map` keyed by a string hash of the
|
|
29
|
+
* arguments (default `JSON.stringify`; override via `hasher`). Pass `limit` to bound
|
|
30
|
+
* the cache to N most-recently-used entries (LRU eviction via `Map` insertion order —
|
|
31
|
+
* on a hit the key is moved to the most-recent end; on overflow the oldest key is
|
|
32
|
+
* dropped); omit for an unbounded cache. The cache is exposed as `fn.cache` and can be
|
|
33
|
+
* reset with `delete fn.cache` — the next call lazily recreates it. (The relocated
|
|
34
|
+
* `Unit` relies on that reset when `createUnit`/`deleteUnit` invalidate the unit-name
|
|
35
|
+
* lookup cache, and passes `limit: 100` to bound the parse cache.)
|
|
36
|
+
*/
|
|
37
|
+
export declare function memoize(fn: (...args: unknown[]) => unknown, { hasher, limit }?: {
|
|
38
|
+
hasher?: (args: unknown[]) => string;
|
|
39
|
+
limit?: number;
|
|
40
|
+
}): MemoizedFunction;
|
|
41
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAG9D;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,YAGe,OAAO,EAAE,KAAG,IAO5C,CAAC;AAEL,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC9B,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9B;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CACrB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACnC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/E,gBAAgB,CA2BlB"}
|
package/dist/string.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type FormatOptions } from './number.js';
|
|
2
|
+
/**
|
|
3
|
+
* Formatting options accepted by the generic `format` helper. Extends the
|
|
4
|
+
* numeric {@link FormatOptions} with the string-level `truncate` and the
|
|
5
|
+
* fraction rendering mode, or is a precision number, or a custom formatter.
|
|
6
|
+
*/
|
|
7
|
+
export type GeneralFormatOptions = number | ((value: unknown) => string) | (FormatOptions & {
|
|
8
|
+
truncate?: number;
|
|
9
|
+
fraction?: 'ratio' | 'decimal';
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Format a value of any type into a string.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* math.format(value)
|
|
16
|
+
* math.format(value, precision)
|
|
17
|
+
* math.format(value, options)
|
|
18
|
+
*
|
|
19
|
+
* When value is a function:
|
|
20
|
+
*
|
|
21
|
+
* - When the function has a property `syntax`, it returns this
|
|
22
|
+
* syntax description.
|
|
23
|
+
* - In other cases, a string `'function'` is returned.
|
|
24
|
+
*
|
|
25
|
+
* When `value` is an Object:
|
|
26
|
+
*
|
|
27
|
+
* - When the object contains a property `format` being a function, this
|
|
28
|
+
* function is invoked as `value.format(options)` and the result is returned.
|
|
29
|
+
* - When the object has its own `toString` method, this method is invoked
|
|
30
|
+
* and the result is returned.
|
|
31
|
+
* - In other cases the function will loop over all object properties and
|
|
32
|
+
* return JSON object notation like '{"a": 2, "b": 3}'.
|
|
33
|
+
*
|
|
34
|
+
* Example usage:
|
|
35
|
+
* math.format(2/7) // '0.2857142857142857'
|
|
36
|
+
* math.format(math.pi, 3) // '3.14'
|
|
37
|
+
* math.format(new Complex(2, 3)) // '2 + 3i'
|
|
38
|
+
* math.format('hello') // '"hello"'
|
|
39
|
+
*
|
|
40
|
+
* @param {*} value Value to be stringified
|
|
41
|
+
* @param {Object | number | Function} [options]
|
|
42
|
+
* Formatting options. See src/utils/number.js:format for a
|
|
43
|
+
* description of the available options controlling number output.
|
|
44
|
+
* This generic "format" also supports the option property `truncate: NN`
|
|
45
|
+
* giving the maximum number NN of characters to return (if there would
|
|
46
|
+
* have been more, they are deleted and replaced by an ellipsis).
|
|
47
|
+
* @return {string} str
|
|
48
|
+
*/
|
|
49
|
+
export declare function format(value: unknown, options?: unknown): string;
|
|
50
|
+
/**
|
|
51
|
+
* Stringify a value into a string enclosed in double quotes.
|
|
52
|
+
* Unescaped double quotes and backslashes inside the value are escaped.
|
|
53
|
+
* @param {*} value
|
|
54
|
+
* @return {string}
|
|
55
|
+
*/
|
|
56
|
+
export declare function stringify(value: unknown): string;
|
|
57
|
+
/**
|
|
58
|
+
* Escape special HTML characters
|
|
59
|
+
* @param {*} value
|
|
60
|
+
* @return {string}
|
|
61
|
+
*/
|
|
62
|
+
export declare function escape(value: unknown): string;
|
|
63
|
+
/**
|
|
64
|
+
* Compare two strings
|
|
65
|
+
* @param {string} x
|
|
66
|
+
* @param {string} y
|
|
67
|
+
* @returns {number}
|
|
68
|
+
*/
|
|
69
|
+
export declare function compareText(x: unknown, y: unknown): number;
|
|
70
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAoBA,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAGzE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAC5B,MAAM,GACN,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,GAC5B,CAAC,aAAa,GAAG;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,CAAC,CAAC;AASP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAShE;AA2DD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAWhD;AAYD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAU7C;AA8CD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAoB1D"}
|
package/dist/switch.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transpose a 2D array. Private helper used only by `core/src/collection.ts`'s
|
|
3
|
+
* `_reduce` (Bucket B slice 2 canonical) — mirrors `expression/src/utils/switch.ts`
|
|
4
|
+
* / `functions/src/utils/switch.ts`, which remain in place unchanged for now
|
|
5
|
+
* (not part of this slice's named scope). Not exported from `internal.ts`.
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export declare function _switch<T>(mat: T[][]): T[][];
|
|
9
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../src/switch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAa5C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* typed-function integration exports
|
|
3
|
+
*/
|
|
4
|
+
export { mathTyped, createMathTSTyped, typed, create, createTypedFunction, TypeRegistry, MATHTS_TYPES, MATHTS_CONVERSIONS, isNumber, isBoolean, isString, isBigInt, isArray, isFunction, isObject, isNull, isUndefined, isComplex, isFraction, isBigNumber, isFloat64Array, isFloat32Array, isInt32Array, isUint32Array, isUint8Array, isMatrix, isDenseMatrix, isSparseMatrix, isUnit, initTypedWasm, isTypedWasmAvailable, } from './mathts-typed.js';
|
|
5
|
+
export type { TypedFunction, TypedInstance, TypeDef, ConversionDef, SignatureFunction, ReferTo, ReferToSelf, } from './mathts-typed.js';
|
|
6
|
+
export { registerNativeTypes } from './type-bridge.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/typed/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEL,SAAS,EACT,iBAAiB,EACjB,KAAK,EACL,MAAM,EACN,mBAAmB,EACnB,YAAY,EAGZ,YAAY,EACZ,kBAAkB,EAGlB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EAGX,SAAS,EACT,UAAU,EACV,WAAW,EAGX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EAGZ,QAAQ,EACR,aAAa,EACb,cAAc,EAGd,MAAM,EAGN,aAAa,EACb,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,aAAa,EACb,aAAa,EACb,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MathTS typed-function Integration
|
|
3
|
+
*
|
|
4
|
+
* Creates a configured typed-function instance with MathTS types
|
|
5
|
+
* for runtime type dispatch across numeric types, matrices, and more.
|
|
6
|
+
*
|
|
7
|
+
* This module directly uses the typed-function library API without
|
|
8
|
+
* any intermediate abstraction layers.
|
|
9
|
+
*
|
|
10
|
+
* Supports WASM-accelerated dispatch when available.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
import typed, { create } from 'typed-function';
|
|
15
|
+
import type { TypedFunction, TypedInstance, SignatureFunction, ReferTo, ReferToSelf } from 'typed-function';
|
|
16
|
+
/**
|
|
17
|
+
* Initialize WASM dispatch for typed-function (optional, improves performance)
|
|
18
|
+
*
|
|
19
|
+
* Uses the unified typed.init() API to enable WASM-accelerated dispatch
|
|
20
|
+
* with automatic fallback to pure JS when WASM is unavailable.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Initialization options
|
|
23
|
+
* @returns Promise resolving to true if WASM was initialized successfully
|
|
24
|
+
*/
|
|
25
|
+
export declare function initTypedWasm(options?: {
|
|
26
|
+
preferWasm?: boolean;
|
|
27
|
+
}): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Check if WASM dispatch is available
|
|
30
|
+
*/
|
|
31
|
+
export declare function isTypedWasmAvailable(): boolean;
|
|
32
|
+
import { Complex } from '../types/complex.js';
|
|
33
|
+
import { Fraction } from '../types/fraction.js';
|
|
34
|
+
import { BigNumber } from '../types/bignumber.js';
|
|
35
|
+
export type { TypedFunction, TypedInstance, SignatureFunction, ReferTo, ReferToSelf };
|
|
36
|
+
/**
|
|
37
|
+
* Any concrete implementation accepted when *declaring* a typed signature.
|
|
38
|
+
*
|
|
39
|
+
* typed-function's published `SignatureFunction` is `(...args: unknown[]) =>
|
|
40
|
+
* unknown`, which is correct for *internal/output* positions (where the stored
|
|
41
|
+
* impl is later CALLED with validated args) but wrong as an *input* type:
|
|
42
|
+
* under `strictFunctionTypes`, function parameters are contravariant, so a
|
|
43
|
+
* concrete impl such as `(a: number, b: number) => number` is NOT assignable
|
|
44
|
+
* to an `unknown[]` parameter list (`unknown` is not assignable to `number`).
|
|
45
|
+
* The correct top-type for "any function" in an input position uses `never`
|
|
46
|
+
* parameters — every function is assignable to it because `never` is
|
|
47
|
+
* assignable to every parameter type. This is exactly the set of values
|
|
48
|
+
* typed-function genuinely accepts when declaring signatures.
|
|
49
|
+
*/
|
|
50
|
+
export type SignatureImpl = (...args: never[]) => unknown;
|
|
51
|
+
/** Signature record accepted by the MathTS typed factory (see {@link SignatureImpl}). */
|
|
52
|
+
export type SignatureRecord = Record<string, SignatureImpl | ReferTo | ReferToSelf>;
|
|
53
|
+
/**
|
|
54
|
+
* The MathTS typed-function factory type.
|
|
55
|
+
*
|
|
56
|
+
* Structurally identical to typed-function's {@link TypedInstance} except its
|
|
57
|
+
* call signatures accept implementations declared with concrete parameter
|
|
58
|
+
* types (see {@link SignatureImpl}). All instance methods are inherited
|
|
59
|
+
* unchanged via `Omit<TypedInstance, never>` (a mapped type, which drops the
|
|
60
|
+
* overly-strict published call signatures while preserving every method).
|
|
61
|
+
*/
|
|
62
|
+
export interface MathTSTyped extends Omit<TypedInstance, never> {
|
|
63
|
+
(name: string, signatures: SignatureRecord): TypedFunction;
|
|
64
|
+
(signatures: SignatureRecord): TypedFunction;
|
|
65
|
+
(...args: Array<string | SignatureRecord | TypedFunction | (SignatureImpl & {
|
|
66
|
+
signature: string;
|
|
67
|
+
})>): TypedFunction;
|
|
68
|
+
referToSelf: (callback: (self: TypedFunction) => SignatureImpl) => ReferToSelf;
|
|
69
|
+
referTo: (...args: [...string[], (...fns: SignatureFunction[]) => SignatureImpl]) => ReferTo;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Type definition for typed-function
|
|
73
|
+
*/
|
|
74
|
+
export interface TypeDef {
|
|
75
|
+
name: string;
|
|
76
|
+
test: (x: unknown) => boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Conversion definition for typed-function
|
|
80
|
+
*/
|
|
81
|
+
export interface ConversionDef {
|
|
82
|
+
from: string;
|
|
83
|
+
to: string;
|
|
84
|
+
convert: (value: unknown) => unknown;
|
|
85
|
+
}
|
|
86
|
+
export declare const isNumber: (x: unknown) => x is number;
|
|
87
|
+
export declare const isBoolean: (x: unknown) => x is boolean;
|
|
88
|
+
export declare const isString: (x: unknown) => x is string;
|
|
89
|
+
export declare const isBigInt: (x: unknown) => x is bigint;
|
|
90
|
+
export declare const isArray: (x: unknown) => x is unknown[];
|
|
91
|
+
export declare const isFunction: (x: unknown) => x is (...args: unknown[]) => unknown;
|
|
92
|
+
export declare const isObject: (x: unknown) => x is object;
|
|
93
|
+
export declare const isNull: (x: unknown) => x is null;
|
|
94
|
+
export declare const isUndefined: (x: unknown) => x is undefined;
|
|
95
|
+
export declare const isFloat64Array: (x: unknown) => x is Float64Array;
|
|
96
|
+
export declare const isFloat32Array: (x: unknown) => x is Float32Array;
|
|
97
|
+
export declare const isInt32Array: (x: unknown) => x is Int32Array;
|
|
98
|
+
export declare const isUint32Array: (x: unknown) => x is Uint32Array;
|
|
99
|
+
export declare const isUint8Array: (x: unknown) => x is Uint8Array;
|
|
100
|
+
/**
|
|
101
|
+
* Check if value is a Complex number
|
|
102
|
+
*/
|
|
103
|
+
export declare const isComplex: (x: unknown) => x is Complex;
|
|
104
|
+
/**
|
|
105
|
+
* Check if value is a Fraction
|
|
106
|
+
*/
|
|
107
|
+
export declare const isFraction: (x: unknown) => x is Fraction;
|
|
108
|
+
/**
|
|
109
|
+
* Check if value is a BigNumber
|
|
110
|
+
*/
|
|
111
|
+
export declare const isBigNumber: (x: unknown) => x is BigNumber;
|
|
112
|
+
/**
|
|
113
|
+
* Check if value is a Matrix (duck typing until Matrix class is implemented)
|
|
114
|
+
*/
|
|
115
|
+
export declare const isMatrix: (x: unknown) => boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Check if value is a DenseMatrix
|
|
118
|
+
*/
|
|
119
|
+
export declare const isDenseMatrix: (x: unknown) => boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Check if value is a SparseMatrix
|
|
122
|
+
*/
|
|
123
|
+
export declare const isSparseMatrix: (x: unknown) => boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Check if value is a Unit
|
|
126
|
+
*
|
|
127
|
+
* Recognises both the native {@link Unit} class (which exposes `value`,
|
|
128
|
+
* `dimensions`, and `notation`) and the legacy duck-typed shape used by
|
|
129
|
+
* mathjs-compatibility shims (`{ value, unit, type }`).
|
|
130
|
+
*/
|
|
131
|
+
export declare const isUnit: (x: unknown) => boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Extended type definition with optional WASM mask support
|
|
134
|
+
*/
|
|
135
|
+
export interface MathTSTypeDef extends TypeDef {
|
|
136
|
+
/** Optional WASM type mask for accelerated dispatch (auto-registered when WASM available) */
|
|
137
|
+
wasmMask?: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* MathTS-specific types to add to typed-function.
|
|
141
|
+
* Note: Most primitive types (number, boolean, string, etc.) are already built into typed-function
|
|
142
|
+
*
|
|
143
|
+
* When WASM is available, custom type masks are automatically registered for efficient dispatch.
|
|
144
|
+
*/
|
|
145
|
+
export declare const MATHTS_TYPES: MathTSTypeDef[];
|
|
146
|
+
export declare const MATHTS_CONVERSIONS: ConversionDef[];
|
|
147
|
+
/**
|
|
148
|
+
* Create a new MathTS typed instance
|
|
149
|
+
*
|
|
150
|
+
* This creates an isolated typed universe with MathTS types and conversions.
|
|
151
|
+
* Uses typed-function's addType() API which automatically registers WASM
|
|
152
|
+
* type masks when available.
|
|
153
|
+
*
|
|
154
|
+
* @returns A new typed-function instance configured for MathTS
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const myTyped = createMathTSTyped();
|
|
159
|
+
*
|
|
160
|
+
* const add = myTyped('add', {
|
|
161
|
+
* 'number, number': (a, b) => a + b,
|
|
162
|
+
* 'Complex, Complex': (a, b) => a.add(b),
|
|
163
|
+
* 'Fraction, Fraction': (a, b) => a.add(b),
|
|
164
|
+
* 'BigNumber, BigNumber': (a, b) => a.add(b),
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function createMathTSTyped(): TypedInstance;
|
|
169
|
+
/**
|
|
170
|
+
* Default MathTS typed instance
|
|
171
|
+
*
|
|
172
|
+
* This is the primary typed-function instance used throughout MathTS.
|
|
173
|
+
* It comes pre-configured with all MathTS types and conversions.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* import { mathTyped, Complex, Fraction, BigNumber } from '@danielsimonjr/mathts-core';
|
|
178
|
+
*
|
|
179
|
+
* // Create a polymorphic add function
|
|
180
|
+
* const add = mathTyped('add', {
|
|
181
|
+
* 'number, number': (a, b) => a + b,
|
|
182
|
+
* 'Complex, Complex': (a, b) => a.add(b),
|
|
183
|
+
* 'Fraction, Fraction': (a, b) => a.add(b),
|
|
184
|
+
* 'BigNumber, BigNumber': (a, b) => a.add(b),
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* // Works with automatic type coercion
|
|
188
|
+
* add(1, 2); // 3
|
|
189
|
+
* add(new Complex(1, 2), new Complex(3, 4)); // Complex(4, 6)
|
|
190
|
+
* add(new Fraction(1, 2), new Fraction(1, 3)); // Fraction(5, 6)
|
|
191
|
+
* add(1, new Complex(2, 3)); // Complex(3, 3) - auto-converts
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare const mathTyped: MathTSTyped;
|
|
195
|
+
/**
|
|
196
|
+
* The default typed-function export (for creating functions without MathTS types)
|
|
197
|
+
*/
|
|
198
|
+
export { typed };
|
|
199
|
+
/**
|
|
200
|
+
* Create a new typed-function instance (typed-function's create)
|
|
201
|
+
*/
|
|
202
|
+
export { create };
|
|
203
|
+
/**
|
|
204
|
+
* TypeRegistry class for managing custom type registrations
|
|
205
|
+
* This is a MathTS utility, not from typed-function
|
|
206
|
+
*/
|
|
207
|
+
export declare class TypeRegistry {
|
|
208
|
+
private types;
|
|
209
|
+
private conversions;
|
|
210
|
+
private instance;
|
|
211
|
+
/**
|
|
212
|
+
* Register a new type
|
|
213
|
+
*/
|
|
214
|
+
registerType<T>(name: string, test: (x: unknown) => x is T): this;
|
|
215
|
+
/**
|
|
216
|
+
* Register a type conversion
|
|
217
|
+
*/
|
|
218
|
+
registerConversion<From, To>(from: string, to: string, convert: (value: From) => To): this;
|
|
219
|
+
/**
|
|
220
|
+
* Check if a type is registered
|
|
221
|
+
*/
|
|
222
|
+
hasType(name: string): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Check if a conversion is registered
|
|
225
|
+
*/
|
|
226
|
+
hasConversion(from: string, to: string): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Get all registered type names
|
|
229
|
+
*/
|
|
230
|
+
getTypeNames(): string[];
|
|
231
|
+
/**
|
|
232
|
+
* Build a typed-function instance from the registry
|
|
233
|
+
*/
|
|
234
|
+
build(): TypedInstance;
|
|
235
|
+
/**
|
|
236
|
+
* Clear all registered types and conversions
|
|
237
|
+
*/
|
|
238
|
+
clear(): void;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Helper to create a typed function with the MathTS typed instance
|
|
242
|
+
*/
|
|
243
|
+
export declare function createTypedFunction<T>(name: string, signatures: {
|
|
244
|
+
[signature: string]: (...args: unknown[]) => T;
|
|
245
|
+
}, typedInstance?: TypedInstance): (...args: unknown[]) => T;
|
|
246
|
+
//# sourceMappingURL=mathts-typed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mathts-typed.d.ts","sourceRoot":"","sources":["../../src/typed/mathts-typed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAMxB;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB5F;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAG9C;AAED,OAAO,EAAE,OAAO,EAA2B,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAA6B,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAA+B,MAAM,uBAAuB,CAAC;AAM/E,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAEtF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAE1D,yFAAyF;AACzF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,GAAG,WAAW,CAAC,CAAC;AAEpF;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC;IAC7D,CAAC,IA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