multipers 2.2.3__cp311-cp311-win_amd64.whl → 2.3.1__cp311-cp311-win_amd64.whl
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.
Potentially problematic release.
This version of multipers might be problematic. Click here for more details.
- multipers/__init__.py +33 -31
- multipers/_signed_measure_meta.py +430 -430
- multipers/_slicer_meta.py +211 -212
- multipers/data/MOL2.py +458 -458
- multipers/data/UCR.py +18 -18
- multipers/data/graphs.py +466 -466
- multipers/data/immuno_regions.py +27 -27
- multipers/data/pytorch2simplextree.py +90 -90
- multipers/data/shape3d.py +101 -101
- multipers/data/synthetic.py +113 -111
- multipers/distances.py +198 -198
- multipers/filtration_conversions.pxd.tp +84 -84
- multipers/filtrations/__init__.py +18 -0
- multipers/{ml/convolutions.py → filtrations/density.py} +563 -520
- multipers/filtrations/filtrations.py +289 -0
- multipers/filtrations.pxd +224 -224
- multipers/function_rips.cp311-win_amd64.pyd +0 -0
- multipers/function_rips.pyx +105 -105
- multipers/grids.cp311-win_amd64.pyd +0 -0
- multipers/grids.pyx +350 -350
- multipers/gudhi/Persistence_slices_interface.h +132 -132
- multipers/gudhi/Simplex_tree_interface.h +239 -245
- multipers/gudhi/Simplex_tree_multi_interface.h +516 -561
- multipers/gudhi/cubical_to_boundary.h +59 -59
- multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -450
- multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -1070
- multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -579
- multipers/gudhi/gudhi/Debug_utils.h +45 -45
- multipers/gudhi/gudhi/Fields/Multi_field.h +484 -484
- multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -455
- multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -450
- multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -531
- multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -507
- multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -531
- multipers/gudhi/gudhi/Fields/Z2_field.h +355 -355
- multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -376
- multipers/gudhi/gudhi/Fields/Zp_field.h +420 -420
- multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -400
- multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -418
- multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -337
- multipers/gudhi/gudhi/Matrix.h +2107 -2107
- multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -1038
- multipers/gudhi/gudhi/Multi_persistence/Box.h +171 -171
- multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -282
- multipers/gudhi/gudhi/Off_reader.h +173 -173
- multipers/gudhi/gudhi/One_critical_filtration.h +1433 -1431
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -769
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -686
- multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -842
- multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -1350
- multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -1105
- multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -859
- multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -910
- multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -139
- multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -230
- multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -211
- multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -60
- multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -60
- multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -136
- multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -190
- multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -616
- multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -150
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -106
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -219
- multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -327
- multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -1140
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -934
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -934
- multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -980
- multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -1092
- multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -192
- multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -921
- multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -1093
- multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -1012
- multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -1244
- multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -186
- multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -164
- multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -156
- multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -376
- multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -540
- multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -118
- multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -173
- multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -128
- multipers/gudhi/gudhi/Persistent_cohomology.h +745 -745
- multipers/gudhi/gudhi/Points_off_io.h +171 -171
- multipers/gudhi/gudhi/Simple_object_pool.h +69 -69
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -463
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -83
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -106
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -277
- multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -62
- multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -27
- multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -62
- multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -157
- multipers/gudhi/gudhi/Simplex_tree.h +2794 -2794
- multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -163
- multipers/gudhi/gudhi/distance_functions.h +62 -62
- multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -104
- multipers/gudhi/gudhi/persistence_interval.h +253 -253
- multipers/gudhi/gudhi/persistence_matrix_options.h +170 -170
- multipers/gudhi/gudhi/reader_utils.h +367 -367
- multipers/gudhi/mma_interface_coh.h +256 -255
- multipers/gudhi/mma_interface_h0.h +223 -231
- multipers/gudhi/mma_interface_matrix.h +291 -282
- multipers/gudhi/naive_merge_tree.h +536 -575
- multipers/gudhi/scc_io.h +310 -289
- multipers/gudhi/truc.h +957 -888
- multipers/io.cp311-win_amd64.pyd +0 -0
- multipers/io.pyx +714 -711
- multipers/ml/accuracies.py +90 -90
- multipers/ml/invariants_with_persistable.py +79 -79
- multipers/ml/kernels.py +176 -176
- multipers/ml/mma.py +713 -714
- multipers/ml/one.py +472 -472
- multipers/ml/point_clouds.py +352 -346
- multipers/ml/signed_measures.py +1589 -1589
- multipers/ml/sliced_wasserstein.py +461 -461
- multipers/ml/tools.py +113 -113
- multipers/mma_structures.cp311-win_amd64.pyd +0 -0
- multipers/mma_structures.pxd +127 -127
- multipers/mma_structures.pyx +4 -8
- multipers/mma_structures.pyx.tp +1083 -1085
- multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -93
- multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -97
- multipers/multi_parameter_rank_invariant/function_rips.h +322 -322
- multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -769
- multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -148
- multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -369
- multipers/multiparameter_edge_collapse.py +41 -41
- multipers/multiparameter_module_approximation/approximation.h +2298 -2295
- multipers/multiparameter_module_approximation/combinatory.h +129 -129
- multipers/multiparameter_module_approximation/debug.h +107 -107
- multipers/multiparameter_module_approximation/format_python-cpp.h +286 -286
- multipers/multiparameter_module_approximation/heap_column.h +238 -238
- multipers/multiparameter_module_approximation/images.h +79 -79
- multipers/multiparameter_module_approximation/list_column.h +174 -174
- multipers/multiparameter_module_approximation/list_column_2.h +232 -232
- multipers/multiparameter_module_approximation/ru_matrix.h +347 -347
- multipers/multiparameter_module_approximation/set_column.h +135 -135
- multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -36
- multipers/multiparameter_module_approximation/unordered_set_column.h +166 -166
- multipers/multiparameter_module_approximation/utilities.h +403 -419
- multipers/multiparameter_module_approximation/vector_column.h +223 -223
- multipers/multiparameter_module_approximation/vector_matrix.h +331 -331
- multipers/multiparameter_module_approximation/vineyards.h +464 -464
- multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -649
- multipers/multiparameter_module_approximation.cp311-win_amd64.pyd +0 -0
- multipers/multiparameter_module_approximation.pyx +218 -217
- multipers/pickle.py +90 -53
- multipers/plots.py +342 -334
- multipers/point_measure.cp311-win_amd64.pyd +0 -0
- multipers/point_measure.pyx +322 -320
- multipers/simplex_tree_multi.cp311-win_amd64.pyd +0 -0
- multipers/simplex_tree_multi.pxd +133 -133
- multipers/simplex_tree_multi.pyx +115 -48
- multipers/simplex_tree_multi.pyx.tp +1947 -1935
- multipers/slicer.cp311-win_amd64.pyd +0 -0
- multipers/slicer.pxd +301 -120
- multipers/slicer.pxd.tp +218 -214
- multipers/slicer.pyx +1570 -507
- multipers/slicer.pyx.tp +931 -914
- multipers/tensor/tensor.h +672 -672
- multipers/tensor.pxd +13 -13
- multipers/test.pyx +44 -44
- multipers/tests/__init__.py +57 -57
- multipers/torch/diff_grids.py +217 -217
- multipers/torch/rips_density.py +310 -304
- {multipers-2.2.3.dist-info → multipers-2.3.1.dist-info}/LICENSE +21 -21
- {multipers-2.2.3.dist-info → multipers-2.3.1.dist-info}/METADATA +21 -11
- multipers-2.3.1.dist-info/RECORD +182 -0
- {multipers-2.2.3.dist-info → multipers-2.3.1.dist-info}/WHEEL +1 -1
- multipers/tests/test_diff_helper.py +0 -73
- multipers/tests/test_hilbert_function.py +0 -82
- multipers/tests/test_mma.py +0 -83
- multipers/tests/test_point_clouds.py +0 -49
- multipers/tests/test_python-cpp_conversion.py +0 -82
- multipers/tests/test_signed_betti.py +0 -181
- multipers/tests/test_signed_measure.py +0 -89
- multipers/tests/test_simplextreemulti.py +0 -221
- multipers/tests/test_slicer.py +0 -221
- multipers-2.2.3.dist-info/RECORD +0 -189
- {multipers-2.2.3.dist-info → multipers-2.3.1.dist-info}/top_level.txt +0 -0
multipers/gudhi/truc.h
CHANGED
|
@@ -1,888 +1,957 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
#include "gudhi/Multi_persistence/Line.h"
|
|
3
|
-
#include "multiparameter_module_approximation/format_python-cpp.h"
|
|
4
|
-
#include <gudhi/One_critical_filtration.h>
|
|
5
|
-
#include <gudhi/Multi_critical_filtration.h>
|
|
6
|
-
#include <algorithm>
|
|
7
|
-
#include <boost/mpl/aux_/na_fwd.hpp>
|
|
8
|
-
#include <cassert>
|
|
9
|
-
#include <
|
|
10
|
-
#include <
|
|
11
|
-
|
|
12
|
-
#include <
|
|
13
|
-
#include <
|
|
14
|
-
#include <
|
|
15
|
-
#include <
|
|
16
|
-
#include <oneapi/tbb/
|
|
17
|
-
#include <oneapi/tbb/
|
|
18
|
-
#include <
|
|
19
|
-
#include <
|
|
20
|
-
#include <
|
|
21
|
-
#include <
|
|
22
|
-
#include <
|
|
23
|
-
#include
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
namespace
|
|
27
|
-
namespace
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/*
|
|
55
|
-
/*
|
|
56
|
-
/*
|
|
57
|
-
/*
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
stream << "
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
stream << "
|
|
85
|
-
stream << "
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
stream << "
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
std::vector<
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
inline
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
stream <<
|
|
175
|
-
for (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
inline
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
template <
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
template <
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
inline void
|
|
381
|
-
this->
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
inline
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
if (
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if (
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
return out;
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
return
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
inline
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
inline
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
inline
|
|
783
|
-
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
this->
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
};
|
|
887
|
-
|
|
888
|
-
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "gudhi/Multi_persistence/Line.h"
|
|
3
|
+
#include "multiparameter_module_approximation/format_python-cpp.h"
|
|
4
|
+
#include <gudhi/One_critical_filtration.h>
|
|
5
|
+
#include <gudhi/Multi_critical_filtration.h>
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
#include <boost/mpl/aux_/na_fwd.hpp>
|
|
8
|
+
#include <cassert>
|
|
9
|
+
#include <csignal>
|
|
10
|
+
#include <cstddef>
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
// #include <gudhi/Simplex_tree/multi_filtrations/Finitely_critical_filtrations.h>
|
|
13
|
+
#include <iostream>
|
|
14
|
+
#include <limits>
|
|
15
|
+
#include <numeric>
|
|
16
|
+
#include <oneapi/tbb/enumerable_thread_specific.h>
|
|
17
|
+
#include <oneapi/tbb/parallel_for.h>
|
|
18
|
+
#include <oneapi/tbb/task_group.h>
|
|
19
|
+
#include <sstream>
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <utility>
|
|
22
|
+
#include <vector>
|
|
23
|
+
#include <type_traits> //std::invoke_result
|
|
24
|
+
#include "scc_io.h"
|
|
25
|
+
|
|
26
|
+
namespace Gudhi {
|
|
27
|
+
namespace multiparameter {
|
|
28
|
+
namespace truc_interface {
|
|
29
|
+
using index_type = std::uint32_t;
|
|
30
|
+
|
|
31
|
+
class PresentationStructure {
|
|
32
|
+
public:
|
|
33
|
+
PresentationStructure() {}
|
|
34
|
+
|
|
35
|
+
/* SimplicialStructure &operator=(const SimplicialStructure &) = default; */
|
|
36
|
+
|
|
37
|
+
PresentationStructure(const std::vector<std::vector<index_type>> &generators,
|
|
38
|
+
const std::vector<int> &generator_dimensions)
|
|
39
|
+
: generators(generators), generator_dimensions(generator_dimensions), num_vertices_(0) {
|
|
40
|
+
for (const auto &stuff : generator_dimensions) {
|
|
41
|
+
if (stuff == 0) num_vertices_++;
|
|
42
|
+
}
|
|
43
|
+
max_dimension_ = generator_dimensions.size() > 0
|
|
44
|
+
? *std::max_element(generator_dimensions.begin(), generator_dimensions.end())
|
|
45
|
+
: 0;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
PresentationStructure(const PresentationStructure &other)
|
|
49
|
+
: generators(other.generators),
|
|
50
|
+
generator_dimensions(other.generator_dimensions),
|
|
51
|
+
num_vertices_(other.num_vertices_),
|
|
52
|
+
max_dimension_(other.max_dimension_) {}
|
|
53
|
+
|
|
54
|
+
/* PresentationStructure &operator=(const PresentationStructure &other) { */
|
|
55
|
+
/* generators = other.generators; */
|
|
56
|
+
/* generator_dimensions = other.generator_dimensions; */
|
|
57
|
+
/* num_vertices_ = other.num_vertices_; */
|
|
58
|
+
/* max_dimension_ = other.max_dimension_; */
|
|
59
|
+
/**/
|
|
60
|
+
/* return *this; */
|
|
61
|
+
/* } */
|
|
62
|
+
|
|
63
|
+
const std::vector<unsigned int> &operator[](std::size_t i) const {
|
|
64
|
+
return generators[i];
|
|
65
|
+
} // needs to be iterable (begin, end, size)
|
|
66
|
+
|
|
67
|
+
std::vector<unsigned int> &operator[](std::size_t i) {
|
|
68
|
+
return generators[i];
|
|
69
|
+
} // needs to be iterable (begin, end, size)
|
|
70
|
+
|
|
71
|
+
inline int dimension(std::size_t i) const { return generator_dimensions[i]; };
|
|
72
|
+
|
|
73
|
+
inline friend std::ostream &operator<<(std::ostream &stream, const PresentationStructure &structure) {
|
|
74
|
+
stream << "Boundary:\n";
|
|
75
|
+
stream << "{";
|
|
76
|
+
for (const auto &stuff : structure.generators) {
|
|
77
|
+
stream << "{";
|
|
78
|
+
for (auto truc : stuff) stream << truc << ", ";
|
|
79
|
+
|
|
80
|
+
if (!stuff.empty()) stream << "\b" << "\b ";
|
|
81
|
+
|
|
82
|
+
stream << "},\n";
|
|
83
|
+
}
|
|
84
|
+
stream << "}\n";
|
|
85
|
+
stream << "Degrees: (max " << structure.max_dimension() << ")\n";
|
|
86
|
+
stream << "{";
|
|
87
|
+
for (const auto &stuff : structure.generator_dimensions) stream << stuff << ", ";
|
|
88
|
+
if (structure.size() > 0) {
|
|
89
|
+
stream << "\b" << "\b";
|
|
90
|
+
}
|
|
91
|
+
stream << "}\n";
|
|
92
|
+
return stream;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
inline void to_stream(std::ostream &stream, const std::vector<index_type> &order) {
|
|
96
|
+
for (const auto &i : order) {
|
|
97
|
+
const auto &stuff = this->operator[](i);
|
|
98
|
+
stream << i << " : [";
|
|
99
|
+
for (const auto &truc : stuff) stream << truc << ", ";
|
|
100
|
+
stream << "]\n";
|
|
101
|
+
}
|
|
102
|
+
/* return stream; */
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
inline std::size_t size() const { return generators.size(); };
|
|
106
|
+
|
|
107
|
+
unsigned int num_vertices() const { return num_vertices_; };
|
|
108
|
+
|
|
109
|
+
unsigned int max_dimension() const { return max_dimension_; }
|
|
110
|
+
|
|
111
|
+
int prune_above_dimension(int dim) {
|
|
112
|
+
int idx = std::lower_bound(generator_dimensions.begin(), generator_dimensions.end(), dim + 1) -
|
|
113
|
+
generator_dimensions.begin();
|
|
114
|
+
generators.resize(idx);
|
|
115
|
+
generator_dimensions.resize(idx);
|
|
116
|
+
max_dimension_ = generator_dimensions.size() ? generator_dimensions.back() : -1;
|
|
117
|
+
return idx;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
PresentationStructure permute(const std::vector<index_type> &order) const {
|
|
121
|
+
std::vector<std::vector<index_type>> new_generators(generators.size());
|
|
122
|
+
std::vector<int> new_generator_dimensions(generator_dimensions.size());
|
|
123
|
+
for (std::size_t i = 0; i < order.size(); i++) {
|
|
124
|
+
new_generators[i] = std::vector<index_type>(generators[order[i]].size());
|
|
125
|
+
for (std::size_t j = 0; j < generators[order[i]].size(); j++) {
|
|
126
|
+
new_generators[i][j] = order[generators[order[i]][j]];
|
|
127
|
+
}
|
|
128
|
+
new_generator_dimensions[i] = generator_dimensions[order[i]];
|
|
129
|
+
}
|
|
130
|
+
return PresentationStructure(new_generators, new_generator_dimensions);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private:
|
|
134
|
+
std::vector<std::vector<index_type>> generators;
|
|
135
|
+
std::vector<int> generator_dimensions;
|
|
136
|
+
unsigned int num_vertices_;
|
|
137
|
+
int max_dimension_ = -1;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
class SimplicialStructure {
|
|
141
|
+
public:
|
|
142
|
+
template <typename SimplexTree>
|
|
143
|
+
void from_simplextree(SimplexTree &st) {
|
|
144
|
+
auto [filtration, boundary] = Gudhi::multiparameter::mma::simplextree_to_ordered_bf(st);
|
|
145
|
+
this->boundaries = boundary;
|
|
146
|
+
this->num_vertices_ = st.num_vertices();
|
|
147
|
+
this->max_dimension_ = st.dimension();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
SimplicialStructure() {}
|
|
151
|
+
|
|
152
|
+
/* SimplicialStructure &operator=(const SimplicialStructure &) = default; */
|
|
153
|
+
|
|
154
|
+
SimplicialStructure(const std::vector<std::vector<index_type>> &boundaries,
|
|
155
|
+
unsigned int num_vertices,
|
|
156
|
+
unsigned int max_dimension)
|
|
157
|
+
: boundaries(boundaries), num_vertices_(num_vertices), max_dimension_(max_dimension) {
|
|
158
|
+
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const std::vector<unsigned int> &operator[](std::size_t i) const {
|
|
162
|
+
return boundaries[i];
|
|
163
|
+
} // needs to be iterable (begin, end, size)
|
|
164
|
+
|
|
165
|
+
std::vector<unsigned int> &operator[](std::size_t i) {
|
|
166
|
+
return boundaries[i];
|
|
167
|
+
} // needs to be iterable (begin, end, size)
|
|
168
|
+
|
|
169
|
+
int dimension(std::size_t i) const { return boundaries[i].size() == 0 ? 0 : boundaries[i].size() - 1; };
|
|
170
|
+
|
|
171
|
+
inline friend std::ostream &operator<<(std::ostream &stream, const SimplicialStructure &structure) {
|
|
172
|
+
stream << "{";
|
|
173
|
+
for (const auto &stuff : structure.boundaries) {
|
|
174
|
+
stream << "{";
|
|
175
|
+
for (auto truc : stuff) stream << truc << ", ";
|
|
176
|
+
|
|
177
|
+
if (!stuff.empty()) stream << "\b" << "\b ";
|
|
178
|
+
|
|
179
|
+
stream << "},\n";
|
|
180
|
+
}
|
|
181
|
+
stream << "}\n";
|
|
182
|
+
return stream;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
inline void to_stream(std::ostream &stream, const std::vector<index_type> &order) {
|
|
186
|
+
for (const auto &i : order) {
|
|
187
|
+
const auto &stuff = this->operator[](i);
|
|
188
|
+
stream << i << " : [";
|
|
189
|
+
for (const auto &truc : stuff) stream << truc << ", ";
|
|
190
|
+
stream << "]\n";
|
|
191
|
+
}
|
|
192
|
+
/* return stream; */
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
inline std::size_t size() const { return boundaries.size(); };
|
|
196
|
+
|
|
197
|
+
inline unsigned int num_vertices() const { return num_vertices_; }
|
|
198
|
+
|
|
199
|
+
inline unsigned int max_dimension() const { return max_dimension_; }
|
|
200
|
+
|
|
201
|
+
int prune_above_dimension([[maybe_unused]] int dim) { throw "Not implemented"; }
|
|
202
|
+
|
|
203
|
+
private:
|
|
204
|
+
std::vector<std::vector<index_type>> boundaries;
|
|
205
|
+
unsigned int num_vertices_;
|
|
206
|
+
unsigned int max_dimension_;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
template <class PersBackend, class Structure, class MultiFiltration>
|
|
210
|
+
class Truc {
|
|
211
|
+
public:
|
|
212
|
+
using Filtration_value = MultiFiltration;
|
|
213
|
+
using value_type = typename MultiFiltration::value_type;
|
|
214
|
+
using split_barcode =
|
|
215
|
+
std::vector<std::vector<std::pair<typename MultiFiltration::value_type, typename MultiFiltration::value_type>>>;
|
|
216
|
+
template <typename value_type = value_type>
|
|
217
|
+
using flat_barcode = std::vector<std::pair<int, std::pair<value_type, value_type>>>;
|
|
218
|
+
|
|
219
|
+
template <typename value_type = value_type>
|
|
220
|
+
using flat_nodim_barcode = std::vector<std::pair<value_type, value_type>>;
|
|
221
|
+
|
|
222
|
+
// CONSTRUCTORS.
|
|
223
|
+
// - Need everything of the same size, generator order is a PERMUTATION
|
|
224
|
+
//
|
|
225
|
+
Truc(const Structure &structure, const std::vector<MultiFiltration> &generator_filtration_values)
|
|
226
|
+
: generator_filtration_values(generator_filtration_values),
|
|
227
|
+
generator_order(structure.size()),
|
|
228
|
+
structure(structure),
|
|
229
|
+
filtration_container(structure.size()) {
|
|
230
|
+
std::iota(generator_order.begin(), generator_order.end(), 0); // range
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
template <class SimplexTree>
|
|
234
|
+
Truc(SimplexTree *simplextree) {
|
|
235
|
+
auto [filtration, boundary] = mma::simplextree_to_ordered_bf(*simplextree);
|
|
236
|
+
structure = SimplicialStructure(boundary, (*simplextree).num_vertices(), (*simplextree).dimension());
|
|
237
|
+
generator_filtration_values.resize(filtration.size());
|
|
238
|
+
for (auto i = 0u; i < filtration.size(); i++)
|
|
239
|
+
generator_filtration_values[i] = filtration[i]; // there is a copy here. TODO : deal with it.
|
|
240
|
+
generator_order = std::vector<index_type>(structure.size());
|
|
241
|
+
std::iota(generator_order.begin(), generator_order.end(), 0); // range
|
|
242
|
+
filtration_container.resize(structure.size());
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
Truc(const std::vector<std::vector<index_type>> &generator_maps,
|
|
246
|
+
const std::vector<int> &generator_dimensions,
|
|
247
|
+
const std::vector<MultiFiltration> &generator_filtrations)
|
|
248
|
+
: generator_filtration_values(generator_filtrations),
|
|
249
|
+
generator_order(generator_filtrations.size(), 0),
|
|
250
|
+
structure(PresentationStructure(generator_maps, generator_dimensions)),
|
|
251
|
+
filtration_container(generator_filtrations.size()) {
|
|
252
|
+
std::iota(generator_order.begin(), generator_order.end(), 0); // range
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
Truc(const Truc &other)
|
|
256
|
+
: generator_filtration_values(other.generator_filtration_values),
|
|
257
|
+
generator_order(other.generator_order),
|
|
258
|
+
structure(other.structure),
|
|
259
|
+
filtration_container(other.filtration_container),
|
|
260
|
+
persistence(other.persistence) {
|
|
261
|
+
persistence._update_permutation_ptr(generator_order);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
Truc &operator=(Truc other) {
|
|
265
|
+
if (this != &other) {
|
|
266
|
+
generator_filtration_values = other.generator_filtration_values;
|
|
267
|
+
generator_order = other.generator_order;
|
|
268
|
+
structure = other.structure;
|
|
269
|
+
filtration_container = other.filtration_container;
|
|
270
|
+
persistence = other.persistence;
|
|
271
|
+
persistence._update_permutation_ptr(generator_order);
|
|
272
|
+
}
|
|
273
|
+
return *this;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
Truc() {};
|
|
277
|
+
|
|
278
|
+
inline bool dimension_order(const index_type &i, const index_type &j) const {
|
|
279
|
+
return structure.dimension(i) < structure.dimension(j);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
inline bool colexical_order(const index_type &i, const index_type &j) const {
|
|
283
|
+
if (structure.dimension(i) > structure.dimension(j)) return false;
|
|
284
|
+
if (structure.dimension(i) < structure.dimension(j)) return true;
|
|
285
|
+
if constexpr (MultiFiltration::is_multicritical()) // TODO : this may not be the best
|
|
286
|
+
throw "Not implemented in the multicritical case";
|
|
287
|
+
|
|
288
|
+
for (int idx = generator_filtration_values[i].num_parameters() - 1; idx >= 0; --idx) {
|
|
289
|
+
if (generator_filtration_values[i][idx] < generator_filtration_values[j][idx])
|
|
290
|
+
return true;
|
|
291
|
+
else if (generator_filtration_values[i][idx] > generator_filtration_values[j][idx])
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
template <class Fun>
|
|
299
|
+
inline Truc rearange_sort(const Fun&& fun) const {
|
|
300
|
+
std::vector<index_type> permutation(generator_order.size());
|
|
301
|
+
std::iota(permutation.begin(), permutation.end(), 0);
|
|
302
|
+
std::sort(permutation.begin(), permutation.end(), [&](std::size_t i, std::size_t j) {
|
|
303
|
+
return fun(i, j);
|
|
304
|
+
});
|
|
305
|
+
std::vector<MultiFiltration> new_filtration(generator_filtration_values.size());
|
|
306
|
+
for (std::size_t i = 0; i < generator_filtration_values.size(); i++) {
|
|
307
|
+
new_filtration[i] = generator_filtration_values[permutation[i]];
|
|
308
|
+
}
|
|
309
|
+
return Truc(structure.permute(permutation), new_filtration);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
Truc colexical_rearange() const {
|
|
313
|
+
return rearange_sort([this](std::size_t i, std::size_t j) { return this->colexical_order(i, j); });
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
template <bool ignore_inf>
|
|
317
|
+
std::vector<std::pair<int, std::vector<index_type>>> get_current_boundary_matrix() {
|
|
318
|
+
std::vector<index_type> permutation(generator_order.size());
|
|
319
|
+
std::iota(permutation.begin(), permutation.end(), 0);
|
|
320
|
+
if constexpr (ignore_inf) {
|
|
321
|
+
permutation.erase(std::remove_if(permutation.begin(),
|
|
322
|
+
permutation.end(),
|
|
323
|
+
[&](std::size_t val) {
|
|
324
|
+
return filtration_container[val] == MultiFiltration::Generator::T_inf;
|
|
325
|
+
}),
|
|
326
|
+
permutation.end());
|
|
327
|
+
std::sort(permutation.begin(), permutation.end());
|
|
328
|
+
}
|
|
329
|
+
std::sort(permutation.begin(), permutation.end(), [&](std::size_t i, std::size_t j) {
|
|
330
|
+
if (structure.dimension(i) > structure.dimension(j)) return false;
|
|
331
|
+
if (structure.dimension(i) < structure.dimension(j)) return true;
|
|
332
|
+
return filtration_container[i] < filtration_container[j];
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
std::vector<std::pair<int, std::vector<index_type>>> matrix(permutation.size());
|
|
336
|
+
|
|
337
|
+
std::vector<index_type> permutationInv(generator_order.size());
|
|
338
|
+
std::size_t newPos = 0;
|
|
339
|
+
for (std::size_t oldPos : permutation) {
|
|
340
|
+
permutationInv[oldPos] = newPos;
|
|
341
|
+
auto &boundary = matrix[newPos].second;
|
|
342
|
+
boundary.resize(structure[oldPos].size());
|
|
343
|
+
for (std::size_t j = 0; j < structure[oldPos].size(); ++j) {
|
|
344
|
+
boundary[j] = permutationInv[structure[oldPos][j]];
|
|
345
|
+
}
|
|
346
|
+
std::sort(boundary.begin(), boundary.end());
|
|
347
|
+
matrix[newPos].first = structure.dimension(oldPos);
|
|
348
|
+
++newPos;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return matrix;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
inline std::size_t num_generators() const { return structure.size(); }
|
|
355
|
+
|
|
356
|
+
inline std::size_t num_parameters() const {
|
|
357
|
+
return num_generators() == 0 ? 0 : this->generator_filtration_values[0].num_parameters();
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
inline const Structure &get_structure() const { return structure; }
|
|
361
|
+
|
|
362
|
+
template <class SubFiltration, bool original_order = true>
|
|
363
|
+
inline void push_to_out(const SubFiltration &f,
|
|
364
|
+
std::vector<typename MultiFiltration::value_type> &filtration_container,
|
|
365
|
+
const std::vector<index_type> &generator_order) const {
|
|
366
|
+
/* std::vector<NewFilrationType> out(this->num_generators()); */
|
|
367
|
+
|
|
368
|
+
// filtration_container.resize(
|
|
369
|
+
// this->num_generators()); // for some reasons it is necessary FIXME
|
|
370
|
+
for (std::size_t i = 0u; i < this->num_generators(); i++) {
|
|
371
|
+
if constexpr (original_order) {
|
|
372
|
+
filtration_container[i] = f.compute_forward_intersection(generator_filtration_values[i]);
|
|
373
|
+
} else {
|
|
374
|
+
filtration_container[i] = f.compute_forward_intersection(generator_filtration_values[generator_order[i]]);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
template <class SubFiltration, bool original_order = true>
|
|
380
|
+
inline void push_to(const SubFiltration &f) {
|
|
381
|
+
this->push_to_out<SubFiltration, original_order>(f, this->filtration_container, this->generator_order);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
template <class array1d>
|
|
385
|
+
inline void set_one_filtration(const array1d &truc) {
|
|
386
|
+
assert(truc.size() == this->num_generators());
|
|
387
|
+
this->filtration_container = truc;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
inline const std::vector<typename MultiFiltration::value_type> &get_one_filtration() const {
|
|
391
|
+
return this->filtration_container;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
inline PersBackend compute_persistence_out(
|
|
395
|
+
const std::vector<typename MultiFiltration::value_type> &one_filtration,
|
|
396
|
+
std::vector<index_type> &out_gen_order,
|
|
397
|
+
const bool ignore_inf) const { // needed ftm as PersBackend only points there
|
|
398
|
+
constexpr const bool verbose = false;
|
|
399
|
+
if (one_filtration.size() != this->num_generators()) {
|
|
400
|
+
throw;
|
|
401
|
+
}
|
|
402
|
+
out_gen_order.resize(this->num_generators());
|
|
403
|
+
std::iota(out_gen_order.begin(),
|
|
404
|
+
out_gen_order.end(),
|
|
405
|
+
0); // we have to reset here, even though we're already doing this
|
|
406
|
+
std::sort(out_gen_order.begin(), out_gen_order.end(), [&](index_type i, index_type j) {
|
|
407
|
+
if (structure.dimension(i) > structure.dimension(j)) return false;
|
|
408
|
+
if (structure.dimension(i) < structure.dimension(j)) return true;
|
|
409
|
+
return one_filtration[i] < one_filtration[j];
|
|
410
|
+
});
|
|
411
|
+
if (!PersBackend::is_vine && ignore_inf) {
|
|
412
|
+
if constexpr (verbose) {
|
|
413
|
+
std::cout << "Removing infinite simplices" << std::endl;
|
|
414
|
+
}
|
|
415
|
+
for (auto &i : out_gen_order)
|
|
416
|
+
if (one_filtration[i] == MultiFiltration::Generator::T_inf) {
|
|
417
|
+
// TODO : later
|
|
418
|
+
// int d = structure.dimension(i);
|
|
419
|
+
// d = d == 0 ? 1 : 0;
|
|
420
|
+
// if (degrees.size()>d || degrees[d] || degrees[d-1])
|
|
421
|
+
// continue;
|
|
422
|
+
i = std::numeric_limits<typename std::remove_reference_t<decltype(out_gen_order)>::value_type>::max();
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if constexpr (false) {
|
|
426
|
+
std::cout << structure << std::endl;
|
|
427
|
+
std::cout << "[";
|
|
428
|
+
for (auto i : out_gen_order) {
|
|
429
|
+
std::cout << i << ", ";
|
|
430
|
+
}
|
|
431
|
+
std::cout << "]" << std::endl;
|
|
432
|
+
std::cout << "[";
|
|
433
|
+
for (auto i : one_filtration) {
|
|
434
|
+
std::cout << i << ",";
|
|
435
|
+
}
|
|
436
|
+
std::cout << "]" << std::endl;
|
|
437
|
+
}
|
|
438
|
+
return PersBackend(structure, out_gen_order);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
inline bool has_persistence() const { return this->persistence.size(); };
|
|
442
|
+
|
|
443
|
+
inline void compute_persistence(const bool ignore_inf = true) {
|
|
444
|
+
this->persistence = this->compute_persistence_out(
|
|
445
|
+
// this->filtration_container, this->generator_order, degrees); // TODO
|
|
446
|
+
// : later
|
|
447
|
+
this->filtration_container,
|
|
448
|
+
this->generator_order,
|
|
449
|
+
ignore_inf);
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
// TODO : static ?
|
|
453
|
+
inline void vineyard_update(PersBackend &persistence,
|
|
454
|
+
const std::vector<typename MultiFiltration::value_type> &one_filtration,
|
|
455
|
+
std::vector<index_type> &generator_order) const {
|
|
456
|
+
constexpr const bool verbose = false;
|
|
457
|
+
/* static_assert(PersBackend::has_vine_update); */
|
|
458
|
+
// the first false is to get the generator order
|
|
459
|
+
// insertion sort
|
|
460
|
+
auto n = this->num_generators();
|
|
461
|
+
if constexpr (verbose) {
|
|
462
|
+
std::cout << "Vine updates : ";
|
|
463
|
+
}
|
|
464
|
+
for (std::size_t i = 0; i < n; i++) {
|
|
465
|
+
auto j = i;
|
|
466
|
+
while (j > 0 && persistence.get_dimension(j) == persistence.get_dimension(j - 1) &&
|
|
467
|
+
one_filtration[generator_order[j]] < one_filtration[generator_order[j - 1]]) {
|
|
468
|
+
if constexpr (verbose) {
|
|
469
|
+
std::cout << j - 1 << ", ";
|
|
470
|
+
}
|
|
471
|
+
persistence.vine_swap(j - 1);
|
|
472
|
+
std::swap(generator_order[j - 1], generator_order[j]);
|
|
473
|
+
j--;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if constexpr (verbose) {
|
|
477
|
+
std::cout << std::endl;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
inline void vineyard_update() {
|
|
482
|
+
vineyard_update(this->persistence, this->filtration_container, this->generator_order);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
inline split_barcode get_barcode(
|
|
486
|
+
PersBackend &persistence,
|
|
487
|
+
const std::vector<typename MultiFiltration::value_type> &filtration_container) const {
|
|
488
|
+
auto barcode_indices = persistence.get_barcode();
|
|
489
|
+
split_barcode out(this->structure.max_dimension() + 1); // TODO : This doesn't allow for negative dimensions
|
|
490
|
+
constexpr const bool verbose = false;
|
|
491
|
+
constexpr const bool debug = false;
|
|
492
|
+
const auto inf = MultiFiltration::Generator::T_inf;
|
|
493
|
+
for (const auto &bar : barcode_indices) {
|
|
494
|
+
if constexpr (verbose) std::cout << "BAR : " << bar.birth << " " << bar.death << "\n";
|
|
495
|
+
if constexpr (debug) {
|
|
496
|
+
if (bar.birth >= filtration_container.size() || bar.birth < 0) {
|
|
497
|
+
std::cout << "Trying to add an incompatible birth... ";
|
|
498
|
+
std::cout << bar.birth << std::endl;
|
|
499
|
+
std::cout << "Death is " << bar.death << std::endl;
|
|
500
|
+
std::cout << "Max size is " << filtration_container.size() << std::endl;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (bar.dim > static_cast<int>(this->structure.max_dimension())) {
|
|
504
|
+
std::cout << "Incompatible dimension detected... " << bar.dim << std::endl;
|
|
505
|
+
std::cout << "While max dim is " << this->structure.max_dimension() << std::endl;
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
auto birth_filtration = filtration_container[bar.birth];
|
|
511
|
+
auto death_filtration = inf;
|
|
512
|
+
if (bar.death != static_cast<typename PersBackend::pos_index>(-1))
|
|
513
|
+
death_filtration = filtration_container[bar.death];
|
|
514
|
+
|
|
515
|
+
if constexpr (verbose) {
|
|
516
|
+
std::cout << "BAR: " << bar.birth << "(" << birth_filtration << ")"
|
|
517
|
+
<< " --" << bar.death << "(" << death_filtration << ")"
|
|
518
|
+
<< " dim " << bar.dim << std::endl;
|
|
519
|
+
}
|
|
520
|
+
if (birth_filtration < death_filtration)
|
|
521
|
+
out[bar.dim].push_back({birth_filtration, death_filtration});
|
|
522
|
+
else {
|
|
523
|
+
out[bar.dim].push_back({inf, inf});
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return out;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
inline split_barcode get_barcode() { return get_barcode(this->persistence, this->filtration_container); }
|
|
530
|
+
|
|
531
|
+
template <typename value_type = value_type>
|
|
532
|
+
static inline flat_nodim_barcode<value_type> get_flat_nodim_barcode(
|
|
533
|
+
PersBackend &persistence,
|
|
534
|
+
std::vector<typename MultiFiltration::value_type> &filtration_container) {
|
|
535
|
+
constexpr const bool verbose = false;
|
|
536
|
+
const auto &barcode_indices = persistence.get_barcode();
|
|
537
|
+
auto num_bars = barcode_indices.size();
|
|
538
|
+
flat_nodim_barcode<value_type> out(num_bars);
|
|
539
|
+
if (num_bars <= 0) return out;
|
|
540
|
+
auto idx = 0u;
|
|
541
|
+
const value_type inf = MultiFiltration::Generator::T_inf;
|
|
542
|
+
for (const auto &bar : barcode_indices) {
|
|
543
|
+
value_type birth_filtration = inf;
|
|
544
|
+
value_type death_filtration = -birth_filtration;
|
|
545
|
+
if (bar.death == static_cast<typename PersBackend::pos_index>(-1))
|
|
546
|
+
death_filtration = inf;
|
|
547
|
+
else
|
|
548
|
+
death_filtration = static_cast<value_type>(filtration_container[bar.death]);
|
|
549
|
+
birth_filtration = static_cast<value_type>(filtration_container[bar.birth]);
|
|
550
|
+
if constexpr (verbose) {
|
|
551
|
+
std::cout << "PAIRING : " << bar.birth << " / " << bar.death << " dim " << bar.dim << std::endl;
|
|
552
|
+
}
|
|
553
|
+
if constexpr (verbose) {
|
|
554
|
+
std::cout << "PAIRING filtration : " << birth_filtration << " " << death_filtration << " dim " << bar.dim
|
|
555
|
+
<< std::endl;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (birth_filtration < death_filtration)
|
|
559
|
+
out[idx] = {birth_filtration, death_filtration};
|
|
560
|
+
else {
|
|
561
|
+
out[idx] = {inf, inf};
|
|
562
|
+
}
|
|
563
|
+
idx++;
|
|
564
|
+
}
|
|
565
|
+
return out;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
template <typename value_type = value_type>
|
|
569
|
+
static inline flat_barcode<value_type> get_flat_barcode(
|
|
570
|
+
PersBackend &persistence,
|
|
571
|
+
std::vector<typename MultiFiltration::value_type> &filtration_container) {
|
|
572
|
+
constexpr const bool verbose = false;
|
|
573
|
+
const auto &barcode_indices = persistence.get_barcode();
|
|
574
|
+
auto num_bars = barcode_indices.size();
|
|
575
|
+
flat_barcode<value_type> out(num_bars);
|
|
576
|
+
if (num_bars <= 0) return out;
|
|
577
|
+
auto idx = 0u;
|
|
578
|
+
const value_type inf = MultiFiltration::Generator::T_inf;
|
|
579
|
+
for (const auto &bar : barcode_indices) {
|
|
580
|
+
value_type birth_filtration = inf;
|
|
581
|
+
value_type death_filtration = -birth_filtration;
|
|
582
|
+
if (bar.death == static_cast<typename PersBackend::pos_index>(-1))
|
|
583
|
+
death_filtration = inf;
|
|
584
|
+
else
|
|
585
|
+
death_filtration = static_cast<value_type>(filtration_container[bar.death]);
|
|
586
|
+
birth_filtration = static_cast<value_type>(filtration_container[bar.birth]);
|
|
587
|
+
if constexpr (verbose) {
|
|
588
|
+
std::cout << "PAIRING : " << bar.birth << " / " << bar.death << " dim " << bar.dim << std::endl;
|
|
589
|
+
}
|
|
590
|
+
if constexpr (verbose) {
|
|
591
|
+
std::cout << "PAIRING filtration : " << birth_filtration << " " << death_filtration << " dim " << bar.dim
|
|
592
|
+
<< std::endl;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (birth_filtration < death_filtration)
|
|
596
|
+
out[idx] = {bar.dim, {birth_filtration, death_filtration}};
|
|
597
|
+
else {
|
|
598
|
+
out[idx] = {bar.dim, {inf, inf}};
|
|
599
|
+
}
|
|
600
|
+
idx++;
|
|
601
|
+
}
|
|
602
|
+
return out;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
template <typename value_type = value_type>
|
|
606
|
+
inline flat_barcode<value_type> get_flat_barcode() {
|
|
607
|
+
return get_flat_barcode(this->persistence, this->filtration_container);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
template <typename value_type = value_type>
|
|
611
|
+
inline flat_nodim_barcode<value_type> get_flat_nodim_barcode() {
|
|
612
|
+
return get_flat_nodim_barcode(this->persistence, this->filtration_container);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
inline friend std::ostream &operator<<(std::ostream &stream, Truc &truc) {
|
|
616
|
+
stream << "-------------------- Truc \n";
|
|
617
|
+
stream << "--- Structure \n";
|
|
618
|
+
stream << truc.structure;
|
|
619
|
+
/* stream << "-- Dimensions (max " << truc.structure.max_dimension() <<
|
|
620
|
+
* ")\n"; */
|
|
621
|
+
/* stream << "{"; */
|
|
622
|
+
/* for (auto i = 0u; i < truc.num_generators(); i++) */
|
|
623
|
+
/* stream << truc.structure.dimension(i) << ", "; */
|
|
624
|
+
/* stream << "\b" */
|
|
625
|
+
/* << "\b"; */
|
|
626
|
+
/* stream << "}" << std::endl; */
|
|
627
|
+
stream << "--- Order \n";
|
|
628
|
+
stream << "{";
|
|
629
|
+
for (const auto &idx : truc.generator_order) stream << idx << ", ";
|
|
630
|
+
stream << "}" << std::endl;
|
|
631
|
+
|
|
632
|
+
stream << "--- Current slice filtration\n";
|
|
633
|
+
stream << "{";
|
|
634
|
+
for (const auto &stuff : truc.filtration_container) stream << stuff << ", ";
|
|
635
|
+
stream << "\b" << "\b";
|
|
636
|
+
stream << "}" << std::endl;
|
|
637
|
+
|
|
638
|
+
stream << "--- Filtrations \n";
|
|
639
|
+
for (const auto &i : truc.generator_order) {
|
|
640
|
+
stream << i << " : ";
|
|
641
|
+
const auto &stuff = truc.generator_filtration_values[i];
|
|
642
|
+
stream << stuff << "\n";
|
|
643
|
+
}
|
|
644
|
+
stream << "--- PersBackend \n";
|
|
645
|
+
stream << truc.persistence;
|
|
646
|
+
|
|
647
|
+
return stream;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
inline std::string to_str() {
|
|
651
|
+
std::stringstream stream;
|
|
652
|
+
stream << *this;
|
|
653
|
+
return stream.str();
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
inline std::pair<typename MultiFiltration::Generator, typename MultiFiltration::Generator> get_bounding_box() const {
|
|
657
|
+
using OC = typename MultiFiltration::Generator;
|
|
658
|
+
// assert(!generator_filtration_values.empty());
|
|
659
|
+
OC a = OC::inf();
|
|
660
|
+
OC b = -1 * a;
|
|
661
|
+
for (const auto &filtration_value : generator_filtration_values) {
|
|
662
|
+
if constexpr (MultiFiltration::is_multi_critical) {
|
|
663
|
+
a.pull_to_greatest_common_lower_bound(factorize_below(filtration_value));
|
|
664
|
+
b.push_to_least_common_upper_bound(factorize_above(filtration_value));
|
|
665
|
+
} else {
|
|
666
|
+
a.pull_to_greatest_common_lower_bound(filtration_value);
|
|
667
|
+
b.push_to_least_common_upper_bound(filtration_value);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return {a, b};
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
inline std::vector<typename MultiFiltration::Generator> get_filtration_values() const {
|
|
674
|
+
if constexpr (MultiFiltration::is_multi_critical) {
|
|
675
|
+
std::vector<typename MultiFiltration::Generator> out;
|
|
676
|
+
out.reserve(generator_filtration_values.size()); // at least this, will dooble later
|
|
677
|
+
for (std::size_t i = 0; i < generator_filtration_values.size(); ++i) {
|
|
678
|
+
for (const auto &f : generator_filtration_values[i]) {
|
|
679
|
+
out.push_back(f);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return out;
|
|
683
|
+
} else {
|
|
684
|
+
return generator_filtration_values; // copy not necessary for Generator
|
|
685
|
+
} // (could return const&)
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
inline std::vector<MultiFiltration> &get_filtrations() { return generator_filtration_values; }
|
|
689
|
+
|
|
690
|
+
inline const std::vector<MultiFiltration> &get_filtrations() const { return generator_filtration_values; }
|
|
691
|
+
|
|
692
|
+
inline const std::vector<int> get_dimensions() const {
|
|
693
|
+
std::size_t n = this->num_generators();
|
|
694
|
+
std::vector<int> out(n);
|
|
695
|
+
for (std::size_t i = 0; i < n; ++i) {
|
|
696
|
+
out[i] = structure.dimension(i);
|
|
697
|
+
}
|
|
698
|
+
return out;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
inline void prune_above_dimension(int max_dim) {
|
|
702
|
+
int idx = structure.prune_above_dimension(max_dim);
|
|
703
|
+
generator_filtration_values.resize(idx);
|
|
704
|
+
generator_order.resize(idx);
|
|
705
|
+
filtration_container.resize(idx);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
inline const std::vector<std::vector<index_type>> get_boundaries() {
|
|
709
|
+
std::size_t n = this->num_generators();
|
|
710
|
+
std::vector<std::vector<index_type>> out(n);
|
|
711
|
+
for (auto i = 0u; i < n; ++i) {
|
|
712
|
+
out[i] = this->structure[i];
|
|
713
|
+
}
|
|
714
|
+
return out;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
auto coarsen_on_grid(const std::vector<std::vector<typename MultiFiltration::value_type>> grid) {
|
|
718
|
+
using return_type = decltype(std::declval<MultiFiltration>().template as_type<std::int32_t>());
|
|
719
|
+
std::vector<return_type> coords(this->num_generators());
|
|
720
|
+
for (std::size_t gen = 0u; gen < coords.size(); ++gen) {
|
|
721
|
+
coords[gen] = compute_coordinates_in_grid<int32_t>(generator_filtration_values[gen], grid);
|
|
722
|
+
}
|
|
723
|
+
return Truc<PersBackend, Structure, return_type>(structure, coords);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
inline void coarsen_on_grid_inplace(const std::vector<std::vector<typename MultiFiltration::value_type>> &grid,
|
|
727
|
+
bool coordinate = true) {
|
|
728
|
+
for (auto gen = 0u; gen < this->num_generators(); ++gen) {
|
|
729
|
+
generator_filtration_values[gen].project_onto_grid(grid, coordinate);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// dim, num_cycle_of_dim, num_faces_in_cycle, vertices_in_face
|
|
734
|
+
inline std::vector<std::vector<std::vector<std::vector<index_type>>>> get_representative_cycles(
|
|
735
|
+
bool update = true,
|
|
736
|
+
bool detailed = false) {
|
|
737
|
+
// iterable iterable simplex key
|
|
738
|
+
auto cycles_key = persistence.get_representative_cycles(update, detailed);
|
|
739
|
+
auto num_cycles = cycles_key.size();
|
|
740
|
+
std::vector<std::vector<std::vector<std::vector<index_type>>>> out(structure.max_dimension() + 1);
|
|
741
|
+
for (auto &cycles_of_dim : out) cycles_of_dim.reserve(num_cycles);
|
|
742
|
+
for (const auto &cycle : cycles_key) {
|
|
743
|
+
int cycle_dim = 0; // for more generality, should be minimal dimension instead
|
|
744
|
+
if (!cycle[0].empty()) { // if empty, cycle has no border -> assumes dimension 0 even if it could be min dim
|
|
745
|
+
cycle_dim = structure.dimension(cycle[0][0]) + 1; // all faces have the same dim
|
|
746
|
+
}
|
|
747
|
+
out[cycle_dim].push_back(cycle);
|
|
748
|
+
}
|
|
749
|
+
return out;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const std::vector<index_type> &get_current_order() const { return generator_order; }
|
|
753
|
+
|
|
754
|
+
const PersBackend &get_persistence() const { return persistence; }
|
|
755
|
+
|
|
756
|
+
PersBackend &get_persistence() { return persistence; }
|
|
757
|
+
|
|
758
|
+
// TrucThread get_safe_thread() { return TrucThread(*this); }
|
|
759
|
+
|
|
760
|
+
class TrucThread {
|
|
761
|
+
public:
|
|
762
|
+
using Filtration_value = MultiFiltration;
|
|
763
|
+
using value_type = typename MultiFiltration::value_type;
|
|
764
|
+
using ThreadSafe = TrucThread;
|
|
765
|
+
|
|
766
|
+
inline TrucThread(const Truc &truc)
|
|
767
|
+
: truc_ptr(&truc),
|
|
768
|
+
generator_order(truc.get_current_order()),
|
|
769
|
+
filtration_container(truc.get_one_filtration()),
|
|
770
|
+
persistence(truc.get_persistence()) {
|
|
771
|
+
persistence._update_permutation_ptr(generator_order);
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
inline TrucThread(const TrucThread &truc)
|
|
775
|
+
: truc_ptr(truc.truc_ptr),
|
|
776
|
+
generator_order(truc.get_current_order()),
|
|
777
|
+
filtration_container(truc.get_one_filtration()),
|
|
778
|
+
persistence(truc.get_persistence()) {
|
|
779
|
+
persistence._update_permutation_ptr(generator_order);
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
inline TrucThread weak_copy() const { return TrucThread(*truc_ptr); }
|
|
783
|
+
|
|
784
|
+
inline bool has_persistence() const { return this->persistence.size(); };
|
|
785
|
+
|
|
786
|
+
inline const PersBackend &get_persistence() const { return persistence; }
|
|
787
|
+
|
|
788
|
+
inline PersBackend &get_persistence() { return persistence; }
|
|
789
|
+
|
|
790
|
+
inline std::pair<MultiFiltration, MultiFiltration> get_bounding_box() const { return truc_ptr->get_bounding_box(); }
|
|
791
|
+
|
|
792
|
+
inline const std::vector<index_type> &get_current_order() const { return generator_order; }
|
|
793
|
+
|
|
794
|
+
inline const std::vector<MultiFiltration> &get_filtrations() const { return truc_ptr->get_filtrations(); }
|
|
795
|
+
|
|
796
|
+
inline const std::vector<int> &get_dimensions() const { return truc_ptr->get_dimensions(); }
|
|
797
|
+
|
|
798
|
+
inline const std::vector<std::vector<index_type>> &get_boundaries() const { return truc_ptr->get_boundaries(); }
|
|
799
|
+
|
|
800
|
+
inline void coarsen_on_grid_inplace(const std::vector<std::vector<typename MultiFiltration::value_type>> &grid,
|
|
801
|
+
bool coordinate = true) {
|
|
802
|
+
truc_ptr->coarsen_on_grid_inplace(grid, coordinate);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
template <typename Subfiltration>
|
|
806
|
+
inline void push_to(const Subfiltration &f) {
|
|
807
|
+
truc_ptr->push_to_out(f, this->filtration_container, this->generator_order);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
inline std::vector<typename PersBackend::cycle_type> get_representative_cycles(bool update = true) {
|
|
811
|
+
return truc_ptr->get_representative_cycles(update);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
inline void compute_persistence(const bool ignore_inf = true) {
|
|
815
|
+
this->persistence =
|
|
816
|
+
this->truc_ptr->compute_persistence_out(this->filtration_container, this->generator_order, ignore_inf);
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
inline void vineyard_update() {
|
|
820
|
+
truc_ptr->vineyard_update(this->persistence, this->filtration_container, this->generator_order);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
template <typename value_type = value_type>
|
|
824
|
+
inline flat_barcode<value_type> get_flat_barcode() {
|
|
825
|
+
return truc_ptr->get_flat_barcode(this->persistence, this->filtration_container);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
template <typename value_type = value_type>
|
|
829
|
+
inline flat_nodim_barcode<value_type> get_flat_nodim_barcode() {
|
|
830
|
+
return truc_ptr->get_flat_nodim_barcode(this->persistence, this->filtration_container);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
inline split_barcode get_barcode() { return truc_ptr->get_barcode(this->persistence, this->filtration_container); }
|
|
834
|
+
|
|
835
|
+
inline std::size_t num_generators() const { return this->truc_ptr->structure.size(); }
|
|
836
|
+
|
|
837
|
+
inline std::size_t num_parameters() const {
|
|
838
|
+
return num_generators() == 0 ? 0 : this->get_filtrations()[0].num_parameters();
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
inline const std::vector<typename MultiFiltration::value_type> &get_one_filtration() const {
|
|
842
|
+
return this->filtration_container;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
inline std::vector<typename MultiFiltration::value_type> &get_one_filtration() {
|
|
846
|
+
return this->filtration_container;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
private:
|
|
850
|
+
const Truc *truc_ptr;
|
|
851
|
+
std::vector<index_type> generator_order; // size fixed at construction time,
|
|
852
|
+
std::vector<typename MultiFiltration::value_type> filtration_container; // filtration of the current slice
|
|
853
|
+
PersBackend persistence; // generated by the structure, and generator_order.
|
|
854
|
+
|
|
855
|
+
}; // class TrucThread
|
|
856
|
+
|
|
857
|
+
/*
|
|
858
|
+
* returns barcodes of the f(multipers)
|
|
859
|
+
*
|
|
860
|
+
*/
|
|
861
|
+
template <typename Fun, typename Fun_arg>
|
|
862
|
+
inline std::vector<split_barcode> barcodes(Fun &&f, const std::vector<Fun_arg> &args, const bool ignore_inf = true) {
|
|
863
|
+
if (args.size() == 0) {
|
|
864
|
+
return {};
|
|
865
|
+
}
|
|
866
|
+
std::vector<split_barcode> out(args.size());
|
|
867
|
+
|
|
868
|
+
if constexpr (PersBackend::is_vine) {
|
|
869
|
+
this->push_to(f(args[0]));
|
|
870
|
+
this->compute_persistence();
|
|
871
|
+
out[0] = this->get_barcode();
|
|
872
|
+
for (auto i = 1u; i < args.size(); ++i) {
|
|
873
|
+
this->push_to(f(args[i]));
|
|
874
|
+
this->vineyard_update();
|
|
875
|
+
out[i] = this->get_barcode();
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
} else {
|
|
879
|
+
ThreadSafe local_template = this->weak_copy();
|
|
880
|
+
tbb::enumerable_thread_specific<ThreadSafe> thread_locals(local_template);
|
|
881
|
+
tbb::parallel_for(static_cast<std::size_t>(0), args.size(), [&](const std::size_t &i) {
|
|
882
|
+
ThreadSafe &s = thread_locals.local();
|
|
883
|
+
s.push_to(f(args[i]));
|
|
884
|
+
s.compute_persistence(ignore_inf);
|
|
885
|
+
out[i] = s.get_barcode();
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
return out;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// FOR Python interface, but I'm not fan. Todo: do the lambda function in
|
|
892
|
+
// cython?
|
|
893
|
+
inline std::vector<split_barcode> persistence_on_lines(const std::vector<std::vector<value_type>> &basepoints,
|
|
894
|
+
bool ignore_inf) {
|
|
895
|
+
return barcodes(
|
|
896
|
+
[](const std::vector<value_type> &basepoint) { return Gudhi::multi_persistence::Line<value_type>(basepoint); },
|
|
897
|
+
basepoints,
|
|
898
|
+
ignore_inf);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
inline std::vector<split_barcode> persistence_on_lines(
|
|
902
|
+
const std::vector<std::pair<std::vector<value_type>, std::vector<value_type>>> &bp_dirs,
|
|
903
|
+
bool ignore_inf) {
|
|
904
|
+
return barcodes(
|
|
905
|
+
[](const std::pair<std::vector<value_type>, std::vector<value_type>> &bpdir) {
|
|
906
|
+
return Gudhi::multi_persistence::Line<value_type>(bpdir.first, bpdir.second);
|
|
907
|
+
},
|
|
908
|
+
bp_dirs,
|
|
909
|
+
ignore_inf);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
void build_from_scc_file(const std::string &inFilePath,
|
|
913
|
+
bool isRivetCompatible = false,
|
|
914
|
+
bool isReversed = false,
|
|
915
|
+
int shiftDimensions = 0) {
|
|
916
|
+
*this = read_scc_file<Truc>(inFilePath, isRivetCompatible, isReversed, shiftDimensions);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
void write_to_scc_file(const std::string &outFilePath,
|
|
920
|
+
int numberOfParameters = -1,
|
|
921
|
+
int degree = -1,
|
|
922
|
+
bool rivetCompatible = false,
|
|
923
|
+
bool IgnoreLastGenerators = false,
|
|
924
|
+
bool stripComments = false,
|
|
925
|
+
bool reverse = false) {
|
|
926
|
+
write_scc_file<Truc>(
|
|
927
|
+
outFilePath, *this, numberOfParameters, degree, rivetCompatible, IgnoreLastGenerators, stripComments, reverse);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
public:
|
|
931
|
+
using ThreadSafe = TrucThread; // for outside
|
|
932
|
+
|
|
933
|
+
TrucThread weak_copy() const { return TrucThread(*this); }
|
|
934
|
+
|
|
935
|
+
// TODO: declare method here instead of scc_io.h
|
|
936
|
+
// it is just temporary, until Truc is cleaned up
|
|
937
|
+
// friend void write_scc_file<Truc>(const std::string &outFilePath,
|
|
938
|
+
// const Truc &slicer,
|
|
939
|
+
// int numberOfParameters,
|
|
940
|
+
// int degree,
|
|
941
|
+
// bool rivetCompatible,
|
|
942
|
+
// bool IgnoreLastGenerators,
|
|
943
|
+
// bool stripComments,
|
|
944
|
+
// bool reverse);
|
|
945
|
+
|
|
946
|
+
private:
|
|
947
|
+
std::vector<MultiFiltration> generator_filtration_values; // defined at construction time. Const
|
|
948
|
+
std::vector<index_type> generator_order; // size fixed at construction time, // TODO : CHANGE THAT TO UINT32
|
|
949
|
+
Structure structure; // defined at construction time. Const
|
|
950
|
+
std::vector<typename MultiFiltration::value_type> filtration_container; // filtration of the current slice
|
|
951
|
+
PersBackend persistence; // generated by the structure, and generator_order.
|
|
952
|
+
|
|
953
|
+
}; // class Truc
|
|
954
|
+
|
|
955
|
+
} // namespace truc_interface
|
|
956
|
+
} // namespace multiparameter
|
|
957
|
+
} // namespace Gudhi
|