multipers 2.3.1__cp313-cp313-manylinux_2_34_x86_64.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.

Files changed (179) hide show
  1. multipers/__init__.py +33 -0
  2. multipers/_signed_measure_meta.py +430 -0
  3. multipers/_slicer_meta.py +211 -0
  4. multipers/data/MOL2.py +458 -0
  5. multipers/data/UCR.py +18 -0
  6. multipers/data/__init__.py +1 -0
  7. multipers/data/graphs.py +466 -0
  8. multipers/data/immuno_regions.py +27 -0
  9. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  10. multipers/data/pytorch2simplextree.py +91 -0
  11. multipers/data/shape3d.py +101 -0
  12. multipers/data/synthetic.py +113 -0
  13. multipers/distances.py +198 -0
  14. multipers/filtration_conversions.pxd +229 -0
  15. multipers/filtration_conversions.pxd.tp +84 -0
  16. multipers/filtrations/__init__.py +18 -0
  17. multipers/filtrations/density.py +563 -0
  18. multipers/filtrations/filtrations.py +289 -0
  19. multipers/filtrations.pxd +224 -0
  20. multipers/function_rips.cpython-313-x86_64-linux-gnu.so +0 -0
  21. multipers/function_rips.pyx +105 -0
  22. multipers/grids.cpython-313-x86_64-linux-gnu.so +0 -0
  23. multipers/grids.pyx +350 -0
  24. multipers/gudhi/Persistence_slices_interface.h +132 -0
  25. multipers/gudhi/Simplex_tree_interface.h +239 -0
  26. multipers/gudhi/Simplex_tree_multi_interface.h +516 -0
  27. multipers/gudhi/cubical_to_boundary.h +59 -0
  28. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
  29. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
  30. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
  31. multipers/gudhi/gudhi/Debug_utils.h +45 -0
  32. multipers/gudhi/gudhi/Fields/Multi_field.h +484 -0
  33. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -0
  34. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -0
  35. multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -0
  36. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -0
  37. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -0
  38. multipers/gudhi/gudhi/Fields/Z2_field.h +355 -0
  39. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -0
  40. multipers/gudhi/gudhi/Fields/Zp_field.h +420 -0
  41. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -0
  42. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -0
  43. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
  44. multipers/gudhi/gudhi/Matrix.h +2107 -0
  45. multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -0
  46. multipers/gudhi/gudhi/Multi_persistence/Box.h +171 -0
  47. multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -0
  48. multipers/gudhi/gudhi/Off_reader.h +173 -0
  49. multipers/gudhi/gudhi/One_critical_filtration.h +1433 -0
  50. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -0
  51. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -0
  52. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -0
  53. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -0
  54. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -0
  55. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -0
  56. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -0
  57. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -0
  58. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -0
  59. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -0
  60. multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -0
  61. multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -0
  62. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -0
  63. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -0
  64. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -0
  65. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -0
  66. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -0
  67. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -0
  68. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -0
  69. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -0
  70. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -0
  71. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -0
  72. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -0
  73. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -0
  74. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -0
  75. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -0
  76. multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -0
  77. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -0
  78. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -0
  79. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -0
  80. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -0
  81. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -0
  82. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -0
  83. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -0
  84. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
  85. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
  86. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
  87. multipers/gudhi/gudhi/Persistent_cohomology.h +745 -0
  88. multipers/gudhi/gudhi/Points_off_io.h +171 -0
  89. multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
  90. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -0
  91. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
  92. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -0
  93. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
  94. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
  95. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
  96. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -0
  97. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -0
  98. multipers/gudhi/gudhi/Simplex_tree.h +2794 -0
  99. multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -0
  100. multipers/gudhi/gudhi/distance_functions.h +62 -0
  101. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
  102. multipers/gudhi/gudhi/persistence_interval.h +253 -0
  103. multipers/gudhi/gudhi/persistence_matrix_options.h +170 -0
  104. multipers/gudhi/gudhi/reader_utils.h +367 -0
  105. multipers/gudhi/mma_interface_coh.h +256 -0
  106. multipers/gudhi/mma_interface_h0.h +223 -0
  107. multipers/gudhi/mma_interface_matrix.h +291 -0
  108. multipers/gudhi/naive_merge_tree.h +536 -0
  109. multipers/gudhi/scc_io.h +310 -0
  110. multipers/gudhi/truc.h +957 -0
  111. multipers/io.cpython-313-x86_64-linux-gnu.so +0 -0
  112. multipers/io.pyx +714 -0
  113. multipers/ml/__init__.py +0 -0
  114. multipers/ml/accuracies.py +90 -0
  115. multipers/ml/invariants_with_persistable.py +79 -0
  116. multipers/ml/kernels.py +176 -0
  117. multipers/ml/mma.py +713 -0
  118. multipers/ml/one.py +472 -0
  119. multipers/ml/point_clouds.py +352 -0
  120. multipers/ml/signed_measures.py +1589 -0
  121. multipers/ml/sliced_wasserstein.py +461 -0
  122. multipers/ml/tools.py +113 -0
  123. multipers/mma_structures.cpython-313-x86_64-linux-gnu.so +0 -0
  124. multipers/mma_structures.pxd +127 -0
  125. multipers/mma_structures.pyx +2742 -0
  126. multipers/mma_structures.pyx.tp +1083 -0
  127. multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -0
  128. multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -0
  129. multipers/multi_parameter_rank_invariant/function_rips.h +322 -0
  130. multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -0
  131. multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -0
  132. multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -0
  133. multipers/multiparameter_edge_collapse.py +41 -0
  134. multipers/multiparameter_module_approximation/approximation.h +2298 -0
  135. multipers/multiparameter_module_approximation/combinatory.h +129 -0
  136. multipers/multiparameter_module_approximation/debug.h +107 -0
  137. multipers/multiparameter_module_approximation/euler_curves.h +0 -0
  138. multipers/multiparameter_module_approximation/format_python-cpp.h +286 -0
  139. multipers/multiparameter_module_approximation/heap_column.h +238 -0
  140. multipers/multiparameter_module_approximation/images.h +79 -0
  141. multipers/multiparameter_module_approximation/list_column.h +174 -0
  142. multipers/multiparameter_module_approximation/list_column_2.h +232 -0
  143. multipers/multiparameter_module_approximation/ru_matrix.h +347 -0
  144. multipers/multiparameter_module_approximation/set_column.h +135 -0
  145. multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -0
  146. multipers/multiparameter_module_approximation/unordered_set_column.h +166 -0
  147. multipers/multiparameter_module_approximation/utilities.h +403 -0
  148. multipers/multiparameter_module_approximation/vector_column.h +223 -0
  149. multipers/multiparameter_module_approximation/vector_matrix.h +331 -0
  150. multipers/multiparameter_module_approximation/vineyards.h +464 -0
  151. multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -0
  152. multipers/multiparameter_module_approximation.cpython-313-x86_64-linux-gnu.so +0 -0
  153. multipers/multiparameter_module_approximation.pyx +218 -0
  154. multipers/pickle.py +90 -0
  155. multipers/plots.py +342 -0
  156. multipers/point_measure.cpython-313-x86_64-linux-gnu.so +0 -0
  157. multipers/point_measure.pyx +322 -0
  158. multipers/simplex_tree_multi.cpython-313-x86_64-linux-gnu.so +0 -0
  159. multipers/simplex_tree_multi.pxd +133 -0
  160. multipers/simplex_tree_multi.pyx +10402 -0
  161. multipers/simplex_tree_multi.pyx.tp +1947 -0
  162. multipers/slicer.cpython-313-x86_64-linux-gnu.so +0 -0
  163. multipers/slicer.pxd +2552 -0
  164. multipers/slicer.pxd.tp +218 -0
  165. multipers/slicer.pyx +16530 -0
  166. multipers/slicer.pyx.tp +931 -0
  167. multipers/tensor/tensor.h +672 -0
  168. multipers/tensor.pxd +13 -0
  169. multipers/test.pyx +44 -0
  170. multipers/tests/__init__.py +57 -0
  171. multipers/torch/__init__.py +1 -0
  172. multipers/torch/diff_grids.py +217 -0
  173. multipers/torch/rips_density.py +310 -0
  174. multipers-2.3.1.dist-info/LICENSE +21 -0
  175. multipers-2.3.1.dist-info/METADATA +144 -0
  176. multipers-2.3.1.dist-info/RECORD +179 -0
  177. multipers-2.3.1.dist-info/WHEEL +5 -0
  178. multipers-2.3.1.dist-info/top_level.txt +1 -0
  179. multipers.libs/libtbb-f2c6754f.so.12.14 +0 -0
multipers/gudhi/truc.h ADDED
@@ -0,0 +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 <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