@topolab/tda 0.0.0-stage → 0.4.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/CHANGELOG.md +106 -0
- package/CITATION.cff +72 -0
- package/LICENSE +21 -0
- package/README.md +100 -2
- package/SECURITY.md +34 -0
- package/THIRD_PARTY_LICENSES.md +697 -0
- package/dist/arrangement.d.ts +50 -0
- package/dist/arrangement.d.ts.map +1 -0
- package/dist/arrangement.js +63 -0
- package/dist/arrangement.js.map +1 -0
- package/dist/build_info.json +12 -0
- package/dist/check.d.ts +118 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +298 -0
- package/dist/check.js.map +1 -0
- package/dist/complex.d.ts +543 -0
- package/dist/complex.d.ts.map +1 -0
- package/dist/complex.js +712 -0
- package/dist/complex.js.map +1 -0
- package/dist/diagram.d.ts +116 -0
- package/dist/diagram.d.ts.map +1 -0
- package/dist/diagram.js +238 -0
- package/dist/diagram.js.map +1 -0
- package/dist/diagram_of.d.ts +17 -0
- package/dist/diagram_of.d.ts.map +1 -0
- package/dist/diagram_of.js +40 -0
- package/dist/diagram_of.js.map +1 -0
- package/dist/experimental.d.ts +18 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +16 -0
- package/dist/experimental.js.map +1 -0
- package/dist/flat.d.ts +64 -0
- package/dist/flat.d.ts.map +1 -0
- package/dist/flat.js +158 -0
- package/dist/flat.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/ladder/tda_ladder.d.ts +223 -0
- package/dist/ladder/tda_ladder.js +1360 -0
- package/dist/ladder/tda_ladder_bg.wasm +0 -0
- package/dist/ladder/tda_ladder_bg.wasm.d.ts +43 -0
- package/dist/ladder.d.ts +306 -0
- package/dist/ladder.d.ts.map +1 -0
- package/dist/ladder.js +607 -0
- package/dist/ladder.js.map +1 -0
- package/dist/load.d.ts +53 -0
- package/dist/load.d.ts.map +1 -0
- package/dist/load.js +173 -0
- package/dist/load.js.map +1 -0
- package/dist/memory.d.ts +58 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +2 -0
- package/dist/memory.js.map +1 -0
- package/dist/persistence.d.ts +349 -0
- package/dist/persistence.d.ts.map +1 -0
- package/dist/persistence.js +478 -0
- package/dist/persistence.js.map +1 -0
- package/dist/pkg/tda_wasm.d.ts +13 -0
- package/dist/pkg/tda_wasm.js +2528 -0
- package/dist/prepared.d.ts +62 -0
- package/dist/prepared.d.ts.map +1 -0
- package/dist/prepared.js +81 -0
- package/dist/prepared.js.map +1 -0
- package/dist/rivet_input.d.ts +93 -0
- package/dist/rivet_input.d.ts.map +1 -0
- package/dist/rivet_input.js +132 -0
- package/dist/rivet_input.js.map +1 -0
- package/dist/source.d.ts +43 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +99 -0
- package/dist/source.js.map +1 -0
- package/dist/tda.wasm +0 -0
- package/dist/two_parameter.d.ts +243 -0
- package/dist/two_parameter.d.ts.map +1 -0
- package/dist/two_parameter.js +275 -0
- package/dist/two_parameter.js.map +1 -0
- package/dist/types.d.ts +146 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vineyard.d.ts +278 -0
- package/dist/vineyard.d.ts.map +1 -0
- package/dist/vineyard.js +236 -0
- package/dist/vineyard.js.map +1 -0
- package/package.json +77 -4
- package/src/arrangement.ts +96 -0
- package/src/check.ts +338 -0
- package/src/complex.ts +1179 -0
- package/src/diagram.ts +299 -0
- package/src/diagram_of.ts +40 -0
- package/src/experimental.ts +17 -0
- package/src/flat.ts +204 -0
- package/src/index.ts +181 -0
- package/src/ladder.ts +903 -0
- package/src/load.ts +201 -0
- package/src/memory.ts +58 -0
- package/src/persistence.ts +752 -0
- package/src/prepared.ts +111 -0
- package/src/rivet_input.ts +195 -0
- package/src/source.ts +132 -0
- package/src/two_parameter.ts +480 -0
- package/src/types.ts +163 -0
- package/src/vineyard.ts +463 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { PersistenceOptions } from './persistence.js';
|
|
2
|
+
import type { ComplexLike, Diagram, Scale } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A complex validated, copied and prepared once by {@link prepareComplex}
|
|
5
|
+
* (canonical simplex order and boundary indices held in the module's memory),
|
|
6
|
+
* answering {@link PreparedComplex.persistence} without repeating that work.
|
|
7
|
+
* The object is frozen.
|
|
8
|
+
*/
|
|
9
|
+
export interface PreparedComplex {
|
|
10
|
+
/** The number of simplices of the snapshot. */
|
|
11
|
+
readonly size: number;
|
|
12
|
+
/** The scale of the snapshot's values, copied from the input (`'value'` when it had none). */
|
|
13
|
+
readonly scale: Scale;
|
|
14
|
+
/** `true` once {@link PreparedComplex.dispose} or `unload()` has released the native snapshot. */
|
|
15
|
+
readonly disposed: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The persistence diagram of the snapshot: the same arrays, in the same
|
|
18
|
+
* order, as `persistence(complex, opts)` of the complex as it was when it
|
|
19
|
+
* was prepared. Every call runs the reduction; no diagram is cached. The
|
|
20
|
+
* result is a plain copy that owns no wasm memory: it stays valid after
|
|
21
|
+
* disposal and after `unload()`, and survives `postMessage`. Throws an
|
|
22
|
+
* `Error` once the handle is disposed; a bad option throws as
|
|
23
|
+
* `persistence` does (`TypeError` or `RangeError`).
|
|
24
|
+
*/
|
|
25
|
+
persistence(opts?: PersistenceOptions): Diagram;
|
|
26
|
+
/**
|
|
27
|
+
* Releases the native snapshot. Idempotent: a second call does nothing.
|
|
28
|
+
* Call it when done; until then the handle is held by the module's
|
|
29
|
+
* cleanup list, so dropping the last reference does not free it before
|
|
30
|
+
* `unload()`.
|
|
31
|
+
*/
|
|
32
|
+
dispose(): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* **Experimental.** Validate, copy and prepare `complex` once, for repeated
|
|
36
|
+
* persistence queries (other fields, other `minPersistence` cutoffs). The
|
|
37
|
+
* checks are those of `persistence`: a complex that `persistence` refuses,
|
|
38
|
+
* `prepareComplex` refuses with the same error, and no handle is created.
|
|
39
|
+
*
|
|
40
|
+
* Ownership:
|
|
41
|
+
* - The snapshot is a copy: changing the input arrays afterwards does not
|
|
42
|
+
* change it. A changed topology or filtration needs a new handle.
|
|
43
|
+
* - Every diagram is an independent copy and remains valid after disposal
|
|
44
|
+
* or `unload()`; diagrams can be sent through `postMessage`.
|
|
45
|
+
* - The handle belongs to the module instance (one per thread) that made it
|
|
46
|
+
* and cannot be transferred or cloned. Another worker prepares its own
|
|
47
|
+
* snapshot from the plain complex.
|
|
48
|
+
* - `dispose()` is idempotent; `persistence` on a disposed handle throws an
|
|
49
|
+
* `Error`.
|
|
50
|
+
* - `unload()` disposes every outstanding handle, and a later `load()` never
|
|
51
|
+
* revives one. So does a trap of the module (a call that runs out of
|
|
52
|
+
* memory), which replaces its instance. Undisposed handles stay allocated until `unload()`, so dispose
|
|
53
|
+
* each one explicitly.
|
|
54
|
+
* - Native allocations are freed on disposal, but the wasm linear memory
|
|
55
|
+
* does not shrink: its high-water mark stays until the module is unloaded
|
|
56
|
+
* and collected.
|
|
57
|
+
*
|
|
58
|
+
* The ordinary `persistence(complex)` stays stateless; nothing here caches a
|
|
59
|
+
* caller's object or a result.
|
|
60
|
+
*/
|
|
61
|
+
export declare function prepareComplex(complex: ComplexLike): PreparedComplex;
|
|
62
|
+
//# sourceMappingURL=prepared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepared.d.ts","sourceRoot":"","sources":["../src/prepared.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,kGAAkG;IAClG,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B;;;;;;;;OAQG;IACH,WAAW,CAAC,IAAI,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC;IAChD;;;;;OAKG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,eAAe,CAwCpE"}
|
package/dist/prepared.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepared complexes: a native snapshot of a complex that answers repeated
|
|
3
|
+
* persistence queries. Exported only from `@topolab/tda/experimental`.
|
|
4
|
+
*/
|
|
5
|
+
import { call, module, onUnload } from './load.js';
|
|
6
|
+
import { coeff as checkCoeff, minPersistence as checkMinPersistence, options } from './check.js';
|
|
7
|
+
import { complexArgs, PERSISTENCE_KEYS } from './persistence.js';
|
|
8
|
+
import { diagramOf } from './diagram_of.js';
|
|
9
|
+
/**
|
|
10
|
+
* **Experimental.** Validate, copy and prepare `complex` once, for repeated
|
|
11
|
+
* persistence queries (other fields, other `minPersistence` cutoffs). The
|
|
12
|
+
* checks are those of `persistence`: a complex that `persistence` refuses,
|
|
13
|
+
* `prepareComplex` refuses with the same error, and no handle is created.
|
|
14
|
+
*
|
|
15
|
+
* Ownership:
|
|
16
|
+
* - The snapshot is a copy: changing the input arrays afterwards does not
|
|
17
|
+
* change it. A changed topology or filtration needs a new handle.
|
|
18
|
+
* - Every diagram is an independent copy and remains valid after disposal
|
|
19
|
+
* or `unload()`; diagrams can be sent through `postMessage`.
|
|
20
|
+
* - The handle belongs to the module instance (one per thread) that made it
|
|
21
|
+
* and cannot be transferred or cloned. Another worker prepares its own
|
|
22
|
+
* snapshot from the plain complex.
|
|
23
|
+
* - `dispose()` is idempotent; `persistence` on a disposed handle throws an
|
|
24
|
+
* `Error`.
|
|
25
|
+
* - `unload()` disposes every outstanding handle, and a later `load()` never
|
|
26
|
+
* revives one. So does a trap of the module (a call that runs out of
|
|
27
|
+
* memory), which replaces its instance. Undisposed handles stay allocated until `unload()`, so dispose
|
|
28
|
+
* each one explicitly.
|
|
29
|
+
* - Native allocations are freed on disposal, but the wasm linear memory
|
|
30
|
+
* does not shrink: its high-water mark stays until the module is unloaded
|
|
31
|
+
* and collected.
|
|
32
|
+
*
|
|
33
|
+
* The ordinary `persistence(complex)` stays stateless; nothing here caches a
|
|
34
|
+
* caller's object or a result.
|
|
35
|
+
*/
|
|
36
|
+
export function prepareComplex(complex) {
|
|
37
|
+
module();
|
|
38
|
+
const c = complexArgs(complex, 'complex');
|
|
39
|
+
const { top, scale } = c;
|
|
40
|
+
// The native object stays in this closure: no pointer is exposed that could
|
|
41
|
+
// be forged or used after its module is unloaded.
|
|
42
|
+
let raw = call('prepareComplex', (m) => new m.PreparedComplex(c.vertices, c.offsets, c.filtrations));
|
|
43
|
+
let unregister;
|
|
44
|
+
// After a trap the instance may be mid-operation (wasm-bindgen's borrow of
|
|
45
|
+
// this handle never released): the handle is abandoned with the instance
|
|
46
|
+
// it belongs to, never freed in it. `__destroy_into_raw()` (wasm-bindgen's
|
|
47
|
+
// generated class, JavaScript only) zeroes the object's pointer and
|
|
48
|
+
// unregisters its finalizer, which would otherwise call into the trapped
|
|
49
|
+
// instance on a later garbage collection.
|
|
50
|
+
const release = (trapped) => {
|
|
51
|
+
if (raw === null)
|
|
52
|
+
return;
|
|
53
|
+
const owned = raw;
|
|
54
|
+
raw = null;
|
|
55
|
+
unregister?.();
|
|
56
|
+
unregister = undefined;
|
|
57
|
+
if (trapped)
|
|
58
|
+
owned.__destroy_into_raw();
|
|
59
|
+
else
|
|
60
|
+
owned.delete();
|
|
61
|
+
};
|
|
62
|
+
const dispose = () => release(false);
|
|
63
|
+
unregister = onUnload(release);
|
|
64
|
+
return Object.freeze({
|
|
65
|
+
size: c.filtrations.length,
|
|
66
|
+
scale,
|
|
67
|
+
get disposed() {
|
|
68
|
+
return raw === null;
|
|
69
|
+
},
|
|
70
|
+
persistence(opts) {
|
|
71
|
+
if (raw === null)
|
|
72
|
+
throw new Error('prepared complex has been disposed');
|
|
73
|
+
const o = options(opts, 'PreparedComplex.persistence', PERSISTENCE_KEYS);
|
|
74
|
+
const coeff = checkCoeff(o.coeff);
|
|
75
|
+
const minPersistence = checkMinPersistence(o.minPersistence);
|
|
76
|
+
return call('prepareComplex', () => diagramOf(raw.persistence(coeff), top, scale, coeff, minPersistence));
|
|
77
|
+
},
|
|
78
|
+
dispose
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=prepared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepared.js","sourceRoot":"","sources":["../src/prepared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,cAAc,IAAI,mBAAmB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAmC5C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,cAAc,CAAC,OAAoB;IACjD,MAAM,EAAE,CAAC;IACT,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACzB,4EAA4E;IAC5E,kDAAkD;IAClD,IAAI,GAAG,GAAG,IAAI,CAAC,gBAAgB,EAAE,C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AAE,GAAG,EAAE,CAAC,SAAS,CAAC,GAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;QAC7G,CAAC;QACD,OAAO;KACR,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { PointCloud } from './check.js';
|
|
2
|
+
import type { DistanceMatrix } from './types.js';
|
|
3
|
+
import type { Bifiltration, Firep, Presentation } from './two_parameter.js';
|
|
4
|
+
/**
|
|
5
|
+
* One RIVET input data file as plain data. The kind of file decides which
|
|
6
|
+
* fields are present: `points` a cloud, `points_fn` values and a cloud,
|
|
7
|
+
* `metric` a distance matrix, `metric_fn` values and a distance matrix,
|
|
8
|
+
* `bifiltration` a bifiltration, `firep` a chain complex.
|
|
9
|
+
*/
|
|
10
|
+
export interface RivetInput {
|
|
11
|
+
/** The kind of data, from `--datatype`; `points` when the flag is absent. */
|
|
12
|
+
datatype: 'points' | 'points_fn' | 'metric' | 'metric_fn' | 'bifiltration' | 'firep';
|
|
13
|
+
/** Every flag of the file: `--name value` as `name` -> value, a flag with no value as `true`. */
|
|
14
|
+
flags: Record<string, string | true>;
|
|
15
|
+
/** `points` and `points_fn`: the cloud. */
|
|
16
|
+
points?: PointCloud;
|
|
17
|
+
/** `metric` and `metric_fn`: the full `n x n` matrix, row-major (the upper-triangular form expanded). */
|
|
18
|
+
distances?: DistanceMatrix;
|
|
19
|
+
/** `points_fn` and `metric_fn`: the function values, one per point. */
|
|
20
|
+
values?: Float64Array;
|
|
21
|
+
/** `--maxdist` as a number; `Infinity` when the flag is absent. */
|
|
22
|
+
maxDistance: number;
|
|
23
|
+
/**
|
|
24
|
+
* `bifiltration`: the simplices as cells, in the file's order, every
|
|
25
|
+
* facet a cell of the file; `gradeOffsets` when any simplex has several
|
|
26
|
+
* grades. With `--xreverse` (`--yreverse`) the x (y) coordinate of every
|
|
27
|
+
* grade is negated, so that the result is an increasing bifiltration.
|
|
28
|
+
*/
|
|
29
|
+
bifiltration?: Bifiltration;
|
|
30
|
+
/** `firep`: the chain complex `C2 -> C1 -> C0` over Z/2, both maps as CSR arrays. */
|
|
31
|
+
firep?: Firep;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reads the text of a RIVET input data file into plain data, as
|
|
35
|
+
* {@link RivetInput}. The six kinds of file of RIVET 1.1 are read:
|
|
36
|
+
* `points`, `points_fn`, `metric`, `metric_fn`, `bifiltration`
|
|
37
|
+
* (multicritical allowed) and `firep`; `--datatype` selects the kind and
|
|
38
|
+
* `points` when the flag is absent. A distance matrix is read in either of
|
|
39
|
+
* the two forms the documentation gives, and the upper-triangular one is
|
|
40
|
+
* expanded to the full symmetric matrix. A bifiltration keeps the file's
|
|
41
|
+
* simplex order, and every facet must itself be listed as a simplex, on
|
|
42
|
+
* any line of the file; with `--xreverse` (`--yreverse`) the x (y)
|
|
43
|
+
* coordinate of every grade is negated, so that the result is an
|
|
44
|
+
* increasing bifiltration. The grades of a firep are as the file gives
|
|
45
|
+
* them; a firep's reverse flags are kept in `flags` only. The Rust crate
|
|
46
|
+
* reads the file (`parse_rivet_input`), so it needs the module.
|
|
47
|
+
*/
|
|
48
|
+
export declare function parseRivetInput(text: string): RivetInput;
|
|
49
|
+
/** Options of {@link rivetPresentation}. */
|
|
50
|
+
export interface RivetPresentationOptions {
|
|
51
|
+
/** Homology degree, a non-negative integer (RIVET's `--homology`). Default 0, as in RIVET. */
|
|
52
|
+
degree?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The minimal presentation of the module the RIVET input file `text`
|
|
56
|
+
* describes, in degree `degree`, built as RIVET 1.1 builds it (by the Rust
|
|
57
|
+
* crate's `rivet_presentation`):
|
|
58
|
+
*
|
|
59
|
+
* - A point cloud or a metric space with function values (`points_fn`,
|
|
60
|
+
* `metric_fn`) gives the function-Rips bifiltration
|
|
61
|
+
* (`functionRipsPresentation`); `--xreverse` filters by decreasing value
|
|
62
|
+
* (the values negated), and `--bifil degree` gives the degree-Rips
|
|
63
|
+
* bifiltration instead.
|
|
64
|
+
* - Without function values (`points`, `metric`) it is the degree-Rips
|
|
65
|
+
* bifiltration (`degreeRipsPresentation`, whose first coordinate is minus
|
|
66
|
+
* the degree); `--bifil function` gives the function-Rips bifiltration of
|
|
67
|
+
* `balldensity[]`, by decreasing value.
|
|
68
|
+
* - `--function balldensity[r]`, `gaussian[σ]` or `eccentricity[p]`
|
|
69
|
+
* computes the function on the points or the metric space (values in the
|
|
70
|
+
* file are not used) and gives its function-Rips bifiltration, whatever
|
|
71
|
+
* `--bifil` says: the ball density `C·#{y : d(x, y) <= r}`, the Gaussian
|
|
72
|
+
* density `C·Σ_y exp(−d(x, y)²/(2σ²))` (`C` makes the values sum to 1) and
|
|
73
|
+
* the eccentricity `(Σ_y d(x, y)^p / n)^(1/p)`. Empty brackets take
|
|
74
|
+
* RIVET's defaults: `r` and `σ` RIVET 1.1's 20th percentile of the
|
|
75
|
+
* distances (entry `⌊M/5⌋ − 1` of the distances of all `M` pairs in
|
|
76
|
+
* increasing order, coincident points' zeros counted; 0 when `M < 5`, and
|
|
77
|
+
* then a point's density counts the points that coincide with it), and
|
|
78
|
+
* `p = 1`. `p` may be any real number at least 1, as RIVET's documentation
|
|
79
|
+
* defines it (RIVET 1.1 truncates it to an integer). The filtration is by
|
|
80
|
+
* decreasing value, with or without `--xreverse`, as RIVET's documentation
|
|
81
|
+
* sets it.
|
|
82
|
+
* - A bifiltration gives `bifiltrationPresentation`, a FIRep
|
|
83
|
+
* `firepPresentation`.
|
|
84
|
+
*
|
|
85
|
+
* Rips bifiltrations go up to `--maxdist`. The file is refused as
|
|
86
|
+
* {@link parseRivetInput} refuses it; `--function user` on a file without
|
|
87
|
+
* function values, a `--function` of another form, `--yreverse` on a Rips
|
|
88
|
+
* bifiltration, a negative `--maxdist` on one and a negative distance are
|
|
89
|
+
* refused with a `RangeError`, as is what the builder refuses. To read the
|
|
90
|
+
* file's data, use {@link parseRivetInput}.
|
|
91
|
+
*/
|
|
92
|
+
export declare function rivetPresentation(text: string, opts?: RivetPresentationOptions): Presentation;
|
|
93
|
+
//# sourceMappingURL=rivet_input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rivet_input.d.ts","sourceRoot":"","sources":["../src/rivet_input.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAQ,UAAU,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,6EAA6E;IAC7E,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,cAAc,GAAG,OAAO,CAAC;IACrF,iGAAiG;IACjG,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IACrC,2CAA2C;IAC3C,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,yGAAyG;IACzG,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,uEAAuE;IACvE,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,qFAAqF;IACrF,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAgED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAIxD;AAED,4CAA4C;AAC5C,MAAM,WAAW,wBAAwB;IACvC,8FAA8F;IAC9F,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,wBAAwB,GAAG,YAAY,CAM7F"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RIVET input data files, the input format RIVET 1.1's documentation
|
|
3
|
+
* specifies, read into plain data, and the module a file describes. The
|
|
4
|
+
* Rust crate reads them (`parse_rivet_input` and `rivet_presentation` in
|
|
5
|
+
* `rust/tda-core/src/two_parameter/rivet.rs`); these functions check their
|
|
6
|
+
* arguments and shape the result. A file holds one of six kinds of data (a
|
|
7
|
+
* point cloud, a point cloud with a function, a metric space, a metric
|
|
8
|
+
* space with a function, a bifiltration or a short chain complex), with
|
|
9
|
+
* the flags that tell RIVET how to build a bifiltration from it.
|
|
10
|
+
*
|
|
11
|
+
* A line that starts with `#` is a comment and a blank line is ignored.
|
|
12
|
+
* A line that starts with `--` is a flag, `--name value`, the value the
|
|
13
|
+
* rest of the line (`true` when the flag has none); a repeated flag keeps
|
|
14
|
+
* its last line. Where the documentation allows commas, numbers are
|
|
15
|
+
* separated by spaces or commas; the bifiltration and firep formats
|
|
16
|
+
* separate their numbers by spaces only. Whitespace is JavaScript's (`\s`).
|
|
17
|
+
*
|
|
18
|
+
* A file that does not follow the documentation is refused with a
|
|
19
|
+
* `TypeError` (a value of the wrong kind, such as a token that is not a
|
|
20
|
+
* number) or a `RangeError` (a wrong count, an index out of range, an
|
|
21
|
+
* unknown `--datatype`), and every message names the 1-based line the
|
|
22
|
+
* error is on.
|
|
23
|
+
*/
|
|
24
|
+
import { int, kind, options } from './check.js';
|
|
25
|
+
import { call, module } from './load.js';
|
|
26
|
+
import { presentationOf } from './two_parameter.js';
|
|
27
|
+
/** The file's text as the UTF-8 bytes the module reads (a lone surrogate as U+FFFD). */
|
|
28
|
+
const encoder = new TextEncoder();
|
|
29
|
+
function textOf(v) {
|
|
30
|
+
if (typeof v !== 'string')
|
|
31
|
+
throw new TypeError(`text must be a string, got ${kind(v)}`);
|
|
32
|
+
return encoder.encode(v);
|
|
33
|
+
}
|
|
34
|
+
/** The module's result as a {@link RivetInput}, its fields in the order of the kind. */
|
|
35
|
+
function inputOf(raw) {
|
|
36
|
+
const r = { datatype: raw.datatype, flags: Object.fromEntries(raw.flags) };
|
|
37
|
+
switch (raw.datatype) {
|
|
38
|
+
case 'points':
|
|
39
|
+
case 'points_fn':
|
|
40
|
+
r.points = { coords: raw.coords, d: raw.d };
|
|
41
|
+
break;
|
|
42
|
+
case 'metric':
|
|
43
|
+
case 'metric_fn':
|
|
44
|
+
r.distances = { distances: raw.distances };
|
|
45
|
+
break;
|
|
46
|
+
case 'bifiltration': {
|
|
47
|
+
const b = { dims: raw.dims, grades: raw.grades, offsets: raw.offsets, facets: raw.facets };
|
|
48
|
+
if (raw.gradeOffsets !== undefined)
|
|
49
|
+
b.gradeOffsets = raw.gradeOffsets;
|
|
50
|
+
r.bifiltration = b;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'firep':
|
|
54
|
+
r.firep = {
|
|
55
|
+
high: { grades: raw.highGrades, offsets: raw.highOffsets, rows: raw.highRows },
|
|
56
|
+
low: { grades: raw.lowGrades, offsets: raw.lowOffsets, rows: raw.lowRows },
|
|
57
|
+
lowRank: raw.lowRank
|
|
58
|
+
};
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (raw.values !== undefined)
|
|
62
|
+
r.values = raw.values;
|
|
63
|
+
r.maxDistance = raw.maxDistance;
|
|
64
|
+
return r;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Reads the text of a RIVET input data file into plain data, as
|
|
68
|
+
* {@link RivetInput}. The six kinds of file of RIVET 1.1 are read:
|
|
69
|
+
* `points`, `points_fn`, `metric`, `metric_fn`, `bifiltration`
|
|
70
|
+
* (multicritical allowed) and `firep`; `--datatype` selects the kind and
|
|
71
|
+
* `points` when the flag is absent. A distance matrix is read in either of
|
|
72
|
+
* the two forms the documentation gives, and the upper-triangular one is
|
|
73
|
+
* expanded to the full symmetric matrix. A bifiltration keeps the file's
|
|
74
|
+
* simplex order, and every facet must itself be listed as a simplex, on
|
|
75
|
+
* any line of the file; with `--xreverse` (`--yreverse`) the x (y)
|
|
76
|
+
* coordinate of every grade is negated, so that the result is an
|
|
77
|
+
* increasing bifiltration. The grades of a firep are as the file gives
|
|
78
|
+
* them; a firep's reverse flags are kept in `flags` only. The Rust crate
|
|
79
|
+
* reads the file (`parse_rivet_input`), so it needs the module.
|
|
80
|
+
*/
|
|
81
|
+
export function parseRivetInput(text) {
|
|
82
|
+
module();
|
|
83
|
+
const bytes = textOf(text);
|
|
84
|
+
return call('parseRivetInput', (m) => inputOf(m.rivetInputFlat(bytes)));
|
|
85
|
+
}
|
|
86
|
+
const RIVET_PRESENTATION_KEYS = { degree: true };
|
|
87
|
+
/**
|
|
88
|
+
* The minimal presentation of the module the RIVET input file `text`
|
|
89
|
+
* describes, in degree `degree`, built as RIVET 1.1 builds it (by the Rust
|
|
90
|
+
* crate's `rivet_presentation`):
|
|
91
|
+
*
|
|
92
|
+
* - A point cloud or a metric space with function values (`points_fn`,
|
|
93
|
+
* `metric_fn`) gives the function-Rips bifiltration
|
|
94
|
+
* (`functionRipsPresentation`); `--xreverse` filters by decreasing value
|
|
95
|
+
* (the values negated), and `--bifil degree` gives the degree-Rips
|
|
96
|
+
* bifiltration instead.
|
|
97
|
+
* - Without function values (`points`, `metric`) it is the degree-Rips
|
|
98
|
+
* bifiltration (`degreeRipsPresentation`, whose first coordinate is minus
|
|
99
|
+
* the degree); `--bifil function` gives the function-Rips bifiltration of
|
|
100
|
+
* `balldensity[]`, by decreasing value.
|
|
101
|
+
* - `--function balldensity[r]`, `gaussian[σ]` or `eccentricity[p]`
|
|
102
|
+
* computes the function on the points or the metric space (values in the
|
|
103
|
+
* file are not used) and gives its function-Rips bifiltration, whatever
|
|
104
|
+
* `--bifil` says: the ball density `C·#{y : d(x, y) <= r}`, the Gaussian
|
|
105
|
+
* density `C·Σ_y exp(−d(x, y)²/(2σ²))` (`C` makes the values sum to 1) and
|
|
106
|
+
* the eccentricity `(Σ_y d(x, y)^p / n)^(1/p)`. Empty brackets take
|
|
107
|
+
* RIVET's defaults: `r` and `σ` RIVET 1.1's 20th percentile of the
|
|
108
|
+
* distances (entry `⌊M/5⌋ − 1` of the distances of all `M` pairs in
|
|
109
|
+
* increasing order, coincident points' zeros counted; 0 when `M < 5`, and
|
|
110
|
+
* then a point's density counts the points that coincide with it), and
|
|
111
|
+
* `p = 1`. `p` may be any real number at least 1, as RIVET's documentation
|
|
112
|
+
* defines it (RIVET 1.1 truncates it to an integer). The filtration is by
|
|
113
|
+
* decreasing value, with or without `--xreverse`, as RIVET's documentation
|
|
114
|
+
* sets it.
|
|
115
|
+
* - A bifiltration gives `bifiltrationPresentation`, a FIRep
|
|
116
|
+
* `firepPresentation`.
|
|
117
|
+
*
|
|
118
|
+
* Rips bifiltrations go up to `--maxdist`. The file is refused as
|
|
119
|
+
* {@link parseRivetInput} refuses it; `--function user` on a file without
|
|
120
|
+
* function values, a `--function` of another form, `--yreverse` on a Rips
|
|
121
|
+
* bifiltration, a negative `--maxdist` on one and a negative distance are
|
|
122
|
+
* refused with a `RangeError`, as is what the builder refuses. To read the
|
|
123
|
+
* file's data, use {@link parseRivetInput}.
|
|
124
|
+
*/
|
|
125
|
+
export function rivetPresentation(text, opts) {
|
|
126
|
+
module();
|
|
127
|
+
const bytes = textOf(text);
|
|
128
|
+
const o = options(opts, 'rivetPresentation', RIVET_PRESENTATION_KEYS);
|
|
129
|
+
const degree = o.degree === undefined ? 0 : int(o.degree, 'degree', 0, 254);
|
|
130
|
+
return call('rivetPresentation', (m) => presentationOf(m.rivetPresentationFlat(bytes, degree), degree));
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=rivet_input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rivet_input.js","sourceRoot":"","sources":["../src/rivet_input.ts"],"names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AM,EAAE,CAAC;IACT,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,MAAM,CAAC,GAAG,OAAO,CAA2B,IAAI,EAAE,mBAAmB,EAAE,uBAAuB,CAAC,CAAC;IAChG,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;IAC5E,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAC1G,CAAC"}
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning a `load()` source into a compiled `WebAssembly.Module`, for the
|
|
3
|
+
* package root and for `./ladder` (internal).
|
|
4
|
+
*
|
|
5
|
+
* Nothing here writes to `globalThis`. In Node the default source is read
|
|
6
|
+
* with `fs`, and bytes or a compiled module are compiled or used without
|
|
7
|
+
* touching `Request`, `Response` or `fetch` (Node defines those lazily; the
|
|
8
|
+
* first read of one installs undici's global dispatcher on `globalThis`).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Where `load` reads a module from: a URL (or its string; in Node the
|
|
12
|
+
* string must be an absolute URL, such as a `file:` URL) or request, a fetch
|
|
13
|
+
* `Response` (or a promise of one), the bytes (an `ArrayBuffer`, or any
|
|
14
|
+
* view of one: a typed array, a Node `Buffer` or a `DataView`), or a
|
|
15
|
+
* compiled `WebAssembly.Module`. A WebAssembly module other than the
|
|
16
|
+
* package's is refused with a `TypeError`. Written without DOM-only names so that a Node
|
|
17
|
+
* project compiles without the DOM lib: the compiled module is typed
|
|
18
|
+
* `WebAssembly.Module` where the environment's types declare it, otherwise
|
|
19
|
+
* any object.
|
|
20
|
+
*/
|
|
21
|
+
export type LoadSource = string | Request | URL | Response | ArrayBuffer | ArrayBufferView | (typeof globalThis extends {
|
|
22
|
+
WebAssembly: {
|
|
23
|
+
Module: abstract new (...args: never[]) => infer M;
|
|
24
|
+
};
|
|
25
|
+
} ? M & object : object) | Promise<string | Request | URL | Response | ArrayBuffer | ArrayBufferView | (typeof globalThis extends {
|
|
26
|
+
WebAssembly: {
|
|
27
|
+
Module: abstract new (...args: never[]) => infer M;
|
|
28
|
+
};
|
|
29
|
+
} ? M & object : object)>;
|
|
30
|
+
/**
|
|
31
|
+
* The compiled module from `source`; without one, from `fallback()` (the
|
|
32
|
+
* binary next to the package's code: read from the file in Node, fetched in
|
|
33
|
+
* a browser). Any `ArrayBufferView` is read as the bytes it views, a
|
|
34
|
+
* `DataView` included. `expected` names an export only the right module
|
|
35
|
+
* has, and `file` the file it comes from, for the refusal of another
|
|
36
|
+
* WebAssembly module.
|
|
37
|
+
*/
|
|
38
|
+
export declare function compileSource(source: LoadSource | undefined, fallback: () => URL, expected: {
|
|
39
|
+
exports: readonly string[];
|
|
40
|
+
file: string;
|
|
41
|
+
pkg: string;
|
|
42
|
+
}): Promise<Exclude<Awaited<LoadSource>, string | Request | URL | Response | ArrayBuffer | ArrayBufferView>>;
|
|
43
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,OAAO,GACP,GAAG,GACH,QAAQ,GACR,WAAW,GACX,eAAe,GACf,CAAC,OAAO,UAAU,SAAS;IAAE,WAAW,EAAE;QAAE,MAAM,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,MAAM,CAAC,CAAA;KAAE,CAAA;CAAE,GAAG,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,GACzH,OAAO,CACH,MAAM,GACN,OAAO,GACP,GAAG,GACH,QAAQ,GACR,WAAW,GACX,eAAe,GACf,CAAC,OAAO,UAAU,SAAS;IAAE,WAAW,EAAE;QAAE,MAAM,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,MAAM,CAAC,CAAA;KAAE,CAAA;CAAE,GAAG,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,CAC5H,CAAC;AA6BN;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,UAAU,GAAG,SAAS,EAC9B,QAAQ,EAAE,MAAM,GAAG,EACnB,QAAQ,EAAE;IAAE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAClE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,GAAG,GAAG,QAAQ,GAAG,WAAW,GAAG,eAAe,CAAC,CAAC,CAO1G"}
|
package/dist/source.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning a `load()` source into a compiled `WebAssembly.Module`, for the
|
|
3
|
+
* package root and for `./ladder` (internal).
|
|
4
|
+
*
|
|
5
|
+
* Nothing here writes to `globalThis`. In Node the default source is read
|
|
6
|
+
* with `fs`, and bytes or a compiled module are compiled or used without
|
|
7
|
+
* touching `Request`, `Response` or `fetch` (Node defines those lazily; the
|
|
8
|
+
* first read of one installs undici's global dispatcher on `globalThis`).
|
|
9
|
+
*/
|
|
10
|
+
const isNode = typeof process !== 'undefined' && typeof process.versions?.node === 'string';
|
|
11
|
+
/**
|
|
12
|
+
* Node's `fs/promises`, reached so that no bundler sees a dependency on it:
|
|
13
|
+
* a literal `import('node:fs/promises')` stops esbuild ("Could not resolve"),
|
|
14
|
+
* fails webpack 5 (UnhandledSchemeError) and makes Vite warn that the module
|
|
15
|
+
* was externalized, in every browser bundle of the package, although this
|
|
16
|
+
* branch only runs in Node. `process.getBuiltinModule` (Node 22.3 and later)
|
|
17
|
+
* needs no import; the fallback (Node 22.0 to 22.2) builds the specifier at
|
|
18
|
+
* run time, which bundlers leave alone.
|
|
19
|
+
*/
|
|
20
|
+
async function nodeFs() {
|
|
21
|
+
const get = process.getBuiltinModule;
|
|
22
|
+
if (typeof get === 'function')
|
|
23
|
+
return get.call(process, 'node:fs/promises');
|
|
24
|
+
return import(/* @vite-ignore */ /* webpackIgnore: true */ ['node', 'fs/promises'].join(':'));
|
|
25
|
+
}
|
|
26
|
+
/** Whether `s` parses as an absolute URL (a scheme and the rest). */
|
|
27
|
+
function isAbsoluteUrl(s) {
|
|
28
|
+
try {
|
|
29
|
+
new URL(s);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The compiled module from `source`; without one, from `fallback()` (the
|
|
38
|
+
* binary next to the package's code: read from the file in Node, fetched in
|
|
39
|
+
* a browser). Any `ArrayBufferView` is read as the bytes it views, a
|
|
40
|
+
* `DataView` included. `expected` names an export only the right module
|
|
41
|
+
* has, and `file` the file it comes from, for the refusal of another
|
|
42
|
+
* WebAssembly module.
|
|
43
|
+
*/
|
|
44
|
+
export async function compileSource(source, fallback, expected) {
|
|
45
|
+
const compiled = await compile(source, fallback);
|
|
46
|
+
const names = new Set(WebAssembly.Module.exports(compiled).map((e) => e.name));
|
|
47
|
+
if (!expected.exports.every((name) => names.has(name))) {
|
|
48
|
+
throw new TypeError(`source is a WebAssembly module, but not ${expected.pkg}'s ${expected.file}`);
|
|
49
|
+
}
|
|
50
|
+
return compiled;
|
|
51
|
+
}
|
|
52
|
+
/** The built-in kind of a value (`'ArrayBuffer'`, `'URL'`, …), the same for one made in another realm (an iframe, a `vm` context). */
|
|
53
|
+
function tag(v) {
|
|
54
|
+
return Object.prototype.toString.call(v).slice(8, -1);
|
|
55
|
+
}
|
|
56
|
+
async function compile(source, fallback) {
|
|
57
|
+
let s = await source;
|
|
58
|
+
if (s === undefined)
|
|
59
|
+
s = fallback();
|
|
60
|
+
// Kinds are told by their tags, not instanceof, so that a source made in
|
|
61
|
+
// another realm is read as the same kind of source.
|
|
62
|
+
const kind = tag(s);
|
|
63
|
+
if (kind === 'WebAssembly.Module')
|
|
64
|
+
return s;
|
|
65
|
+
if (kind === 'ArrayBuffer')
|
|
66
|
+
return WebAssembly.compile(s);
|
|
67
|
+
if (ArrayBuffer.isView(s)) {
|
|
68
|
+
// Every view as its bytes: WebAssembly.compile itself takes no DataView.
|
|
69
|
+
return WebAssembly.compile(new Uint8Array(s.buffer, s.byteOffset, s.byteLength));
|
|
70
|
+
}
|
|
71
|
+
if (isNode && typeof s === 'string' && !isAbsoluteUrl(s)) {
|
|
72
|
+
throw new TypeError(`source "${s}" is not a URL: in Node, pass a URL (such as new URL('./tda.wasm', import.meta.url) or a file: URL) ` +
|
|
73
|
+
'or the bytes (for example from fs.readFile)');
|
|
74
|
+
}
|
|
75
|
+
// A URL of another realm, as a URL of this one.
|
|
76
|
+
if (kind === 'URL')
|
|
77
|
+
s = new URL(String(s));
|
|
78
|
+
if (isNode && (s instanceof URL || (typeof s === 'string' && s.startsWith('file:')))) {
|
|
79
|
+
const url = s instanceof URL ? s : new URL(s);
|
|
80
|
+
if (url.protocol === 'file:') {
|
|
81
|
+
const { readFile } = await nodeFs();
|
|
82
|
+
return WebAssembly.compile((await readFile(url)));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (typeof s === 'string' || s instanceof URL || tag(s) === 'Request') {
|
|
86
|
+
s = await fetch(s);
|
|
87
|
+
}
|
|
88
|
+
if (tag(s) === 'Response') {
|
|
89
|
+
const r = s;
|
|
90
|
+
if (!r.ok)
|
|
91
|
+
throw new Error(`fetching the WebAssembly module failed: ${r.status} ${r.statusText} (${r.url})`);
|
|
92
|
+
if (typeof WebAssembly.compileStreaming === 'function' && r.headers.get('Content-Type') === 'application/wasm') {
|
|
93
|
+
return WebAssembly.compileStreaming(r);
|
|
94
|
+
}
|
|
95
|
+
return WebAssembly.compile(await r.arrayBuffer());
|
|
96
|
+
}
|
|
97
|
+
throw new TypeError('source must be a URL, a Request, a Response, the bytes or a WebAssembly.Module');
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA+BH,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,KAAK,QAAQ,CAAC;AAE5F;;;;;;;;GAQG;AACH,KAAK,UAAU,MAAM;IACnB,MAAM,GAAG,GAAI,OAA0D,CAAC,gBAAgB,CAAC;IACzF,IAAI,OAAO,GAAG,KAAK,UAAU;QAAE,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAsC,CAAC;IACjH,OAAO,MAAM,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAChG,CAAC;AAED,qEAAqE;AACrE,SAAS,aAAa,CAAC,CAAS;IAC9B,IAAI,CAAC;QACH,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAA8B,EAC9B,QAAmB,EACnB,QAAmE;IAEnE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,QAAQ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