@topolab/tda 0.3.0 → 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.
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Two-parameter persistent homology: minimal presentations, bigraded Betti
3
+ * numbers, the Hilbert function and the fibered barcode (the barcode along a
4
+ * line), over Z/2.
5
+ */
6
+ import { allFinite, f64, finite, int, isTyped, kind, nonNegative, options, points as checkPoints, sized } from './check.js';
7
+ import { distanceMatrix, isMatrix } from './complex.js';
8
+ import { call, module } from './load.js';
9
+ const FUNCTION_RIPS_KEYS = { degree: true, maxEdgeLength: true };
10
+ /** The module's six arrays with the degree (internal: also used by src/rivet_input.ts). */
11
+ export function presentationOf(raw, degree) {
12
+ return {
13
+ xs: raw.xs,
14
+ ys: raw.ys,
15
+ generators: raw.generators,
16
+ relations: raw.relations,
17
+ offsets: raw.offsets,
18
+ rows: raw.rows,
19
+ degree
20
+ };
21
+ }
22
+ /**
23
+ * The minimal presentation of the degree-`degree` homology of the
24
+ * function-Rips bifiltration of a point cloud or a distance matrix: the
25
+ * simplex on a set of points is present at `(a, r)` when every point has
26
+ * function value `<= a` and every pair is at distance `<= r`. `values[i]` is
27
+ * the function at point `i` (for instance a codensity, so that dense
28
+ * regions come first). Degrees 0, 1 and 2 never build the complex (degrees 0
29
+ * and 1 take thousands of points, degree 2 hundreds); higher degrees build it
30
+ * up to dimension `degree + 1`.
31
+ */
32
+ export function functionRipsPresentation(points, values, opts) {
33
+ module();
34
+ const o = options(opts, 'functionRipsPresentation', FUNCTION_RIPS_KEYS);
35
+ const matrix = isMatrix(points, 'points');
36
+ const n = matrix ? distanceMatrix(points, 'points') : checkPoints(points, 'points');
37
+ const fn = f64(values, 'values');
38
+ sized(fn.length, n, 'values', 'one function value per point');
39
+ allFinite(fn, 'values');
40
+ const degree = o.degree === undefined ? 1 : int(o.degree, 'degree', 0, 254);
41
+ const threshold = o.maxEdgeLength === undefined ? Infinity : nonNegative(o.maxEdgeLength, 'maxEdgeLength');
42
+ return call((m) => {
43
+ if (matrix) {
44
+ return presentationOf(m.functionRipsPresentationFromMatrixFlat(points.distances, n, fn, threshold, degree), degree);
45
+ }
46
+ const { coords, d } = points;
47
+ return presentationOf(m.functionRipsPresentationFlat(coords, d, fn, threshold, degree), degree);
48
+ });
49
+ }
50
+ const DEGREE_RIPS_KEYS = { degree: true, maxEdgeLength: true };
51
+ /**
52
+ * The minimal presentation of the degree-`degree` homology of the
53
+ * degree-Rips bifiltration of a point cloud or a distance matrix: at
54
+ * `(−k, r)`, the Rips complex at scale `r` on the points with at least `k`
55
+ * other points within `r`. The first coordinate is minus the degree, so that
56
+ * the complex grows along both axes; it needs no function on the points.
57
+ * Every simplex has one grade per degree its points reach, so the cost
58
+ * grows with the number of simplices times the number of points: for small
59
+ * clouds (about 60 points in degree 1 take a second).
60
+ */
61
+ export function degreeRipsPresentation(points, opts) {
62
+ module();
63
+ const o = options(opts, 'degreeRipsPresentation', DEGREE_RIPS_KEYS);
64
+ const matrix = isMatrix(points, 'points');
65
+ const n = matrix ? distanceMatrix(points, 'points') : checkPoints(points, 'points');
66
+ const degree = o.degree === undefined ? 1 : int(o.degree, 'degree', 0, 254);
67
+ const threshold = o.maxEdgeLength === undefined ? Infinity : nonNegative(o.maxEdgeLength, 'maxEdgeLength');
68
+ return call((m) => {
69
+ if (matrix) {
70
+ return presentationOf(m.degreeRipsPresentationFromMatrixFlat(points.distances, n, threshold, degree), degree);
71
+ }
72
+ const { coords, d } = points;
73
+ return presentationOf(m.degreeRipsPresentationFlat(coords, d, threshold, degree), degree);
74
+ });
75
+ }
76
+ const BIFILTRATION_PRESENTATION_KEYS = { degree: true };
77
+ /** A typed array of kind `arrayKind`, from this realm or another. */
78
+ function typed(v, arrayKind, name) {
79
+ if (!isTyped(v, arrayKind))
80
+ throw new TypeError(`${name} must be a ${arrayKind}, got ${kind(v)}`);
81
+ return v;
82
+ }
83
+ /** A data object (its fields are read, not listed): anything but an object is a `TypeError`. */
84
+ function record(v, name) {
85
+ if (v === null || typeof v !== 'object' || Array.isArray(v))
86
+ throw new TypeError(`${name} must be an object, got ${kind(v)}`);
87
+ return v;
88
+ }
89
+ /**
90
+ * The minimal presentation of the degree-`degree` homology of any
91
+ * bifiltered cell complex, one grade a cell or several, over Z/2.
92
+ */
93
+ export function bifiltrationPresentation(bifiltration, opts) {
94
+ module();
95
+ const b = record(bifiltration, 'bifiltration');
96
+ const o = options(opts, 'bifiltrationPresentation', BIFILTRATION_PRESENTATION_KEYS);
97
+ const dims = typed(b.dims, 'Uint8Array', 'bifiltration.dims');
98
+ const grades = typed(b.grades, 'Float64Array', 'bifiltration.grades');
99
+ const offsets = typed(b.offsets, 'Uint32Array', 'bifiltration.offsets');
100
+ const facets = typed(b.facets, 'Uint32Array', 'bifiltration.facets');
101
+ const degree = o.degree === undefined ? 1 : int(o.degree, 'degree', 0, 254);
102
+ if (b.gradeOffsets !== undefined) {
103
+ const gradeOffsets = typed(b.gradeOffsets, 'Uint32Array', 'bifiltration.gradeOffsets');
104
+ return call((m) => presentationOf(m.multicriticalPresentationFlat(dims, gradeOffsets, grades, offsets, facets, degree), degree));
105
+ }
106
+ return call((m) => presentationOf(m.bifiltrationPresentationFlat(dims, grades, offsets, facets, degree), degree));
107
+ }
108
+ /** A presentation's arrays, checked for their kinds (internal: also used by src/arrangement.ts). */
109
+ export function checked(p, name) {
110
+ const o = record(p, name);
111
+ typed(o.xs, 'Float64Array', `${name}.xs`);
112
+ typed(o.ys, 'Float64Array', `${name}.ys`);
113
+ typed(o.generators, 'Uint32Array', `${name}.generators`);
114
+ typed(o.relations, 'Uint32Array', `${name}.relations`);
115
+ typed(o.offsets, 'Uint32Array', `${name}.offsets`);
116
+ typed(o.rows, 'Uint32Array', `${name}.rows`);
117
+ return o;
118
+ }
119
+ function gradesOf(p, grid) {
120
+ const out = new Float64Array(grid.length);
121
+ for (let i = 0; i < grid.length; i += 2) {
122
+ out[i] = p.xs[grid[i]];
123
+ out[i + 1] = p.ys[grid[i + 1]];
124
+ }
125
+ return out;
126
+ }
127
+ /**
128
+ * The bigraded Betti numbers ξ₀, ξ₁, ξ₂ of a presented module (the grades
129
+ * of the generators, the relations and the relations among relations, with
130
+ * multiplicity) and its Hilbert function, the dimension of the module at
131
+ * every point of the plane.
132
+ */
133
+ export function bigradedBetti(presentation) {
134
+ module();
135
+ const p = checked(presentation, 'presentation');
136
+ return call((m) => {
137
+ const r = m.presentationInvariantsFlat(p.xs, p.ys, p.generators, p.relations, p.offsets, p.rows);
138
+ return {
139
+ b0: gradesOf(p, p.generators),
140
+ b1: gradesOf(p, p.relations),
141
+ b2: gradesOf(p, r.syzygies),
142
+ xs: p.xs,
143
+ ys: p.ys,
144
+ hilbert: r.hilbert
145
+ };
146
+ });
147
+ }
148
+ /**
149
+ * One line, checked, as the module reads it: `[px, py, a, b]` with `angle`
150
+ * false for the direction `(a, b)`, or `[px, py, degrees, 0]` with `angle`
151
+ * true. The module builds the line (it normalises the direction, or takes
152
+ * the cosine and sine of the angle), so that it is the line a Rust caller of
153
+ * `Line::new` or `Line::from_angle` gets, to the bit.
154
+ */
155
+ function lineOf(line, name) {
156
+ const l = record(line, name);
157
+ const point = l.point;
158
+ if (point === null || typeof point !== 'object' || point.length !== 2) {
159
+ throw new TypeError(`${name}.point must be [x, y], got ${kind(point)}`);
160
+ }
161
+ const px = finite(point[0], `${name}.point[0]`);
162
+ const py = finite(point[1], `${name}.point[1]`);
163
+ if (l.direction !== undefined) {
164
+ const direction = l.direction;
165
+ if (direction === null || typeof direction !== 'object' || direction.length !== 2) {
166
+ throw new TypeError(`${name}.direction must be [dx, dy], got ${kind(direction)}`);
167
+ }
168
+ const dx = nonNegative(direction[0], `${name}.direction[0]`);
169
+ const dy = nonNegative(direction[1], `${name}.direction[1]`);
170
+ if (!Number.isFinite(dx) || !Number.isFinite(dy) || (dx === 0 && dy === 0)) {
171
+ throw new RangeError(`${name}.direction must be finite and not zero, got [${dx}, ${dy}]`);
172
+ }
173
+ return { numbers: [px, py, dx, dy], angle: false };
174
+ }
175
+ const angle = finite(l.angle, `${name}.angle`);
176
+ if (angle < 0 || angle > 90)
177
+ throw new RangeError(`${name}.angle must be between 0 and 90 degrees, got ${angle}`);
178
+ return { numbers: [px, py, angle, 0], angle: true };
179
+ }
180
+ export function fiberedBarcode(presentation, lines) {
181
+ module();
182
+ const p = checked(presentation, 'presentation');
183
+ const { many, flat, angles } = linesOf(lines);
184
+ return call((m) => barcodesOf(m.presentationSliceFlat(p.xs, p.ys, p.generators, p.relations, p.offsets, p.rows, flat, angles), many));
185
+ }
186
+ /**
187
+ * One line or an array of lines as the module reads them: `[px, py, a, b, …]`
188
+ * and one flag per line, 1 when the line is given by its angle (internal:
189
+ * also used by src/arrangement.ts).
190
+ */
191
+ export function linesOf(lines) {
192
+ const many = Array.isArray(lines);
193
+ const list = (many ? lines : [lines]);
194
+ const flat = new Float64Array(4 * list.length);
195
+ const angles = new Uint8Array(list.length);
196
+ list.forEach((l, i) => {
197
+ const { numbers, angle } = lineOf(l, many ? `lines[${i}]` : 'line');
198
+ flat.set(numbers, 4 * i);
199
+ angles[i] = angle ? 1 : 0;
200
+ });
201
+ return { many, flat, angles };
202
+ }
203
+ /**
204
+ * The barcodes of `{ pairs, offsets, lines }`, each with the line the module
205
+ * built (internal: also used by src/arrangement.ts).
206
+ */
207
+ export function barcodesOf(r, many) {
208
+ const out = [];
209
+ for (let i = 0; i < r.lines.length / 4; i++) {
210
+ out.push({
211
+ pairs: r.pairs.slice(2 * r.offsets[i], 2 * r.offsets[i + 1]),
212
+ point: [r.lines[4 * i], r.lines[4 * i + 1]],
213
+ direction: [r.lines[4 * i + 2], r.lines[4 * i + 3]]
214
+ });
215
+ }
216
+ return many ? out : out[0];
217
+ }
218
+ const FIREP_KEYS = { degree: true };
219
+ function firepMatrix(v, name) {
220
+ const m = record(v, name);
221
+ return {
222
+ grades: typed(m.grades, 'Float64Array', `${name}.grades`),
223
+ offsets: typed(m.offsets, 'Uint32Array', `${name}.offsets`),
224
+ rows: typed(m.rows, 'Uint32Array', `${name}.rows`)
225
+ };
226
+ }
227
+ /**
228
+ * The minimal presentation of the homology of a chain complex of free
229
+ * bigraded modules at its middle (RIVET's FIRep input), over Z/2.
230
+ */
231
+ export function firepPresentation(firep, opts) {
232
+ module();
233
+ const f = record(firep, 'firep');
234
+ const high = firepMatrix(f.high, 'firep.high');
235
+ const low = firepMatrix(f.low, 'firep.low');
236
+ const lowRank = int(f.lowRank, 'firep.lowRank', 0);
237
+ const o = options(opts, 'firepPresentation', FIREP_KEYS);
238
+ const degree = o.degree === undefined ? 1 : int(o.degree, 'degree', 0, 254);
239
+ return call((m) => presentationOf(m.firepPresentationFlat(high.grades, high.offsets, high.rows, low.grades, low.offsets, low.rows, lowRank), degree));
240
+ }
241
+ const COARSEN_KEYS = { xbins: true, ybins: true, xRange: true, yRange: true };
242
+ function rangeOf(v, name) {
243
+ if (v === undefined)
244
+ return new Float64Array(0);
245
+ if (v === null || typeof v !== 'object' || v.length !== 2) {
246
+ throw new TypeError(`${name} must be [lo, hi], got ${kind(v)}`);
247
+ }
248
+ const r = v;
249
+ const lo = finite(r[0], `${name}[0]`);
250
+ const hi = finite(r[1], `${name}[1]`);
251
+ if (lo > hi)
252
+ throw new RangeError(`${name} must have lo <= hi, got [${lo}, ${hi}]`);
253
+ return Float64Array.of(lo, hi);
254
+ }
255
+ /**
256
+ * The minimal presentation of the module coarsened onto a grid, as RIVET
257
+ * coarsens with `--xbins` and `--ybins`: `xbins` values evenly spaced over
258
+ * `xRange`, the last at its end (`lo + k (hi − lo) / xbins`, `k = 1 …
259
+ * xbins`), the same for `y`, and every grade rounded up to the grid. The
260
+ * coarsened module at a point is the module at the largest grid point below
261
+ * it, so fewer grades, fewer anchors and a smaller augmented arrangement,
262
+ * at the price of moving every interval's ends up to the grid.
263
+ */
264
+ export function coarsenPresentation(presentation, opts) {
265
+ module();
266
+ const p = checked(presentation, 'presentation');
267
+ const o = options(opts, 'coarsenPresentation', COARSEN_KEYS);
268
+ const xbins = o.xbins === undefined ? 0 : int(o.xbins, 'xbins', 0);
269
+ const ybins = o.ybins === undefined ? 0 : int(o.ybins, 'ybins', 0);
270
+ const xRange = rangeOf(o.xRange, 'xRange');
271
+ const yRange = rangeOf(o.yRange, 'yRange');
272
+ const degree = typeof p.degree === 'number' ? p.degree : 0;
273
+ return call((m) => presentationOf(m.presentationCoarsenFlat(p.xs, p.ys, p.generators, p.relations, p.offsets, p.rows, xbins, ybins, xRange, yRange), degree));
274
+ }
275
+ //# sourceMappingURL=two_parameter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"two_parameter.js","sourceRoot":"","sources":["../src/two_parameter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE5H,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAiCzC,MAAM,kBAAkB,GAA0C,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;AAExG,2FAA2F;AAC3F,MAAM,UAAU,cAAc,CAAC,GAAiC,EAAE,MAAc;IAC9E,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,MAAM;KACP,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAA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CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAChB,cAAc,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAC1I,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topolab/tda",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "topolab TDA, the WebAssembly build of its Rust core: alpha, Čech, Delaunay–Čech, Rips, witness, k-fold cover, ellipsoid, wing, box and cubical complexes, persistent homology and zigzag persistence, exact diagram distances and persistence representations.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The augmented arrangement of a two-parameter persistence module: a native
3
+ * structure that answers barcodes along lines without a reduction per line.
4
+ * Exported only from `@topolab/tda/experimental` (src/experimental.ts).
5
+ */
6
+ import { call, module, onUnload } from './load.js';
7
+ import { barcodesOf, checked, linesOf } from './two_parameter.js';
8
+ import type { FiberedBarcode, Presentation, SliceLine } from './two_parameter.js';
9
+
10
+ /**
11
+ * The augmented arrangement of a presented module, built once by
12
+ * {@link augmentedArrangement} and held in the module's memory. The object
13
+ * is frozen.
14
+ */
15
+ export interface AugmentedArrangement {
16
+ /**
17
+ * The anchors kept, as grades `[x, y, …]`: the least upper bounds of two
18
+ * incomparable grades whose order along a line decides the barcode. Each
19
+ * is a segment of the arrangement in the space of lines.
20
+ */
21
+ readonly anchors: Float64Array;
22
+ /** The number of cells (faces of the arrangement). */
23
+ readonly cells: number;
24
+ /** The number of distinct barcode templates among the cells. */
25
+ readonly templates: number;
26
+ /** `true` once {@link AugmentedArrangement.dispose} or `unload()` has released it. */
27
+ readonly disposed: boolean;
28
+ /**
29
+ * The barcode along a line, or along each line of an array: the same
30
+ * arrays as `fiberedBarcode(presentation, lines)`, read off the template
31
+ * of the line's cell. The results are plain copies that own no wasm
32
+ * memory. Throws an `Error` once the arrangement is disposed.
33
+ */
34
+ fiberedBarcode(line: SliceLine): FiberedBarcode;
35
+ fiberedBarcode(lines: readonly SliceLine[]): FiberedBarcode[];
36
+ /**
37
+ * Releases the native arrangement. Idempotent. Until then it is held by
38
+ * the module's cleanup list, so dropping the last reference does not free
39
+ * it before `unload()`.
40
+ */
41
+ dispose(): void;
42
+ }
43
+
44
+ /**
45
+ * **Experimental.** The augmented arrangement of a presented module
46
+ * (Lesnick and Wright, [reference](https://topolab.ai/tda/docs/references/#lesnick-and-wright-2015)):
47
+ * the lines of non-negative slope cut into cells, each with a barcode
48
+ * template, so that the barcode along any line costs locating its cell
49
+ * and one push per grade. Building it costs about one vineyard update per
50
+ * pair of cells and grades exchanged; the number of cells grows with the
51
+ * square of the number of anchors, so a large module is first coarsened
52
+ * (`coarsenPresentation`).
53
+ *
54
+ * Ownership is that of `prepareComplex`: the arrangement is a copy, held
55
+ * until `dispose()` or `unload()`, tied to the module instance (one per
56
+ * thread) that built it; every barcode is an independent copy.
57
+ */
58
+ export function augmentedArrangement(presentation: Presentation): AugmentedArrangement {
59
+ module();
60
+ const p = checked(presentation, 'presentation');
61
+ // The native object stays in this closure: no pointer is exposed that could
62
+ // be forged or used after its module is unloaded.
63
+ let raw = call((m) => new m.TwoParameterArrangement(p.xs, p.ys, p.generators, p.relations, p.offsets, p.rows));
64
+ const stats = call(() => raw!.stats());
65
+ const anchors = call(() => raw!.anchors());
66
+ let unregister: (() => void) | undefined;
67
+ // After a trap the handle is abandoned with its instance, never freed in
68
+ // it (see src/prepared.ts).
69
+ const release = (trapped: boolean) => {
70
+ if (raw === null) return;
71
+ const owned = raw;
72
+ raw = null;
73
+ unregister?.();
74
+ unregister = undefined;
75
+ if (trapped) owned.__destroy_into_raw();
76
+ else owned.delete();
77
+ };
78
+ unregister = onUnload(release);
79
+ function fiberedBarcode(line: SliceLine): FiberedBarcode;
80
+ function fiberedBarcode(lines: readonly SliceLine[]): FiberedBarcode[];
81
+ function fiberedBarcode(lines: SliceLine | readonly SliceLine[]): FiberedBarcode | FiberedBarcode[] {
82
+ if (raw === null) throw new Error('augmented arrangement has been disposed');
83
+ const { many, flat, angles } = linesOf(lines);
84
+ return call(() => barcodesOf(raw!.barcodes(flat, angles), many));
85
+ }
86
+ return Object.freeze({
87
+ anchors,
88
+ cells: stats[2]!,
89
+ templates: stats[3]!,
90
+ get disposed() {
91
+ return raw === null;
92
+ },
93
+ fiberedBarcode,
94
+ dispose: () => release(false)
95
+ });
96
+ }
@@ -3,11 +3,15 @@
3
3
  * release, outside the plain-data contract of the root entry point.
4
4
  *
5
5
  * `prepareComplex` keeps a validated complex in the module's memory for
6
- * repeated persistence queries. Unlike every root function, it returns a
7
- * handle that owns native memory: dispose it (or `unload()`). It uses the
8
- * module the root's `load()` loaded.
6
+ * repeated persistence queries, and `augmentedArrangement` the augmented
7
+ * arrangement of a two-parameter module for repeated barcodes along lines.
8
+ * Unlike every root function, they return handles that own native memory:
9
+ * dispose them (or `unload()`). They use the module the root's `load()`
10
+ * loaded.
9
11
  *
10
12
  * @packageDocumentation
11
13
  */
12
14
  export { prepareComplex } from './prepared.js';
13
15
  export type { PreparedComplex } from './prepared.js';
16
+ export { augmentedArrangement } from './arrangement.js';
17
+ export type { AugmentedArrangement } from './arrangement.js';
package/src/index.ts CHANGED
@@ -95,6 +95,32 @@ export type {
95
95
  BoxFiltrationPersistenceOptions
96
96
  } from './complex.js';
97
97
 
98
+ export {
99
+ functionRipsPresentation,
100
+ degreeRipsPresentation,
101
+ bifiltrationPresentation,
102
+ bigradedBetti,
103
+ fiberedBarcode,
104
+ coarsenPresentation,
105
+ firepPresentation
106
+ } from './two_parameter.js';
107
+ export { parseRivetInput, rivetPresentation } from './rivet_input.js';
108
+ export type { RivetInput, RivetPresentationOptions } from './rivet_input.js';
109
+ export type {
110
+ Presentation,
111
+ FunctionRipsPresentationOptions,
112
+ DegreeRipsPresentationOptions,
113
+ Bifiltration,
114
+ BifiltrationPresentationOptions,
115
+ BigradedBetti,
116
+ SliceLine,
117
+ FiberedBarcode,
118
+ CoarsenPresentationOptions,
119
+ Firep,
120
+ FirepMatrix,
121
+ FirepPresentationOptions
122
+ } from './two_parameter.js';
123
+
98
124
  export {
99
125
  persistence,
100
126
  ripsPersistence,
@@ -0,0 +1,195 @@
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 type { Keys, PointCloud } from './check.js';
27
+ import type { DistanceMatrix } from './types.js';
28
+ import { presentationOf } from './two_parameter.js';
29
+ import type { Bifiltration, Firep, Presentation } from './two_parameter.js';
30
+
31
+ /**
32
+ * One RIVET input data file as plain data. The kind of file decides which
33
+ * fields are present: `points` a cloud, `points_fn` values and a cloud,
34
+ * `metric` a distance matrix, `metric_fn` values and a distance matrix,
35
+ * `bifiltration` a bifiltration, `firep` a chain complex.
36
+ */
37
+ export interface RivetInput {
38
+ /** The kind of data, from `--datatype`; `points` when the flag is absent. */
39
+ datatype: 'points' | 'points_fn' | 'metric' | 'metric_fn' | 'bifiltration' | 'firep';
40
+ /** Every flag of the file: `--name value` as `name` -> value, a flag with no value as `true`. */
41
+ flags: Record<string, string | true>;
42
+ /** `points` and `points_fn`: the cloud. */
43
+ points?: PointCloud;
44
+ /** `metric` and `metric_fn`: the full `n x n` matrix, row-major (the upper-triangular form expanded). */
45
+ distances?: DistanceMatrix;
46
+ /** `points_fn` and `metric_fn`: the function values, one per point. */
47
+ values?: Float64Array;
48
+ /** `--maxdist` as a number; `Infinity` when the flag is absent. */
49
+ maxDistance: number;
50
+ /**
51
+ * `bifiltration`: the simplices as cells, in the file's order, every
52
+ * facet a cell of the file; `gradeOffsets` when any simplex has several
53
+ * grades. With `--xreverse` (`--yreverse`) the x (y) coordinate of every
54
+ * grade is negated, so that the result is an increasing bifiltration.
55
+ */
56
+ bifiltration?: Bifiltration;
57
+ /** `firep`: the chain complex `C2 -> C1 -> C0` over Z/2, both maps as CSR arrays. */
58
+ firep?: Firep;
59
+ }
60
+
61
+ /** What the module's `rivetInputFlat` returns: the data of the file's kind as flat arrays. */
62
+ interface RawInput {
63
+ datatype: RivetInput['datatype'];
64
+ flags: [string, string | true][];
65
+ maxDistance: number;
66
+ coords?: Float64Array;
67
+ d?: number;
68
+ distances?: Float64Array;
69
+ values?: Float64Array;
70
+ dims?: Uint8Array;
71
+ grades?: Float64Array;
72
+ offsets?: Uint32Array;
73
+ facets?: Uint32Array;
74
+ gradeOffsets?: Uint32Array;
75
+ highGrades?: Float64Array;
76
+ highOffsets?: Uint32Array;
77
+ highRows?: Uint32Array;
78
+ lowGrades?: Float64Array;
79
+ lowOffsets?: Uint32Array;
80
+ lowRows?: Uint32Array;
81
+ lowRank?: number;
82
+ }
83
+
84
+ /** The file's text as the UTF-8 bytes the module reads (a lone surrogate as U+FFFD). */
85
+ const encoder = new TextEncoder();
86
+
87
+ function textOf(v: unknown): Uint8Array {
88
+ if (typeof v !== 'string') throw new TypeError(`text must be a string, got ${kind(v)}`);
89
+ return encoder.encode(v);
90
+ }
91
+
92
+ /** The module's result as a {@link RivetInput}, its fields in the order of the kind. */
93
+ function inputOf(raw: RawInput): RivetInput {
94
+ const r = { datatype: raw.datatype, flags: Object.fromEntries(raw.flags) } as RivetInput;
95
+ switch (raw.datatype) {
96
+ case 'points':
97
+ case 'points_fn':
98
+ r.points = { coords: raw.coords!, d: raw.d! };
99
+ break;
100
+ case 'metric':
101
+ case 'metric_fn':
102
+ r.distances = { distances: raw.distances! };
103
+ break;
104
+ case 'bifiltration': {
105
+ const b: Bifiltration = { dims: raw.dims!, grades: raw.grades!, offsets: raw.offsets!, facets: raw.facets! };
106
+ if (raw.gradeOffsets !== undefined) b.gradeOffsets = raw.gradeOffsets;
107
+ r.bifiltration = b;
108
+ break;
109
+ }
110
+ case 'firep':
111
+ r.firep = {
112
+ high: { grades: raw.highGrades!, offsets: raw.highOffsets!, rows: raw.highRows! },
113
+ low: { grades: raw.lowGrades!, offsets: raw.lowOffsets!, rows: raw.lowRows! },
114
+ lowRank: raw.lowRank!
115
+ };
116
+ break;
117
+ }
118
+ if (raw.values !== undefined) r.values = raw.values;
119
+ r.maxDistance = raw.maxDistance;
120
+ return r;
121
+ }
122
+
123
+ /**
124
+ * Reads the text of a RIVET input data file into plain data, as
125
+ * {@link RivetInput}. The six kinds of file of RIVET 1.1 are read:
126
+ * `points`, `points_fn`, `metric`, `metric_fn`, `bifiltration`
127
+ * (multicritical allowed) and `firep`; `--datatype` selects the kind and
128
+ * `points` when the flag is absent. A distance matrix is read in either of
129
+ * the two forms the documentation gives, and the upper-triangular one is
130
+ * expanded to the full symmetric matrix. A bifiltration keeps the file's
131
+ * simplex order, and every facet must itself be listed as a simplex, on
132
+ * any line of the file; with `--xreverse` (`--yreverse`) the x (y)
133
+ * coordinate of every grade is negated, so that the result is an
134
+ * increasing bifiltration. The grades of a firep are as the file gives
135
+ * them; a firep's reverse flags are kept in `flags` only. The Rust crate
136
+ * reads the file (`parse_rivet_input`), so it needs the module.
137
+ */
138
+ export function parseRivetInput(text: string): RivetInput {
139
+ module();
140
+ const bytes = textOf(text);
141
+ return call('parseRivetInput', (m) => inputOf(m.rivetInputFlat(bytes) as RawInput));
142
+ }
143
+
144
+ /** Options of {@link rivetPresentation}. */
145
+ export interface RivetPresentationOptions {
146
+ /** Homology degree, a non-negative integer (RIVET's `--homology`). Default 0, as in RIVET. */
147
+ degree?: number;
148
+ }
149
+ const RIVET_PRESENTATION_KEYS: Keys<RivetPresentationOptions> = { degree: true };
150
+
151
+ /**
152
+ * The minimal presentation of the module the RIVET input file `text`
153
+ * describes, in degree `degree`, built as RIVET 1.1 builds it (by the Rust
154
+ * crate's `rivet_presentation`):
155
+ *
156
+ * - A point cloud or a metric space with function values (`points_fn`,
157
+ * `metric_fn`) gives the function-Rips bifiltration
158
+ * (`functionRipsPresentation`); `--xreverse` filters by decreasing value
159
+ * (the values negated), and `--bifil degree` gives the degree-Rips
160
+ * bifiltration instead.
161
+ * - Without function values (`points`, `metric`) it is the degree-Rips
162
+ * bifiltration (`degreeRipsPresentation`, whose first coordinate is minus
163
+ * the degree); `--bifil function` gives the function-Rips bifiltration of
164
+ * `balldensity[]`, by decreasing value.
165
+ * - `--function balldensity[r]`, `gaussian[σ]` or `eccentricity[p]`
166
+ * computes the function on the points or the metric space (values in the
167
+ * file are not used) and gives its function-Rips bifiltration, whatever
168
+ * `--bifil` says: the ball density `C·#{y : d(x, y) <= r}`, the Gaussian
169
+ * density `C·Σ_y exp(−d(x, y)²/(2σ²))` (`C` makes the values sum to 1) and
170
+ * the eccentricity `(Σ_y d(x, y)^p / n)^(1/p)`. Empty brackets take
171
+ * RIVET's defaults: `r` and `σ` RIVET 1.1's 20th percentile of the
172
+ * distances (entry `⌊M/5⌋ − 1` of the distances of all `M` pairs in
173
+ * increasing order, coincident points' zeros counted; 0 when `M < 5`, and
174
+ * then a point's density counts the points that coincide with it), and
175
+ * `p = 1`. `p` may be any real number at least 1, as RIVET's documentation
176
+ * defines it (RIVET 1.1 truncates it to an integer). The filtration is by
177
+ * decreasing value, with or without `--xreverse`, as RIVET's documentation
178
+ * sets it.
179
+ * - A bifiltration gives `bifiltrationPresentation`, a FIRep
180
+ * `firepPresentation`.
181
+ *
182
+ * Rips bifiltrations go up to `--maxdist`. The file is refused as
183
+ * {@link parseRivetInput} refuses it; `--function user` on a file without
184
+ * function values, a `--function` of another form, `--yreverse` on a Rips
185
+ * bifiltration, a negative `--maxdist` on one and a negative distance are
186
+ * refused with a `RangeError`, as is what the builder refuses. To read the
187
+ * file's data, use {@link parseRivetInput}.
188
+ */
189
+ export function rivetPresentation(text: string, opts?: RivetPresentationOptions): Presentation {
190
+ module();
191
+ const bytes = textOf(text);
192
+ const o = options<RivetPresentationOptions>(opts, 'rivetPresentation', RIVET_PRESENTATION_KEYS);
193
+ const degree = o.degree === undefined ? 0 : int(o.degree, 'degree', 0, 254);
194
+ return call('rivetPresentation', (m) => presentationOf(m.rivetPresentationFlat(bytes, degree), degree));
195
+ }