@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.
Files changed (105) hide show
  1. package/CHANGELOG.md +106 -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 +697 -0
  7. package/dist/arrangement.d.ts +50 -0
  8. package/dist/arrangement.d.ts.map +1 -0
  9. package/dist/arrangement.js +63 -0
  10. package/dist/arrangement.js.map +1 -0
  11. package/dist/build_info.json +12 -0
  12. package/dist/check.d.ts +118 -0
  13. package/dist/check.d.ts.map +1 -0
  14. package/dist/check.js +298 -0
  15. package/dist/check.js.map +1 -0
  16. package/dist/complex.d.ts +543 -0
  17. package/dist/complex.d.ts.map +1 -0
  18. package/dist/complex.js +712 -0
  19. package/dist/complex.js.map +1 -0
  20. package/dist/diagram.d.ts +116 -0
  21. package/dist/diagram.d.ts.map +1 -0
  22. package/dist/diagram.js +238 -0
  23. package/dist/diagram.js.map +1 -0
  24. package/dist/diagram_of.d.ts +17 -0
  25. package/dist/diagram_of.d.ts.map +1 -0
  26. package/dist/diagram_of.js +40 -0
  27. package/dist/diagram_of.js.map +1 -0
  28. package/dist/experimental.d.ts +18 -0
  29. package/dist/experimental.d.ts.map +1 -0
  30. package/dist/experimental.js +16 -0
  31. package/dist/experimental.js.map +1 -0
  32. package/dist/flat.d.ts +64 -0
  33. package/dist/flat.d.ts.map +1 -0
  34. package/dist/flat.js +158 -0
  35. package/dist/flat.js.map +1 -0
  36. package/dist/index.d.ts +42 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +31 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/ladder/tda_ladder.d.ts +223 -0
  41. package/dist/ladder/tda_ladder.js +1360 -0
  42. package/dist/ladder/tda_ladder_bg.wasm +0 -0
  43. package/dist/ladder/tda_ladder_bg.wasm.d.ts +43 -0
  44. package/dist/ladder.d.ts +306 -0
  45. package/dist/ladder.d.ts.map +1 -0
  46. package/dist/ladder.js +607 -0
  47. package/dist/ladder.js.map +1 -0
  48. package/dist/load.d.ts +53 -0
  49. package/dist/load.d.ts.map +1 -0
  50. package/dist/load.js +173 -0
  51. package/dist/load.js.map +1 -0
  52. package/dist/memory.d.ts +58 -0
  53. package/dist/memory.d.ts.map +1 -0
  54. package/dist/memory.js +2 -0
  55. package/dist/memory.js.map +1 -0
  56. package/dist/persistence.d.ts +349 -0
  57. package/dist/persistence.d.ts.map +1 -0
  58. package/dist/persistence.js +478 -0
  59. package/dist/persistence.js.map +1 -0
  60. package/dist/pkg/tda_wasm.d.ts +13 -0
  61. package/dist/pkg/tda_wasm.js +2528 -0
  62. package/dist/prepared.d.ts +62 -0
  63. package/dist/prepared.d.ts.map +1 -0
  64. package/dist/prepared.js +81 -0
  65. package/dist/prepared.js.map +1 -0
  66. package/dist/rivet_input.d.ts +93 -0
  67. package/dist/rivet_input.d.ts.map +1 -0
  68. package/dist/rivet_input.js +132 -0
  69. package/dist/rivet_input.js.map +1 -0
  70. package/dist/source.d.ts +43 -0
  71. package/dist/source.d.ts.map +1 -0
  72. package/dist/source.js +99 -0
  73. package/dist/source.js.map +1 -0
  74. package/dist/tda.wasm +0 -0
  75. package/dist/two_parameter.d.ts +243 -0
  76. package/dist/two_parameter.d.ts.map +1 -0
  77. package/dist/two_parameter.js +275 -0
  78. package/dist/two_parameter.js.map +1 -0
  79. package/dist/types.d.ts +146 -0
  80. package/dist/types.d.ts.map +1 -0
  81. package/dist/types.js +2 -0
  82. package/dist/types.js.map +1 -0
  83. package/dist/vineyard.d.ts +278 -0
  84. package/dist/vineyard.d.ts.map +1 -0
  85. package/dist/vineyard.js +236 -0
  86. package/dist/vineyard.js.map +1 -0
  87. package/package.json +77 -4
  88. package/src/arrangement.ts +96 -0
  89. package/src/check.ts +338 -0
  90. package/src/complex.ts +1179 -0
  91. package/src/diagram.ts +299 -0
  92. package/src/diagram_of.ts +40 -0
  93. package/src/experimental.ts +17 -0
  94. package/src/flat.ts +204 -0
  95. package/src/index.ts +181 -0
  96. package/src/ladder.ts +903 -0
  97. package/src/load.ts +201 -0
  98. package/src/memory.ts +58 -0
  99. package/src/persistence.ts +752 -0
  100. package/src/prepared.ts +111 -0
  101. package/src/rivet_input.ts +195 -0
  102. package/src/source.ts +132 -0
  103. package/src/two_parameter.ts +480 -0
  104. package/src/types.ts +163 -0
  105. package/src/vineyard.ts +463 -0
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Persistence vineyards: the classes of a filtered complex followed through
3
+ * a homotopy of its values (internal module; the package root re-exports
4
+ * the API).
5
+ */
6
+ import { call, module } from './load.js';
7
+ import { coeff as checkCoeff, f64, int, kind, minPersistence as checkMinPersistence, nonNegative, options, points } from './check.js';
8
+ import { gridArgs } from './complex.js';
9
+ import { complexArgs } from './persistence.js';
10
+ const VINEYARD_REPRESENTATIVES_KEYS = { times: true, dims: true };
11
+ const EMPTY_F64 = new Float64Array(0);
12
+ const EMPTY_U32 = new Uint32Array(0);
13
+ /** Checks a vineyard `representatives` option against `[0, maxTime]` and `0 .. maxDim`. */
14
+ function repRequest(v, fn, maxTime, maxDim) {
15
+ if (v === undefined)
16
+ return { withReps: false, times: EMPTY_F64, filterDims: false, dims: EMPTY_U32 };
17
+ const o = options(v, fn, VINEYARD_REPRESENTATIVES_KEYS, 'representatives', 'representatives.');
18
+ const times = f64(o.times, 'representatives.times');
19
+ for (let i = 0; i < times.length; i++) {
20
+ const t = times[i];
21
+ if (!Number.isFinite(t) || t < 0 || t > maxTime) {
22
+ throw new RangeError(`representatives.times[${i}] must be between 0 and ${maxTime}, got ${t}`);
23
+ }
24
+ }
25
+ if (o.dims === undefined)
26
+ return { withReps: true, times, filterDims: false, dims: EMPTY_U32 };
27
+ if (!Array.isArray(o.dims))
28
+ throw new TypeError(`representatives.dims must be an array of integers, got ${kind(o.dims)}`);
29
+ const dims = new Uint32Array(o.dims.length);
30
+ for (let i = 0; i < o.dims.length; i++)
31
+ dims[i] = int(o.dims[i], `representatives.dims[${i}]`, 0, maxDim);
32
+ return { withReps: true, times, filterDims: true, dims };
33
+ }
34
+ const VINEYARD_KEYS = { coeff: true, minPersistence: true, representatives: true };
35
+ /**
36
+ * The persistence vineyard of a filtered simplicial complex whose values
37
+ * change: `complex.filtrations` are the values at time 0, and `frames[m]`
38
+ * (one value per simplex, in the complex's order) those at time `m + 1`.
39
+ * Between two frames every value moves on a straight line, and the result
40
+ * follows every class of the persistence diagram through that homotopy over
41
+ * `Z/coeff`.
42
+ *
43
+ * The algorithm is the linear-time transposition update ([reference](https://topolab.ai/tda/docs/references/#cohen-steiner-edelsbrunner-and-morozov-2006)): the
44
+ * matrix decomposition behind `persistence` is computed once, at time 0,
45
+ * and repaired in time linear in the number of simplices each time two
46
+ * simplices adjacent in the filtration order exchange their places, instead
47
+ * of being recomputed.
48
+ *
49
+ * The complex must be closed, and monotone at time 0 and at every frame (no
50
+ * face valued above a coface); every value must be finite. Anything else is
51
+ * a `RangeError` naming the simplex. Simplices of equal value keep their
52
+ * order, which at time 0 is the documented order of {@link Complex}: at a
53
+ * frame the vines' points with `death > birth` are the pairs of
54
+ * `persistence` of the complex with that frame's values (over the same
55
+ * `coeff`), and at any time in between those of the interpolated values.
56
+ *
57
+ * Memory bounds a vineyard before its size limits do: the decomposition
58
+ * keeps U, every column addition of the reduction at time 0 (on tied or
59
+ * evenly spread values many times the number of simplices), and
60
+ * transpositions fill it in further. A vineyard that does not fit throws
61
+ * `TOO_LARGE` (phase `'boundary matrix'`). The same holds for
62
+ * {@link cubicalVineyard} and {@link ripsVineyard}.
63
+ */
64
+ export function vineyard(complex, frames, opts) {
65
+ module();
66
+ const o = options(opts, 'vineyard', VINEYARD_KEYS);
67
+ const c = complexArgs(complex, 'complex');
68
+ const coeff = checkCoeff(o.coeff);
69
+ const minPersistence = checkMinPersistence(o.minPersistence);
70
+ if (!isList(frames)) {
71
+ throw new TypeError(`frames must be an array of value arrays (Float64Array or arrays of numbers), got ${kind(frames)}`);
72
+ }
73
+ const n = c.filtrations.length;
74
+ const count = frames.length + 1;
75
+ const rep = repRequest(o.representatives, 'vineyard', count - 1, 255);
76
+ const all = new Float64Array(n * count);
77
+ all.set(c.filtrations);
78
+ for (let m = 0; m < frames.length; m++) {
79
+ const frame = f64(frames[m], `frames[${m}]`);
80
+ if (frame.length !== n) {
81
+ throw new RangeError(`frames[${m}] must have one value per simplex (${n}), got ${frame.length}`);
82
+ }
83
+ all.set(frame, n * (m + 1));
84
+ }
85
+ return call('vineyard', (m) => vinesOf(m.vineyardFlat(c.vertices, c.offsets, all, count, minPersistence, coeff, rep.times, rep.withReps, rep.dims, rep.filterDims), c.scale, coeff));
86
+ }
87
+ /** The vines of a module result. */
88
+ function vinesOf(raw, scale, coeff) {
89
+ const out = {
90
+ dims: raw.dims,
91
+ offsets: raw.offsets,
92
+ times: raw.times,
93
+ births: raw.births,
94
+ deaths: raw.deaths,
95
+ birthSimplices: raw.birthSimplices,
96
+ deathSimplices: raw.deathSimplices,
97
+ transpositions: raw.transpositions,
98
+ switches: raw.switches,
99
+ scale,
100
+ coeff
101
+ };
102
+ if (raw.representatives !== undefined)
103
+ out.representatives = raw.representatives;
104
+ return out;
105
+ }
106
+ /** An array or array-like object (not a typed array) whose length is a non-negative integer. */
107
+ function isList(v) {
108
+ if (v === null || typeof v !== 'object' || ArrayBuffer.isView(v))
109
+ return false;
110
+ const length = v.length;
111
+ return Number.isSafeInteger(length) && length >= 0;
112
+ }
113
+ /** An array of inputs (not a typed array), at least one; returns its length. */
114
+ function frameList(v, name, plural, one) {
115
+ if (!isList(v)) {
116
+ throw new TypeError(`${name} must be an array of ${plural}, got ${kind(v)}`);
117
+ }
118
+ const count = v.length;
119
+ if (count === 0)
120
+ throw new RangeError(`${name} must hold at least one ${one}, got none`);
121
+ return count;
122
+ }
123
+ /**
124
+ * Compute the persistence vineyard of a sequence of images or volumes of the
125
+ * same shape, following the classes of the sublevel-set persistence diagram
126
+ * (T-construction, as in {@link cubicalPersistence}) across frames over
127
+ * `Z/coeff`.
128
+ *
129
+ * Each image assigns values to the cells of one shared cubical complex, the
130
+ * T-construction complex of the grid: each top-dimensional cell (pixel or
131
+ * voxel) takes its own value, and each lower-dimensional cell takes the
132
+ * minimum value among the top-dimensional cells containing it. Between
133
+ * consecutive images, each cell's value moves linearly, and the vines follow
134
+ * that homotopy using the transposition updates of {@link vineyard}. At
135
+ * image `m`, the vine points with `death > birth` are the pairs of
136
+ * `cubicalPersistence(images[m], { coeff })`. Cell values are interpolated
137
+ * between images rather than pixel values: a lower-dimensional cell takes the
138
+ * linear interpolation of its two cell values, which can lie below the
139
+ * T-construction value of the interpolated image.
140
+ *
141
+ * Every image must be a {@link Grid} with the same shape as `images[0]` and
142
+ * finite values.
143
+ */
144
+ export function cubicalVineyard(images, opts) {
145
+ module();
146
+ const o = options(opts, 'cubicalVineyard', VINEYARD_KEYS);
147
+ const coeff = checkCoeff(o.coeff);
148
+ const minPersistence = checkMinPersistence(o.minPersistence);
149
+ const count = frameList(images, 'images', 'images { values: Float64Array, shape: number[] }', 'image');
150
+ const rep = repRequest(o.representatives, 'cubicalVineyard', count - 1, 255);
151
+ const extents = gridArgs(images[0], 'images[0]');
152
+ const size = images[0].values.length;
153
+ const shape = [...images[0].shape];
154
+ const all = new Float64Array(size * count);
155
+ for (let m = 0; m < count; m++) {
156
+ const image = images[m];
157
+ if (m > 0) {
158
+ gridArgs(image, `images[${m}]`);
159
+ const other = image.shape;
160
+ if (other.length !== shape.length || other.some((x, i) => x !== shape[i])) {
161
+ throw new RangeError(`images[${m}].shape must be the shape of images[0] ([${shape.join(', ')}]), got [${other.join(', ')}]`);
162
+ }
163
+ }
164
+ all.set(image.values, size * m);
165
+ }
166
+ return call('cubicalVineyard', (m) => {
167
+ const raw = m.cubicalVineyardFlat(extents, all, count, minPersistence, coeff, rep.times, rep.withReps, rep.dims, rep.filterDims);
168
+ const { birthSimplices, deathSimplices, ...rest } = vinesOf(raw, 'value', coeff);
169
+ return { ...rest, birthCells: birthSimplices, deathCells: deathSimplices, shape, scale: 'value' };
170
+ });
171
+ }
172
+ const RIPS_VINEYARD_KEYS = {
173
+ maxDim: true,
174
+ maxEdgeLength: true,
175
+ coeff: true,
176
+ minPersistence: true,
177
+ representatives: true
178
+ };
179
+ /**
180
+ * Compute the persistence vineyard of a moving point cloud, following the
181
+ * classes of the Vietoris–Rips persistence diagram across frames over
182
+ * `Z/coeff`. `clouds[m]` holds the same points in the same order at time `m`.
183
+ *
184
+ * One shared complex serves all clouds: every simplex up to dimension
185
+ * `maxDim + 1` whose edges each have length at most `maxEdgeLength` in at
186
+ * least one cloud (all such simplices by default). Cloud `m` assigns each
187
+ * simplex the length of its longest edge there, as {@link ripsComplex} does,
188
+ * and between consecutive clouds each simplex's value moves linearly; the
189
+ * vines follow that homotopy using the transposition updates of
190
+ * {@link vineyard}. Simplex values are interpolated rather than point
191
+ * coordinates: between two clouds, a simplex takes the linear interpolation
192
+ * of its two lengths, not its length in the interpolated cloud.
193
+ *
194
+ * At cloud `m`, the vine points with `death > birth` are the pairs of
195
+ * `ripsPersistence(clouds[m], { maxDim, coeff })`. With a finite
196
+ * `maxEdgeLength`, every vine is exact while `death` is below
197
+ * `maxEdgeLength`: at each cloud and at every time between consecutive
198
+ * clouds, the complex contains every simplex of value at most
199
+ * `maxEdgeLength` at its exact value. A death at or above `maxEdgeLength`
200
+ * indicates only that the class persists until at least `maxEdgeLength`.
201
+ *
202
+ * Every cloud must have the same number of points and `d` as `clouds[0]`,
203
+ * with finite coordinates.
204
+ */
205
+ export function ripsVineyard(clouds, opts) {
206
+ module();
207
+ const o = options(opts, 'ripsVineyard', RIPS_VINEYARD_KEYS);
208
+ const maxDim = o.maxDim === undefined ? 1 : int(o.maxDim, 'maxDim', 0, 9);
209
+ const maxEdgeLength = o.maxEdgeLength === undefined ? Infinity : nonNegative(o.maxEdgeLength, 'maxEdgeLength');
210
+ const coeff = checkCoeff(o.coeff);
211
+ const minPersistence = checkMinPersistence(o.minPersistence);
212
+ const count = frameList(clouds, 'clouds', 'point clouds { coords: Float64Array, d: number }', 'point cloud');
213
+ const rep = repRequest(o.representatives, 'ripsVineyard', count - 1, maxDim);
214
+ const n = points(clouds[0], 'clouds[0]', { squaredDistances: true });
215
+ const d = clouds[0].d;
216
+ const size = clouds[0].coords.length;
217
+ const all = new Float64Array(size * count);
218
+ for (let m = 0; m < count; m++) {
219
+ const c = clouds[m];
220
+ if (m > 0) {
221
+ const k = points(c, `clouds[${m}]`, { squaredDistances: true });
222
+ if (c.d !== d || k !== n) {
223
+ throw new RangeError(`clouds[${m}] must have the ${n} points of ${d} coordinates of clouds[0], got ${k} points of ${c.d}`);
224
+ }
225
+ }
226
+ all.set(c.coords, size * m);
227
+ }
228
+ return call('ripsVineyard', (m) => {
229
+ const raw = m.ripsVineyardFlat(all, d, count, maxEdgeLength, maxDim, minPersistence, coeff, rep.times, rep.withReps, rep.dims, rep.filterDims);
230
+ return {
231
+ ...vinesOf(raw, 'edgeLength', coeff),
232
+ complex: { vertices: raw.vertices, offsets: raw.complexOffsets, filtrations: raw.filtrations, scale: 'edgeLength' }
233
+ };
234
+ });
235
+ }
236
+ //# sourceMappingURL=vineyard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vineyard.js","sourceRoot":"","sources":["../src/vineyard.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,IAAI,mBAAmB,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEtI,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAqB/C,MAAM,6BAA6B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,MAAM,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACV,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;YAChE,IAAI,CAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,mBAAmB,CAAC,cAAc,CAAC,kCAAkC,CAAC,cAAc,CAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YAC9H,CAAC;QACH,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,CAAE,CAAC,MAAM,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;QAChC,MAAM,GAAG,GAAG,CAAC,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;QAC/I,OAAO;YACL,GAAG,OAAO,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,CAAC;YACpC,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,cAAc,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,KAAK,EAAE,YAAqB,EAAE;SAC7H,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,79 @@
1
1
  {
2
2
  "name": "@topolab/tda",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.0",
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
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./ladder": {
14
+ "types": "./dist/ladder.d.ts",
15
+ "import": "./dist/ladder.js",
16
+ "default": "./dist/ladder.js"
17
+ },
18
+ "./experimental": {
19
+ "types": "./dist/experimental.d.ts",
20
+ "import": "./dist/experimental.js",
21
+ "default": "./dist/experimental.js"
22
+ },
23
+ "./tda.wasm": "./dist/tda.wasm",
24
+ "./ladder.wasm": "./dist/ladder/tda_ladder_bg.wasm",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "type": "module",
28
+ "keywords": [
29
+ "topological-data-analysis",
30
+ "tda",
31
+ "persistent-homology",
32
+ "persistence-diagrams",
33
+ "alpha-complex",
34
+ "vietoris-rips",
35
+ "cech-complex",
36
+ "ellipsoid-cech-complex",
37
+ "wing-complex",
38
+ "cubical-complex",
39
+ "bottleneck-distance",
40
+ "wasserstein-distance",
41
+ "optimal-transport",
42
+ "betti-numbers",
43
+ "persistence-landscapes",
44
+ "persistence-images",
45
+ "webassembly",
46
+ "wasm",
47
+ "computational-topology",
48
+ "computational-geometry",
49
+ "typescript",
50
+ "commutative-ladder",
51
+ "multiparameter-persistence",
52
+ "zigzag-persistence",
53
+ "vineyards",
54
+ "interval-approximation"
55
+ ],
56
+ "author": "topolab <dev@topolab.ai>",
57
+ "license": "MIT",
58
+ "bugs": {
59
+ "url": "https://topolab.ai/contact/"
60
+ },
61
+ "homepage": "https://topolab.ai/tda/docs/",
62
+ "sideEffects": false,
63
+ "engines": {
64
+ "node": ">=22"
65
+ },
66
+ "files": [
67
+ "dist/",
68
+ "src/",
69
+ "README.md",
70
+ "CHANGELOG.md",
71
+ "LICENSE",
72
+ "THIRD_PARTY_LICENSES.md",
73
+ "SECURITY.md",
74
+ "CITATION.cff"
75
+ ],
76
+ "publishConfig": {
77
+ "access": "public"
78
+ }
79
+ }
@@ -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
+ }