@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.
- package/CHANGELOG.md +82 -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 +696 -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 +14 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +13 -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 +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -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 +1900 -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/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/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/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 +13 -0
- package/src/flat.ts +204 -0
- package/src/index.ts +155 -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/source.ts +132 -0
- package/src/types.ts +163 -0
- package/src/vineyard.ts +463 -0
package/src/prepared.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
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 type { PersistenceOptions } from './persistence.js';
|
|
9
|
+
import { diagramOf } from './diagram_of.js';
|
|
10
|
+
import type { ComplexLike, Diagram, Scale } from './types.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A complex validated, copied and prepared once by {@link prepareComplex}
|
|
14
|
+
* (canonical simplex order and boundary indices held in the module's memory),
|
|
15
|
+
* answering {@link PreparedComplex.persistence} without repeating that work.
|
|
16
|
+
* The object is frozen.
|
|
17
|
+
*/
|
|
18
|
+
export interface PreparedComplex {
|
|
19
|
+
/** The number of simplices of the snapshot. */
|
|
20
|
+
readonly size: number;
|
|
21
|
+
/** The scale of the snapshot's values, copied from the input (`'value'` when it had none). */
|
|
22
|
+
readonly scale: Scale;
|
|
23
|
+
/** `true` once {@link PreparedComplex.dispose} or `unload()` has released the native snapshot. */
|
|
24
|
+
readonly disposed: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The persistence diagram of the snapshot: the same arrays, in the same
|
|
27
|
+
* order, as `persistence(complex, opts)` of the complex as it was when it
|
|
28
|
+
* was prepared. Every call runs the reduction; no diagram is cached. The
|
|
29
|
+
* result is a plain copy that owns no wasm memory: it stays valid after
|
|
30
|
+
* disposal and after `unload()`, and survives `postMessage`. Throws an
|
|
31
|
+
* `Error` once the handle is disposed; a bad option throws as
|
|
32
|
+
* `persistence` does (`TypeError` or `RangeError`).
|
|
33
|
+
*/
|
|
34
|
+
persistence(opts?: PersistenceOptions): Diagram;
|
|
35
|
+
/**
|
|
36
|
+
* Releases the native snapshot. Idempotent: a second call does nothing.
|
|
37
|
+
* Call it when done; until then the handle is held by the module's
|
|
38
|
+
* cleanup list, so dropping the last reference does not free it before
|
|
39
|
+
* `unload()`.
|
|
40
|
+
*/
|
|
41
|
+
dispose(): void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* **Experimental.** Validate, copy and prepare `complex` once, for repeated
|
|
46
|
+
* persistence queries (other fields, other `minPersistence` cutoffs). The
|
|
47
|
+
* checks are those of `persistence`: a complex that `persistence` refuses,
|
|
48
|
+
* `prepareComplex` refuses with the same error, and no handle is created.
|
|
49
|
+
*
|
|
50
|
+
* Ownership:
|
|
51
|
+
* - The snapshot is a copy: changing the input arrays afterwards does not
|
|
52
|
+
* change it. A changed topology or filtration needs a new handle.
|
|
53
|
+
* - Every diagram is an independent copy and remains valid after disposal
|
|
54
|
+
* or `unload()`; diagrams can be sent through `postMessage`.
|
|
55
|
+
* - The handle belongs to the module instance (one per thread) that made it
|
|
56
|
+
* and cannot be transferred or cloned. Another worker prepares its own
|
|
57
|
+
* snapshot from the plain complex.
|
|
58
|
+
* - `dispose()` is idempotent; `persistence` on a disposed handle throws an
|
|
59
|
+
* `Error`.
|
|
60
|
+
* - `unload()` disposes every outstanding handle, and a later `load()` never
|
|
61
|
+
* revives one. So does a trap of the module (a call that runs out of
|
|
62
|
+
* memory), which replaces its instance. Undisposed handles stay allocated until `unload()`, so dispose
|
|
63
|
+
* each one explicitly.
|
|
64
|
+
* - Native allocations are freed on disposal, but the wasm linear memory
|
|
65
|
+
* does not shrink: its high-water mark stays until the module is unloaded
|
|
66
|
+
* and collected.
|
|
67
|
+
*
|
|
68
|
+
* The ordinary `persistence(complex)` stays stateless; nothing here caches a
|
|
69
|
+
* caller's object or a result.
|
|
70
|
+
*/
|
|
71
|
+
export function prepareComplex(complex: ComplexLike): PreparedComplex {
|
|
72
|
+
module();
|
|
73
|
+
const c = complexArgs(complex, 'complex');
|
|
74
|
+
const { top, scale } = c;
|
|
75
|
+
// The native object stays in this closure: no pointer is exposed that could
|
|
76
|
+
// be forged or used after its module is unloaded.
|
|
77
|
+
let raw = call('prepareComplex', (m) => new m.PreparedComplex(c.vertices, c.offsets, c.filtrations));
|
|
78
|
+
let unregister: (() => void) | undefined;
|
|
79
|
+
// After a trap the instance may be mid-operation (wasm-bindgen's borrow of
|
|
80
|
+
// this handle never released): the handle is abandoned with the instance
|
|
81
|
+
// it belongs to, never freed in it. `__destroy_into_raw()` (wasm-bindgen's
|
|
82
|
+
// generated class, JavaScript only) zeroes the object's pointer and
|
|
83
|
+
// unregisters its finalizer, which would otherwise call into the trapped
|
|
84
|
+
// instance on a later garbage collection.
|
|
85
|
+
const release = (trapped: boolean) => {
|
|
86
|
+
if (raw === null) return;
|
|
87
|
+
const owned = raw;
|
|
88
|
+
raw = null;
|
|
89
|
+
unregister?.();
|
|
90
|
+
unregister = undefined;
|
|
91
|
+
if (trapped) owned.__destroy_into_raw();
|
|
92
|
+
else owned.delete();
|
|
93
|
+
};
|
|
94
|
+
const dispose = () => release(false);
|
|
95
|
+
unregister = onUnload(release);
|
|
96
|
+
return Object.freeze({
|
|
97
|
+
size: c.filtrations.length,
|
|
98
|
+
scale,
|
|
99
|
+
get disposed() {
|
|
100
|
+
return raw === null;
|
|
101
|
+
},
|
|
102
|
+
persistence(opts?: PersistenceOptions): Diagram {
|
|
103
|
+
if (raw === null) throw new Error('prepared complex has been disposed');
|
|
104
|
+
const o = options<PersistenceOptions>(opts, 'PreparedComplex.persistence', PERSISTENCE_KEYS);
|
|
105
|
+
const coeff = checkCoeff(o.coeff);
|
|
106
|
+
const minPersistence = checkMinPersistence(o.minPersistence);
|
|
107
|
+
return call('prepareComplex', () => diagramOf(raw!.persistence(coeff), top, scale, coeff, minPersistence));
|
|
108
|
+
},
|
|
109
|
+
dispose
|
|
110
|
+
});
|
|
111
|
+
}
|
package/src/source.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
/**
|
|
12
|
+
* Where `load` reads a module from: a URL (or its string; in Node the
|
|
13
|
+
* string must be an absolute URL, such as a `file:` URL) or request, a fetch
|
|
14
|
+
* `Response` (or a promise of one), the bytes (an `ArrayBuffer`, or any
|
|
15
|
+
* view of one: a typed array, a Node `Buffer` or a `DataView`), or a
|
|
16
|
+
* compiled `WebAssembly.Module`. A WebAssembly module other than the
|
|
17
|
+
* package's is refused with a `TypeError`. Written without DOM-only names so that a Node
|
|
18
|
+
* project compiles without the DOM lib: the compiled module is typed
|
|
19
|
+
* `WebAssembly.Module` where the environment's types declare it, otherwise
|
|
20
|
+
* any object.
|
|
21
|
+
*/
|
|
22
|
+
export type LoadSource =
|
|
23
|
+
| string
|
|
24
|
+
| Request
|
|
25
|
+
| URL
|
|
26
|
+
| Response
|
|
27
|
+
| ArrayBuffer
|
|
28
|
+
| ArrayBufferView
|
|
29
|
+
| (typeof globalThis extends { WebAssembly: { Module: abstract new (...args: never[]) => infer M } } ? M & object : object)
|
|
30
|
+
| Promise<
|
|
31
|
+
| string
|
|
32
|
+
| Request
|
|
33
|
+
| URL
|
|
34
|
+
| Response
|
|
35
|
+
| ArrayBuffer
|
|
36
|
+
| ArrayBufferView
|
|
37
|
+
| (typeof globalThis extends { WebAssembly: { Module: abstract new (...args: never[]) => infer M } } ? M & object : object)
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
const isNode = typeof process !== 'undefined' && typeof process.versions?.node === 'string';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Node's `fs/promises`, reached so that no bundler sees a dependency on it:
|
|
44
|
+
* a literal `import('node:fs/promises')` stops esbuild ("Could not resolve"),
|
|
45
|
+
* fails webpack 5 (UnhandledSchemeError) and makes Vite warn that the module
|
|
46
|
+
* was externalized, in every browser bundle of the package, although this
|
|
47
|
+
* branch only runs in Node. `process.getBuiltinModule` (Node 22.3 and later)
|
|
48
|
+
* needs no import; the fallback (Node 22.0 to 22.2) builds the specifier at
|
|
49
|
+
* run time, which bundlers leave alone.
|
|
50
|
+
*/
|
|
51
|
+
async function nodeFs(): Promise<typeof import('node:fs/promises')> {
|
|
52
|
+
const get = (process as { getBuiltinModule?: (id: string) => unknown }).getBuiltinModule;
|
|
53
|
+
if (typeof get === 'function') return get.call(process, 'node:fs/promises') as typeof import('node:fs/promises');
|
|
54
|
+
return import(/* @vite-ignore */ /* webpackIgnore: true */ ['node', 'fs/promises'].join(':'));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether `s` parses as an absolute URL (a scheme and the rest). */
|
|
58
|
+
function isAbsoluteUrl(s: string): boolean {
|
|
59
|
+
try {
|
|
60
|
+
new URL(s);
|
|
61
|
+
return true;
|
|
62
|
+
} catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The compiled module from `source`; without one, from `fallback()` (the
|
|
69
|
+
* binary next to the package's code: read from the file in Node, fetched in
|
|
70
|
+
* a browser). Any `ArrayBufferView` is read as the bytes it views, a
|
|
71
|
+
* `DataView` included. `expected` names an export only the right module
|
|
72
|
+
* has, and `file` the file it comes from, for the refusal of another
|
|
73
|
+
* WebAssembly module.
|
|
74
|
+
*/
|
|
75
|
+
export async function compileSource(
|
|
76
|
+
source: LoadSource | undefined,
|
|
77
|
+
fallback: () => URL,
|
|
78
|
+
expected: { exports: readonly string[]; file: string; pkg: string }
|
|
79
|
+
): Promise<Exclude<Awaited<LoadSource>, string | Request | URL | Response | ArrayBuffer | ArrayBufferView>> {
|
|
80
|
+
const compiled = await compile(source, fallback);
|
|
81
|
+
const names = new Set(WebAssembly.Module.exports(compiled).map((e) => e.name));
|
|
82
|
+
if (!expected.exports.every((name) => names.has(name))) {
|
|
83
|
+
throw new TypeError(`source is a WebAssembly module, but not ${expected.pkg}'s ${expected.file}`);
|
|
84
|
+
}
|
|
85
|
+
return compiled as Exclude<Awaited<LoadSource>, string | Request | URL | Response | ArrayBuffer | ArrayBufferView>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The built-in kind of a value (`'ArrayBuffer'`, `'URL'`, …), the same for one made in another realm (an iframe, a `vm` context). */
|
|
89
|
+
function tag(v: unknown): string {
|
|
90
|
+
return Object.prototype.toString.call(v).slice(8, -1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function compile(source: LoadSource | undefined, fallback: () => URL): Promise<WebAssembly.Module> {
|
|
94
|
+
let s: unknown = await source;
|
|
95
|
+
if (s === undefined) s = fallback();
|
|
96
|
+
// Kinds are told by their tags, not instanceof, so that a source made in
|
|
97
|
+
// another realm is read as the same kind of source.
|
|
98
|
+
const kind = tag(s);
|
|
99
|
+
if (kind === 'WebAssembly.Module') return s as WebAssembly.Module;
|
|
100
|
+
if (kind === 'ArrayBuffer') return WebAssembly.compile(s as ArrayBuffer);
|
|
101
|
+
if (ArrayBuffer.isView(s)) {
|
|
102
|
+
// Every view as its bytes: WebAssembly.compile itself takes no DataView.
|
|
103
|
+
return WebAssembly.compile(new Uint8Array(s.buffer, s.byteOffset, s.byteLength) as Uint8Array<ArrayBuffer>);
|
|
104
|
+
}
|
|
105
|
+
if (isNode && typeof s === 'string' && !isAbsoluteUrl(s)) {
|
|
106
|
+
throw new TypeError(
|
|
107
|
+
`source "${s}" is not a URL: in Node, pass a URL (such as new URL('./tda.wasm', import.meta.url) or a file: URL) ` +
|
|
108
|
+
'or the bytes (for example from fs.readFile)'
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
// A URL of another realm, as a URL of this one.
|
|
112
|
+
if (kind === 'URL') s = new URL(String(s));
|
|
113
|
+
if (isNode && (s instanceof URL || (typeof s === 'string' && s.startsWith('file:')))) {
|
|
114
|
+
const url = s instanceof URL ? s : new URL(s);
|
|
115
|
+
if (url.protocol === 'file:') {
|
|
116
|
+
const { readFile } = await nodeFs();
|
|
117
|
+
return WebAssembly.compile((await readFile(url)) as Uint8Array<ArrayBuffer>);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (typeof s === 'string' || s instanceof URL || tag(s) === 'Request') {
|
|
121
|
+
s = await fetch(s as RequestInfo | URL);
|
|
122
|
+
}
|
|
123
|
+
if (tag(s) === 'Response') {
|
|
124
|
+
const r = s as Response;
|
|
125
|
+
if (!r.ok) throw new Error(`fetching the WebAssembly module failed: ${r.status} ${r.statusText} (${r.url})`);
|
|
126
|
+
if (typeof WebAssembly.compileStreaming === 'function' && r.headers.get('Content-Type') === 'application/wasm') {
|
|
127
|
+
return WebAssembly.compileStreaming(r);
|
|
128
|
+
}
|
|
129
|
+
return WebAssembly.compile(await r.arrayBuffer());
|
|
130
|
+
}
|
|
131
|
+
throw new TypeError('source must be a URL, a Request, a Response, the bytes or a WebAssembly.Module');
|
|
132
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
|
|
9
|
+
export type { PointCloud };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The quantity a filtration's values measure, carried by every complex and
|
|
13
|
+
* diagram.
|
|
14
|
+
*
|
|
15
|
+
* - `'edgeLength'`: an edge length, twice a ball radius (Rips, ellipsoid
|
|
16
|
+
* Rips; cutoff `maxEdgeLength`);
|
|
17
|
+
* - `'radius'`: the radius of a ball (Čech, Delaunay–Čech, ellipsoid Čech;
|
|
18
|
+
* cutoff `maxRadius`);
|
|
19
|
+
* - `'squaredRadius'`: a squared radius, negative at weighted vertices
|
|
20
|
+
* (alpha, coupled alpha, k-fold cover; cutoff `maxSquaredRadius`);
|
|
21
|
+
* - `'squaredRelaxation'`: the relaxation of the witness complex, a squared
|
|
22
|
+
* length (cutoff `maxSquaredRelaxation`);
|
|
23
|
+
* - `'epsilon'`: the wing length ε (wing complex; cutoff `maxEpsilon`);
|
|
24
|
+
* - `'growthRadius'`: the ℓ∞ radius `j · stepSize` within which the boxes of
|
|
25
|
+
* the box filtration grow (cutoffs `stepSize`, `maxSteps`);
|
|
26
|
+
* - `'value'`: the caller's own values (cubical complexes, a complex the
|
|
27
|
+
* caller builds, zigzag operations).
|
|
28
|
+
*/
|
|
29
|
+
export type Scale =
|
|
30
|
+
| 'edgeLength'
|
|
31
|
+
| 'radius'
|
|
32
|
+
| 'squaredRadius'
|
|
33
|
+
| 'squaredRelaxation'
|
|
34
|
+
| 'epsilon'
|
|
35
|
+
| 'growthRadius'
|
|
36
|
+
| 'value';
|
|
37
|
+
|
|
38
|
+
/** 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. */
|
|
39
|
+
export interface DistanceMatrix {
|
|
40
|
+
/** The `n²` distances, row-major. */
|
|
41
|
+
distances: Float64Array;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* An image or a volume: `values` row-major in NumPy's order, the last axis
|
|
46
|
+
* fastest. A `height × width` image is `shape: [height, width]`, its pixel
|
|
47
|
+
* `(row, column)` at `values[row · width + column]`, as in `ImageData`.
|
|
48
|
+
*/
|
|
49
|
+
export interface Grid {
|
|
50
|
+
/** The values, row-major (length the product of `shape`). */
|
|
51
|
+
values: Float64Array;
|
|
52
|
+
/** The extent of each axis, slowest first. */
|
|
53
|
+
shape: number[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A filtered simplicial complex as three typed arrays (CSR): simplex `i` is
|
|
58
|
+
* `vertices[offsets[i] .. offsets[i + 1])`, its vertex ids in increasing
|
|
59
|
+
* order, entered at `filtrations[i]`.
|
|
60
|
+
*
|
|
61
|
+
* Every builder lists its simplices in one documented order: by value
|
|
62
|
+
* (`-0` equal to `+0`), then by dimension, then lexicographically on the
|
|
63
|
+
* increasing vertex lists (as Python sorts lists). Values never decrease,
|
|
64
|
+
* and every face comes before its cofaces. (Where the input's ties are not
|
|
65
|
+
* exact in double precision, the full Čech builder raises a coface to its
|
|
66
|
+
* faces' values; see `cechComplex`.)
|
|
67
|
+
*
|
|
68
|
+
* A function that takes simplices (`persistence`, `volumeOptimalCycles`,
|
|
69
|
+
* `flatten`, the ladder filtrations) accepts each simplex's vertices in any
|
|
70
|
+
* order and sorts them; a vertex listed twice in one simplex is refused with
|
|
71
|
+
* a `RangeError`.
|
|
72
|
+
*/
|
|
73
|
+
export interface Complex {
|
|
74
|
+
/** Concatenated vertex ids of every simplex (increasing within a simplex). */
|
|
75
|
+
vertices: Int32Array;
|
|
76
|
+
/** Length `count + 1`; simplex `i` is `vertices[offsets[i] .. offsets[i + 1])`. */
|
|
77
|
+
offsets: Uint32Array;
|
|
78
|
+
/** The value at which simplex `i` enters. */
|
|
79
|
+
filtrations: Float64Array;
|
|
80
|
+
/** The quantity the values measure. */
|
|
81
|
+
scale: Scale;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* What the functions that take a complex accept: a {@link Complex}, or the
|
|
86
|
+
* same three arrays as number arrays (converted, with integer checks), with
|
|
87
|
+
* or without `scale`.
|
|
88
|
+
*/
|
|
89
|
+
export interface ComplexLike {
|
|
90
|
+
vertices: ArrayLike<number>;
|
|
91
|
+
offsets: ArrayLike<number>;
|
|
92
|
+
filtrations: ArrayLike<number>;
|
|
93
|
+
scale?: Scale;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** One simplex as an object (what {@link materialize} builds from a {@link Complex}). */
|
|
97
|
+
export interface Simplex {
|
|
98
|
+
/** Vertex ids, increasing in what the package returns; any order in what it takes. */
|
|
99
|
+
vertices: number[];
|
|
100
|
+
/** The value at which the simplex enters. */
|
|
101
|
+
filtration: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Every cell of a T-construction cubical complex, in the order (value, then
|
|
106
|
+
* cell dimension, then bitmap position).
|
|
107
|
+
*/
|
|
108
|
+
export interface CubicalComplex {
|
|
109
|
+
/** The grid's shape (the input's, slowest axis first). */
|
|
110
|
+
shape: number[];
|
|
111
|
+
/**
|
|
112
|
+
* Position of each cell in the bitmap, the grid of `2 · shape[i] + 1`
|
|
113
|
+
* positions along axis `i`, numbered row-major (the last axis fastest): a
|
|
114
|
+
* cell's coordinate is odd along the axes it spans, and the pixel at
|
|
115
|
+
* `(p0, p1, …)` is the cell at `(2 p0 + 1, 2 p1 + 1, …)`.
|
|
116
|
+
*/
|
|
117
|
+
cells: Uint32Array;
|
|
118
|
+
/** The dimension of each cell (the number of its odd coordinates). */
|
|
119
|
+
dims: Uint8Array;
|
|
120
|
+
/** The value of each cell: the smallest value of the pixels containing it. */
|
|
121
|
+
filtrations: Float64Array;
|
|
122
|
+
/** Always `'value'`: the image's own values. */
|
|
123
|
+
scale: 'value';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A persistence diagram. `pairs[k]` lists the classes of Hₖ as
|
|
128
|
+
* `[birth, death, birth, death, …]`, essential classes with
|
|
129
|
+
* `death = Infinity`, one array per homology dimension from 0 to the highest
|
|
130
|
+
* the call computes (empty arrays included). Pairs of length zero are left
|
|
131
|
+
* out, and with the `minPersistence` option every finite pair with
|
|
132
|
+
* `death − birth <= minPersistence`.
|
|
133
|
+
*/
|
|
134
|
+
export interface Diagram {
|
|
135
|
+
/** `pairs[k]`: the pairs of Hₖ, `[birth, death, …]`. */
|
|
136
|
+
pairs: Float64Array[];
|
|
137
|
+
/** The quantity the values measure. */
|
|
138
|
+
scale: Scale;
|
|
139
|
+
/** The coefficient field `Z/coeff` the diagram was computed over. */
|
|
140
|
+
coeff: number;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The result of a builder's `…Persistence` function: the diagram, and with `complex: true` the complex it was computed from. */
|
|
144
|
+
export interface BuilderPersistence<C extends Complex = Complex> extends Diagram {
|
|
145
|
+
/** The complex, as the builder returns it; present only with `complex: true`. */
|
|
146
|
+
complex?: C;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Options every builder's `…Persistence` function takes beside the builder's own. */
|
|
150
|
+
export interface BuilderPersistenceOptions {
|
|
151
|
+
/** The prime `p` of the coefficient field `Z/p`, from 2 to `2^31 − 1`. Default 2. */
|
|
152
|
+
coeff?: number;
|
|
153
|
+
/** Also return the complex, as the builder returns it. Default `false`. */
|
|
154
|
+
complex?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Leave out the finite pairs with `death − birth <= minPersistence`
|
|
157
|
+
* (GUDHI's `min_persistence`); essential pairs are always kept. A finite
|
|
158
|
+
* number `>= 0`. Default 0: only the pairs of length zero are left out.
|
|
159
|
+
* `1e-12` removes the bars one ulp long that rounding leaves on symmetric
|
|
160
|
+
* input such as a lattice.
|
|
161
|
+
*/
|
|
162
|
+
minPersistence?: number;
|
|
163
|
+
}
|