@topolab/tda 0.0.0-stage → 0.3.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 (90) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/CITATION.cff +72 -0
  3. package/LICENSE +21 -0
  4. package/README.md +100 -2
  5. package/SECURITY.md +34 -0
  6. package/THIRD_PARTY_LICENSES.md +696 -0
  7. package/dist/build_info.json +12 -0
  8. package/dist/check.d.ts +118 -0
  9. package/dist/check.d.ts.map +1 -0
  10. package/dist/check.js +298 -0
  11. package/dist/check.js.map +1 -0
  12. package/dist/complex.d.ts +543 -0
  13. package/dist/complex.d.ts.map +1 -0
  14. package/dist/complex.js +712 -0
  15. package/dist/complex.js.map +1 -0
  16. package/dist/diagram.d.ts +116 -0
  17. package/dist/diagram.d.ts.map +1 -0
  18. package/dist/diagram.js +238 -0
  19. package/dist/diagram.js.map +1 -0
  20. package/dist/diagram_of.d.ts +17 -0
  21. package/dist/diagram_of.d.ts.map +1 -0
  22. package/dist/diagram_of.js +40 -0
  23. package/dist/diagram_of.js.map +1 -0
  24. package/dist/experimental.d.ts +14 -0
  25. package/dist/experimental.d.ts.map +1 -0
  26. package/dist/experimental.js +13 -0
  27. package/dist/experimental.js.map +1 -0
  28. package/dist/flat.d.ts +64 -0
  29. package/dist/flat.d.ts.map +1 -0
  30. package/dist/flat.js +158 -0
  31. package/dist/flat.js.map +1 -0
  32. package/dist/index.d.ts +38 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +29 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/ladder/tda_ladder.d.ts +223 -0
  37. package/dist/ladder/tda_ladder.js +1360 -0
  38. package/dist/ladder/tda_ladder_bg.wasm +0 -0
  39. package/dist/ladder/tda_ladder_bg.wasm.d.ts +43 -0
  40. package/dist/ladder.d.ts +306 -0
  41. package/dist/ladder.d.ts.map +1 -0
  42. package/dist/ladder.js +607 -0
  43. package/dist/ladder.js.map +1 -0
  44. package/dist/load.d.ts +53 -0
  45. package/dist/load.d.ts.map +1 -0
  46. package/dist/load.js +173 -0
  47. package/dist/load.js.map +1 -0
  48. package/dist/memory.d.ts +58 -0
  49. package/dist/memory.d.ts.map +1 -0
  50. package/dist/memory.js +2 -0
  51. package/dist/memory.js.map +1 -0
  52. package/dist/persistence.d.ts +349 -0
  53. package/dist/persistence.d.ts.map +1 -0
  54. package/dist/persistence.js +478 -0
  55. package/dist/persistence.js.map +1 -0
  56. package/dist/pkg/tda_wasm.d.ts +13 -0
  57. package/dist/pkg/tda_wasm.js +1900 -0
  58. package/dist/prepared.d.ts +62 -0
  59. package/dist/prepared.d.ts.map +1 -0
  60. package/dist/prepared.js +81 -0
  61. package/dist/prepared.js.map +1 -0
  62. package/dist/source.d.ts +43 -0
  63. package/dist/source.d.ts.map +1 -0
  64. package/dist/source.js +99 -0
  65. package/dist/source.js.map +1 -0
  66. package/dist/tda.wasm +0 -0
  67. package/dist/types.d.ts +146 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/types.js +2 -0
  70. package/dist/types.js.map +1 -0
  71. package/dist/vineyard.d.ts +278 -0
  72. package/dist/vineyard.d.ts.map +1 -0
  73. package/dist/vineyard.js +236 -0
  74. package/dist/vineyard.js.map +1 -0
  75. package/package.json +77 -4
  76. package/src/check.ts +338 -0
  77. package/src/complex.ts +1179 -0
  78. package/src/diagram.ts +299 -0
  79. package/src/diagram_of.ts +40 -0
  80. package/src/experimental.ts +13 -0
  81. package/src/flat.ts +204 -0
  82. package/src/index.ts +155 -0
  83. package/src/ladder.ts +903 -0
  84. package/src/load.ts +201 -0
  85. package/src/memory.ts +58 -0
  86. package/src/persistence.ts +752 -0
  87. package/src/prepared.ts +111 -0
  88. package/src/source.ts +132 -0
  89. package/src/types.ts +163 -0
  90. 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"}
@@ -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,CAAC,CAAC,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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,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,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;I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C;YAC/G,OAAO,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,IAAI,SAAS,CAAC,gFAAgF,CAAC,CAAC;AACxG,CAAC"}
package/dist/tda.wasm ADDED
Binary file
@@ -0,0 +1,146 @@
1
+ /**
2
+ * The plain data the package takes and returns. Every result is a plain
3
+ * object of typed arrays, numbers, strings, booleans and arrays of them, so
4
+ * it survives `postMessage` and `structuredClone` whole; no result has
5
+ * methods.
6
+ */
7
+ import type { PointCloud } from './check.js';
8
+ export type { PointCloud };
9
+ /**
10
+ * The quantity a filtration's values measure, carried by every complex and
11
+ * diagram.
12
+ *
13
+ * - `'edgeLength'`: an edge length, twice a ball radius (Rips, ellipsoid
14
+ * Rips; cutoff `maxEdgeLength`);
15
+ * - `'radius'`: the radius of a ball (Čech, Delaunay–Čech, ellipsoid Čech;
16
+ * cutoff `maxRadius`);
17
+ * - `'squaredRadius'`: a squared radius, negative at weighted vertices
18
+ * (alpha, coupled alpha, k-fold cover; cutoff `maxSquaredRadius`);
19
+ * - `'squaredRelaxation'`: the relaxation of the witness complex, a squared
20
+ * length (cutoff `maxSquaredRelaxation`);
21
+ * - `'epsilon'`: the wing length ε (wing complex; cutoff `maxEpsilon`);
22
+ * - `'growthRadius'`: the ℓ∞ radius `j · stepSize` within which the boxes of
23
+ * the box filtration grow (cutoffs `stepSize`, `maxSteps`);
24
+ * - `'value'`: the caller's own values (cubical complexes, a complex the
25
+ * caller builds, zigzag operations).
26
+ */
27
+ export type Scale = 'edgeLength' | 'radius' | 'squaredRadius' | 'squaredRelaxation' | 'epsilon' | 'growthRadius' | 'value';
28
+ /** A dense `n × n` distance matrix, row-major; only the strict lower triangle (`distances[i·n + j]`, `i > j`) is read, and no entry may be NaN or negative. */
29
+ export interface DistanceMatrix {
30
+ /** The `n²` distances, row-major. */
31
+ distances: Float64Array;
32
+ }
33
+ /**
34
+ * An image or a volume: `values` row-major in NumPy's order, the last axis
35
+ * fastest. A `height × width` image is `shape: [height, width]`, its pixel
36
+ * `(row, column)` at `values[row · width + column]`, as in `ImageData`.
37
+ */
38
+ export interface Grid {
39
+ /** The values, row-major (length the product of `shape`). */
40
+ values: Float64Array;
41
+ /** The extent of each axis, slowest first. */
42
+ shape: number[];
43
+ }
44
+ /**
45
+ * A filtered simplicial complex as three typed arrays (CSR): simplex `i` is
46
+ * `vertices[offsets[i] .. offsets[i + 1])`, its vertex ids in increasing
47
+ * order, entered at `filtrations[i]`.
48
+ *
49
+ * Every builder lists its simplices in one documented order: by value
50
+ * (`-0` equal to `+0`), then by dimension, then lexicographically on the
51
+ * increasing vertex lists (as Python sorts lists). Values never decrease,
52
+ * and every face comes before its cofaces. (Where the input's ties are not
53
+ * exact in double precision, the full Čech builder raises a coface to its
54
+ * faces' values; see `cechComplex`.)
55
+ *
56
+ * A function that takes simplices (`persistence`, `volumeOptimalCycles`,
57
+ * `flatten`, the ladder filtrations) accepts each simplex's vertices in any
58
+ * order and sorts them; a vertex listed twice in one simplex is refused with
59
+ * a `RangeError`.
60
+ */
61
+ export interface Complex {
62
+ /** Concatenated vertex ids of every simplex (increasing within a simplex). */
63
+ vertices: Int32Array;
64
+ /** Length `count + 1`; simplex `i` is `vertices[offsets[i] .. offsets[i + 1])`. */
65
+ offsets: Uint32Array;
66
+ /** The value at which simplex `i` enters. */
67
+ filtrations: Float64Array;
68
+ /** The quantity the values measure. */
69
+ scale: Scale;
70
+ }
71
+ /**
72
+ * What the functions that take a complex accept: a {@link Complex}, or the
73
+ * same three arrays as number arrays (converted, with integer checks), with
74
+ * or without `scale`.
75
+ */
76
+ export interface ComplexLike {
77
+ vertices: ArrayLike<number>;
78
+ offsets: ArrayLike<number>;
79
+ filtrations: ArrayLike<number>;
80
+ scale?: Scale;
81
+ }
82
+ /** One simplex as an object (what {@link materialize} builds from a {@link Complex}). */
83
+ export interface Simplex {
84
+ /** Vertex ids, increasing in what the package returns; any order in what it takes. */
85
+ vertices: number[];
86
+ /** The value at which the simplex enters. */
87
+ filtration: number;
88
+ }
89
+ /**
90
+ * Every cell of a T-construction cubical complex, in the order (value, then
91
+ * cell dimension, then bitmap position).
92
+ */
93
+ export interface CubicalComplex {
94
+ /** The grid's shape (the input's, slowest axis first). */
95
+ shape: number[];
96
+ /**
97
+ * Position of each cell in the bitmap, the grid of `2 · shape[i] + 1`
98
+ * positions along axis `i`, numbered row-major (the last axis fastest): a
99
+ * cell's coordinate is odd along the axes it spans, and the pixel at
100
+ * `(p0, p1, …)` is the cell at `(2 p0 + 1, 2 p1 + 1, …)`.
101
+ */
102
+ cells: Uint32Array;
103
+ /** The dimension of each cell (the number of its odd coordinates). */
104
+ dims: Uint8Array;
105
+ /** The value of each cell: the smallest value of the pixels containing it. */
106
+ filtrations: Float64Array;
107
+ /** Always `'value'`: the image's own values. */
108
+ scale: 'value';
109
+ }
110
+ /**
111
+ * A persistence diagram. `pairs[k]` lists the classes of Hₖ as
112
+ * `[birth, death, birth, death, …]`, essential classes with
113
+ * `death = Infinity`, one array per homology dimension from 0 to the highest
114
+ * the call computes (empty arrays included). Pairs of length zero are left
115
+ * out, and with the `minPersistence` option every finite pair with
116
+ * `death − birth <= minPersistence`.
117
+ */
118
+ export interface Diagram {
119
+ /** `pairs[k]`: the pairs of Hₖ, `[birth, death, …]`. */
120
+ pairs: Float64Array[];
121
+ /** The quantity the values measure. */
122
+ scale: Scale;
123
+ /** The coefficient field `Z/coeff` the diagram was computed over. */
124
+ coeff: number;
125
+ }
126
+ /** The result of a builder's `…Persistence` function: the diagram, and with `complex: true` the complex it was computed from. */
127
+ export interface BuilderPersistence<C extends Complex = Complex> extends Diagram {
128
+ /** The complex, as the builder returns it; present only with `complex: true`. */
129
+ complex?: C;
130
+ }
131
+ /** Options every builder's `…Persistence` function takes beside the builder's own. */
132
+ export interface BuilderPersistenceOptions {
133
+ /** The prime `p` of the coefficient field `Z/p`, from 2 to `2^31 − 1`. Default 2. */
134
+ coeff?: number;
135
+ /** Also return the complex, as the builder returns it. Default `false`. */
136
+ complex?: boolean;
137
+ /**
138
+ * Leave out the finite pairs with `death − birth <= minPersistence`
139
+ * (GUDHI's `min_persistence`); essential pairs are always kept. A finite
140
+ * number `>= 0`. Default 0: only the pairs of length zero are left out.
141
+ * `1e-12` removes the bars one ulp long that rounding leaves on symmetric
142
+ * input such as a lattice.
143
+ */
144
+ minPersistence?: number;
145
+ }
146
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,KAAK,GACb,YAAY,GACZ,QAAQ,GACR,eAAe,GACf,mBAAmB,GACnB,SAAS,GACT,cAAc,GACd,OAAO,CAAC;AAEZ,+JAA+J;AAC/J,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,SAAS,EAAE,YAAY,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,IAAI;IACnB,6DAA6D;IAC7D,MAAM,EAAE,YAAY,CAAC;IACrB,8CAA8C;IAC9C,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,OAAO;IACtB,8EAA8E;IAC9E,QAAQ,EAAE,UAAU,CAAC;IACrB,mFAAmF;IACnF,OAAO,EAAE,WAAW,CAAC;IACrB,6CAA6C;IAC7C,WAAW,EAAE,YAAY,CAAC;IAC1B,uCAAuC;IACvC,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,WAAW,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,yFAAyF;AACzF,MAAM,WAAW,OAAO;IACtB,sFAAsF;IACtF,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB;;;;;OAKG;IACH,KAAK,EAAE,WAAW,CAAC;IACnB,sEAAsE;IACtE,IAAI,EAAE,UAAU,CAAC;IACjB,8EAA8E;IAC9E,WAAW,EAAE,YAAY,CAAC;IAC1B,gDAAgD;IAChD,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACtB,wDAAwD;IACxD,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,uCAAuC;IACvC,KAAK,EAAE,KAAK,CAAC;IACb,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;CACf;AAED,iIAAiI;AACjI,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,CAAE,SAAQ,OAAO;IAC9E,iFAAiF;IACjF,OAAO,CAAC,EAAE,CAAC,CAAC;CACb;AAED,sFAAsF;AACtF,MAAM,WAAW,yBAAyB;IACxC,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}