multipers 2.4.0b1__cp312-cp312-macosx_11_0_arm64.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.
Files changed (184) hide show
  1. multipers/.dylibs/libboost_timer.dylib +0 -0
  2. multipers/.dylibs/libc++.1.0.dylib +0 -0
  3. multipers/.dylibs/libtbb.12.17.dylib +0 -0
  4. multipers/__init__.py +33 -0
  5. multipers/_signed_measure_meta.py +426 -0
  6. multipers/_slicer_meta.py +231 -0
  7. multipers/array_api/__init__.py +62 -0
  8. multipers/array_api/numpy.py +124 -0
  9. multipers/array_api/torch.py +133 -0
  10. multipers/data/MOL2.py +458 -0
  11. multipers/data/UCR.py +18 -0
  12. multipers/data/__init__.py +1 -0
  13. multipers/data/graphs.py +466 -0
  14. multipers/data/immuno_regions.py +27 -0
  15. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  16. multipers/data/pytorch2simplextree.py +91 -0
  17. multipers/data/shape3d.py +101 -0
  18. multipers/data/synthetic.py +113 -0
  19. multipers/distances.py +202 -0
  20. multipers/filtration_conversions.pxd +736 -0
  21. multipers/filtration_conversions.pxd.tp +226 -0
  22. multipers/filtrations/__init__.py +21 -0
  23. multipers/filtrations/density.py +529 -0
  24. multipers/filtrations/filtrations.py +480 -0
  25. multipers/filtrations.pxd +534 -0
  26. multipers/filtrations.pxd.tp +332 -0
  27. multipers/function_rips.cpython-312-darwin.so +0 -0
  28. multipers/function_rips.pyx +104 -0
  29. multipers/grids.cpython-312-darwin.so +0 -0
  30. multipers/grids.pyx +538 -0
  31. multipers/gudhi/Persistence_slices_interface.h +213 -0
  32. multipers/gudhi/Simplex_tree_interface.h +274 -0
  33. multipers/gudhi/Simplex_tree_multi_interface.h +648 -0
  34. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
  35. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
  36. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
  37. multipers/gudhi/gudhi/Debug_utils.h +52 -0
  38. multipers/gudhi/gudhi/Degree_rips_bifiltration.h +2307 -0
  39. multipers/gudhi/gudhi/Dynamic_multi_parameter_filtration.h +2524 -0
  40. multipers/gudhi/gudhi/Fields/Multi_field.h +453 -0
  41. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +460 -0
  42. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +444 -0
  43. multipers/gudhi/gudhi/Fields/Multi_field_small.h +584 -0
  44. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +490 -0
  45. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +580 -0
  46. multipers/gudhi/gudhi/Fields/Z2_field.h +391 -0
  47. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +389 -0
  48. multipers/gudhi/gudhi/Fields/Zp_field.h +493 -0
  49. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +384 -0
  50. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +492 -0
  51. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
  52. multipers/gudhi/gudhi/Matrix.h +2200 -0
  53. multipers/gudhi/gudhi/Multi_filtration/Multi_parameter_generator.h +1712 -0
  54. multipers/gudhi/gudhi/Multi_filtration/multi_filtration_conversions.h +237 -0
  55. multipers/gudhi/gudhi/Multi_filtration/multi_filtration_utils.h +225 -0
  56. multipers/gudhi/gudhi/Multi_parameter_filtered_complex.h +485 -0
  57. multipers/gudhi/gudhi/Multi_parameter_filtration.h +2643 -0
  58. multipers/gudhi/gudhi/Multi_persistence/Box.h +233 -0
  59. multipers/gudhi/gudhi/Multi_persistence/Line.h +309 -0
  60. multipers/gudhi/gudhi/Multi_persistence/Multi_parameter_filtered_complex_pcoh_interface.h +268 -0
  61. multipers/gudhi/gudhi/Multi_persistence/Persistence_interface_cohomology.h +159 -0
  62. multipers/gudhi/gudhi/Multi_persistence/Persistence_interface_matrix.h +463 -0
  63. multipers/gudhi/gudhi/Multi_persistence/Point.h +853 -0
  64. multipers/gudhi/gudhi/Off_reader.h +173 -0
  65. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +834 -0
  66. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +838 -0
  67. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +833 -0
  68. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1367 -0
  69. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1157 -0
  70. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +869 -0
  71. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +905 -0
  72. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +122 -0
  73. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +260 -0
  74. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +288 -0
  75. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +170 -0
  76. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +247 -0
  77. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +571 -0
  78. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +182 -0
  79. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +130 -0
  80. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +235 -0
  81. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +312 -0
  82. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1092 -0
  83. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +923 -0
  84. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +914 -0
  85. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +930 -0
  86. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1071 -0
  87. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +203 -0
  88. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +886 -0
  89. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +984 -0
  90. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1213 -0
  91. multipers/gudhi/gudhi/Persistence_matrix/index_mapper.h +58 -0
  92. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +227 -0
  93. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +200 -0
  94. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +166 -0
  95. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +319 -0
  96. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +562 -0
  97. multipers/gudhi/gudhi/Persistence_on_a_line.h +152 -0
  98. multipers/gudhi/gudhi/Persistence_on_rectangle.h +617 -0
  99. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
  100. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
  101. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
  102. multipers/gudhi/gudhi/Persistent_cohomology.h +769 -0
  103. multipers/gudhi/gudhi/Points_off_io.h +171 -0
  104. multipers/gudhi/gudhi/Projective_cover_kernel.h +379 -0
  105. multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
  106. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +559 -0
  107. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
  108. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +121 -0
  109. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
  110. multipers/gudhi/gudhi/Simplex_tree/filtration_value_utils.h +155 -0
  111. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
  112. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
  113. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +60 -0
  114. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +105 -0
  115. multipers/gudhi/gudhi/Simplex_tree.h +3170 -0
  116. multipers/gudhi/gudhi/Slicer.h +848 -0
  117. multipers/gudhi/gudhi/Thread_safe_slicer.h +393 -0
  118. multipers/gudhi/gudhi/distance_functions.h +62 -0
  119. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
  120. multipers/gudhi/gudhi/multi_simplex_tree_helpers.h +147 -0
  121. multipers/gudhi/gudhi/persistence_interval.h +263 -0
  122. multipers/gudhi/gudhi/persistence_matrix_options.h +188 -0
  123. multipers/gudhi/gudhi/reader_utils.h +367 -0
  124. multipers/gudhi/gudhi/simple_mdspan.h +484 -0
  125. multipers/gudhi/gudhi/slicer_helpers.h +779 -0
  126. multipers/gudhi/tmp_h0_pers/mma_interface_h0.h +223 -0
  127. multipers/gudhi/tmp_h0_pers/naive_merge_tree.h +536 -0
  128. multipers/io.cpython-312-darwin.so +0 -0
  129. multipers/io.pyx +472 -0
  130. multipers/ml/__init__.py +0 -0
  131. multipers/ml/accuracies.py +90 -0
  132. multipers/ml/invariants_with_persistable.py +79 -0
  133. multipers/ml/kernels.py +176 -0
  134. multipers/ml/mma.py +713 -0
  135. multipers/ml/one.py +472 -0
  136. multipers/ml/point_clouds.py +352 -0
  137. multipers/ml/signed_measures.py +1667 -0
  138. multipers/ml/sliced_wasserstein.py +461 -0
  139. multipers/ml/tools.py +113 -0
  140. multipers/mma_structures.cpython-312-darwin.so +0 -0
  141. multipers/mma_structures.pxd +134 -0
  142. multipers/mma_structures.pyx +1483 -0
  143. multipers/mma_structures.pyx.tp +1126 -0
  144. multipers/multi_parameter_rank_invariant/diff_helpers.h +85 -0
  145. multipers/multi_parameter_rank_invariant/euler_characteristic.h +95 -0
  146. multipers/multi_parameter_rank_invariant/function_rips.h +317 -0
  147. multipers/multi_parameter_rank_invariant/hilbert_function.h +761 -0
  148. multipers/multi_parameter_rank_invariant/persistence_slices.h +149 -0
  149. multipers/multi_parameter_rank_invariant/rank_invariant.h +350 -0
  150. multipers/multiparameter_edge_collapse.py +41 -0
  151. multipers/multiparameter_module_approximation/approximation.h +2541 -0
  152. multipers/multiparameter_module_approximation/debug.h +107 -0
  153. multipers/multiparameter_module_approximation/format_python-cpp.h +292 -0
  154. multipers/multiparameter_module_approximation/utilities.h +428 -0
  155. multipers/multiparameter_module_approximation.cpython-312-darwin.so +0 -0
  156. multipers/multiparameter_module_approximation.pyx +286 -0
  157. multipers/ops.cpython-312-darwin.so +0 -0
  158. multipers/ops.pyx +231 -0
  159. multipers/pickle.py +89 -0
  160. multipers/plots.py +550 -0
  161. multipers/point_measure.cpython-312-darwin.so +0 -0
  162. multipers/point_measure.pyx +409 -0
  163. multipers/simplex_tree_multi.cpython-312-darwin.so +0 -0
  164. multipers/simplex_tree_multi.pxd +136 -0
  165. multipers/simplex_tree_multi.pyx +11719 -0
  166. multipers/simplex_tree_multi.pyx.tp +2102 -0
  167. multipers/slicer.cpython-312-darwin.so +0 -0
  168. multipers/slicer.pxd +2097 -0
  169. multipers/slicer.pxd.tp +263 -0
  170. multipers/slicer.pyx +13042 -0
  171. multipers/slicer.pyx.tp +1259 -0
  172. multipers/tensor/tensor.h +672 -0
  173. multipers/tensor.pxd +13 -0
  174. multipers/test.pyx +44 -0
  175. multipers/tests/__init__.py +70 -0
  176. multipers/torch/__init__.py +1 -0
  177. multipers/torch/diff_grids.py +240 -0
  178. multipers/torch/rips_density.py +310 -0
  179. multipers/vector_interface.pxd +46 -0
  180. multipers-2.4.0b1.dist-info/METADATA +131 -0
  181. multipers-2.4.0b1.dist-info/RECORD +184 -0
  182. multipers-2.4.0b1.dist-info/WHEEL +6 -0
  183. multipers-2.4.0b1.dist-info/licenses/LICENSE +21 -0
  184. multipers-2.4.0b1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,848 @@
1
+ /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2
+ * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3
+ * Author(s): David Loiseaux
4
+ *
5
+ * Copyright (C) 2023 Inria
6
+ *
7
+ * Modification(s):
8
+ * - 2025/04 Hannah Schreiber: Reorganization + documentation.
9
+ * - YYYY/MM Author: Description of the modification
10
+ */
11
+
12
+ /**
13
+ * @file Slicer.h
14
+ * @author David Loiseaux
15
+ * @brief Contains the @ref Gudhi::multi_persistence::Slicer class.
16
+ */
17
+
18
+ #ifndef MP_SLICER_H_INCLUDED
19
+ #define MP_SLICER_H_INCLUDED
20
+
21
+ #include <array>
22
+ #include <initializer_list>
23
+ #include <limits>
24
+ #include <string>
25
+ #include <type_traits>
26
+ #include <numeric> //std::iota
27
+ #include <utility> //std::move
28
+ #include <cstdint> //std::int32_t
29
+ #include <vector>
30
+ #include <ostream>
31
+ // #include <sstream> //std::stringstream, to remove when to_str gets removed
32
+
33
+ #include <gudhi/Debug_utils.h>
34
+ #include <gudhi/Multi_filtration/multi_filtration_utils.h>
35
+ #include <gudhi/Multi_parameter_filtered_complex.h>
36
+ #include <gudhi/Multi_persistence/Line.h>
37
+ #include <gudhi/Thread_safe_slicer.h>
38
+ #include <gudhi/Projective_cover_kernel.h>
39
+ #include <gudhi/persistence_interval.h>
40
+ #include <gudhi/slicer_helpers.h>
41
+ #include <oneapi/tbb/parallel_for.h>
42
+
43
+ namespace Gudhi {
44
+ namespace multi_persistence {
45
+
46
+ /**
47
+ * @class Slicer Slicer.h gudhi/Slicer.h
48
+ * @ingroup multi_persistence
49
+ *
50
+ * @brief Class encoding a filtered complex, presentation or resolution, inducing a multiparameter persistence module
51
+ * with:
52
+ * (1) a complex / presentation matrix / resolution matrix
53
+ * (2) a filtration (indexed by the complex) for each generator of (1), and
54
+ * (3) tools to compute 1-dimensional slices of the induced multi-parameter persistence module.
55
+ *
56
+ * TODO: more details
57
+ *
58
+ * @tparam MultiFiltrationValue Filtration value class respecting the @ref MultiFiltrationValue concept.
59
+ * @tparam PersistenceAlgorithm Class respecting the @ref PersistenceAlgorithm concept. Used to compute persistence,
60
+ * eventually vineyards and representative cycles.
61
+ */
62
+ template <class MultiFiltrationValue, class PersistenceAlgorithm>
63
+ class Slicer
64
+ {
65
+ public:
66
+ using Persistence = PersistenceAlgorithm; /**< Persistence algorithm type. */
67
+ using Filtration_value = MultiFiltrationValue; /**< Filtration value type. */
68
+ using T = typename Filtration_value::value_type; /**< Numerical filtration value element type. */
69
+ using Complex = Multi_parameter_filtered_complex<Filtration_value>; /**< Complex type. */
70
+ using Index = typename Complex::Index; /**< Complex index type. */
71
+ using Dimension = typename Complex::Dimension; /**< Dimension type. */
72
+ template <typename Value = T>
73
+ using Bar = Gudhi::persistence_matrix::Persistence_interval<Dimension, Value>; /**< Bar type. */
74
+ /**
75
+ * @brief Barcode type. A vector of @ref Bar, a tuple like structure containing birth, death and dimension of a bar.
76
+ */
77
+ template <typename Value = T>
78
+ using Barcode = std::vector<Bar<Value>>;
79
+ /**
80
+ * @brief Flat barcode type. All bars are represented by a birth and a death value stored in arrays of size 2.
81
+ */
82
+ template <typename Value = T>
83
+ using Flat_barcode = std::vector<std::array<Value,2> >;
84
+ /**
85
+ * @brief Barcode ordered by dimension type. A vector which has at index \f$ d \f$ the @ref Barcode of dimension
86
+ * \f$ d \f$.
87
+ */
88
+ template <typename Value = T>
89
+ using Multi_dimensional_barcode = std::vector<Barcode<Value>>;
90
+ /**
91
+ * @brief Flat barcode ordered by dimension type. A vector which has at index \f$ d \f$ the @ref Flat_barcode of
92
+ * dimension \f$ d \f$.
93
+ */
94
+ template <typename Value = T>
95
+ using Multi_dimensional_flat_barcode = std::vector<Flat_barcode<Value>>;
96
+ using Cycle = std::vector<Index>; /**< Cycle type. */
97
+ using Thread_safe = Thread_safe_slicer<Slicer>; /**< Thread safe slicer type. */
98
+
99
+ // CONSTRUCTORS
100
+
101
+ /**
102
+ * @brief Default constructor. Constructs an empty slicer.
103
+ */
104
+ Slicer() = default;
105
+
106
+ /**
107
+ * @brief Constructs the slicer by copying the given complex. The current slice is not initialized to a default
108
+ * value, it can be set with @ref set_slice or @ref push_to.
109
+ *
110
+ * It is recommended to use a complex which is ordered by dimension for better performance.
111
+ */
112
+ Slicer(const Complex& complex)
113
+ : complex_(complex),
114
+ slice_(complex.get_number_of_cycle_generators()),
115
+ generatorOrder_(complex.get_number_of_cycle_generators()),
116
+ persistence_()
117
+ {}
118
+
119
+ /**
120
+ * @brief Constructs the slicer by moving the given complex. The current slice is not initialized to a default
121
+ * value, it can be set with @ref set_slice or @ref push_to.
122
+ *
123
+ * It is recommended to use a complex which is ordered by dimension for better performance.
124
+ */
125
+ Slicer(Complex&& complex)
126
+ : complex_(std::move(complex)),
127
+ slice_(complex_.get_number_of_cycle_generators()),
128
+ generatorOrder_(complex_.get_number_of_cycle_generators()),
129
+ persistence_()
130
+ {}
131
+
132
+ /**
133
+ * @brief Copy constructor. Persistence computation initialization is not updated.
134
+ */
135
+ Slicer(const Slicer& other)
136
+ : complex_(other.complex_), slice_(other.slice_), generatorOrder_(other.generatorOrder_), persistence_()
137
+ {}
138
+
139
+ /**
140
+ * @brief Copy constructor. Persistence computation initialization is not updated.
141
+ */
142
+ template <class OtherMultiFiltrationValue, class OtherPersistenceAlgorithm>
143
+ Slicer(const Slicer<OtherMultiFiltrationValue, OtherPersistenceAlgorithm>& other)
144
+ : complex_(other.get_filtered_complex()),
145
+ slice_(other.get_slice().begin(), other.get_slice().end()),
146
+ generatorOrder_(other.get_current_order()),
147
+ persistence_()
148
+ {}
149
+
150
+ /**
151
+ * @brief Move constructor. Persistence computation initialization is not updated.
152
+ */
153
+ Slicer(Slicer&& other) noexcept
154
+ : complex_(std::move(other.complex_)),
155
+ slice_(std::move(other.slice_)),
156
+ generatorOrder_(std::move(other.generatorOrder_)),
157
+ persistence_()
158
+ {}
159
+
160
+ ~Slicer() = default;
161
+
162
+ /**
163
+ * @brief Assign operator. Persistence computation initialization is not updated.
164
+ */
165
+ Slicer& operator=(const Slicer& other)
166
+ {
167
+ complex_ = other.complex_;
168
+ slice_ = other.slice_;
169
+ generatorOrder_ = other.generatorOrder_;
170
+ persistence_.reset();
171
+
172
+ return *this;
173
+ }
174
+
175
+ /**
176
+ * @brief Assign operator. Persistence computation initialization is not updated.
177
+ */
178
+ template <class OtherMultiFiltrationValue, class OtherPersistenceAlgorithm>
179
+ Slicer& operator=(const Slicer<OtherMultiFiltrationValue, OtherPersistenceAlgorithm>& other)
180
+ {
181
+ complex_ = other.get_filtered_complex();
182
+ slice_ = std::vector<T>(other.get_slice().begin(), other.get_slice().end());
183
+ generatorOrder_ = other.get_current_order();
184
+ persistence_.reset();
185
+
186
+ return *this;
187
+ }
188
+
189
+ /**
190
+ * @brief Move assign operator. Persistence computation initialization is not updated.
191
+ */
192
+ Slicer& operator=(Slicer&& other) noexcept
193
+ {
194
+ complex_ = std::move(other.complex_);
195
+ slice_ = std::move(other.slice_);
196
+ generatorOrder_ = std::move(other.generatorOrder_);
197
+ persistence_.reset();
198
+
199
+ return *this;
200
+ }
201
+
202
+ // TODO: swap ?
203
+
204
+ // ACCESS
205
+
206
+ /**
207
+ * @brief Returns a thread safe copy of this object. The copy is lighter than a real copy, as the complex is passed
208
+ * by pointer and gives access to all const method and persistence related methods. But the returned object will be
209
+ * invalidated if this object is destroyed.
210
+ */
211
+ Thread_safe weak_copy() const { return Thread_safe(*this); }
212
+
213
+ /**
214
+ * @brief Returns the number of generators in the stored module.
215
+ */
216
+ Index get_number_of_cycle_generators() const { return complex_.get_number_of_cycle_generators(); }
217
+
218
+ /**
219
+ * @brief Returns the number of parameters of the stored filtration. If the module is empty, the number returned is 0.
220
+ */
221
+ Index get_number_of_parameters() const { return complex_.get_number_of_parameters(); }
222
+
223
+ /**
224
+ * @brief Returns the underlying complex.
225
+ */
226
+ const Complex& get_filtered_complex() const { return complex_; }
227
+
228
+ /**
229
+ * @brief Returns a const reference to the current permutation map, indicating in which order are the generators
230
+ * with respect to the current slice (i.e., \$f order[i] \$f corresponds to the index in the complex of the
231
+ * \$f i^{th} \$f generator in the filtration represented by the slice). It will be initialized with
232
+ * @ref initialize_persistence_computation.
233
+ *
234
+ * If `ignoreInf` was true when calling @ref initialize_persistence_computation, indices of generators at infinity
235
+ * are not stored in the container. That means that the size can be smaller than what
236
+ * @ref get_number_of_cycle_generators returns.
237
+ */
238
+ const std::vector<Index>& get_current_order() const { return generatorOrder_; }
239
+
240
+ /**
241
+ * @brief Returns a const reference to the current slice. It can be initialized or updated with @ref set_slice
242
+ * and @ref push_to.
243
+ */
244
+ const std::vector<T>& get_slice() const { return slice_; }
245
+
246
+ /**
247
+ * @brief Returns a reference to the current slice. It can also be initialized or updated with @ref set_slice
248
+ * and @ref push_to.
249
+ */
250
+ std::vector<T>& get_slice() { return slice_; }
251
+
252
+ /**
253
+ * @brief Returns a const reference to the class computing the persistence of the current slice. It will be
254
+ * initialized with @ref initialize_persistence_computation.
255
+ */
256
+ const Persistence& get_persistence_algorithm() const { return persistence_; }
257
+
258
+ /**
259
+ * @brief Returns two filtration values representing respectively the greatest common lower bound of all filtration
260
+ * values in the filtration and the lowest common upper bound of them.
261
+ */
262
+ std::pair<Filtration_value, Filtration_value> get_bounding_box() const
263
+ {
264
+ Filtration_value a = Filtration_value::inf(get_number_of_parameters());
265
+ Filtration_value b = Filtration_value::minus_inf(get_number_of_parameters());
266
+ for (const Filtration_value& fil : complex_.get_filtration_values()) {
267
+ if (fil.num_generators() > 1) {
268
+ a.pull_to_greatest_common_lower_bound(factorize_below(fil));
269
+ // Because of Degree_rips_bifiltration
270
+ Filtration_value above = factorize_above(fil);
271
+ auto g = above.num_generators() - 1;
272
+ b.push_to_least_common_upper_bound({above(g, 0), above(g, 1)});
273
+ } else {
274
+ a.pull_to_greatest_common_lower_bound(fil);
275
+ b.push_to_least_common_upper_bound(fil);
276
+ }
277
+ }
278
+ return std::make_pair(std::move(a), std::move(b));
279
+ }
280
+
281
+ /**
282
+ * @brief Returns a const reference to the filtration value container. A filtration value at index \$f i \$f
283
+ * correspond to the filtration value associated to the generators at index \$f i \$f.
284
+ */
285
+ const typename Complex::Filtration_value_container& get_filtration_values() const
286
+ {
287
+ return complex_.get_filtration_values();
288
+ }
289
+
290
+ /**
291
+ * @brief Returns a reference to the filtration value container. A filtration value at index \$f i \$f
292
+ * correspond to the filtration value associated to the generators at index \$f i \$f.
293
+ *
294
+ * @warning The container is not const such that the user can easily modify/update a filtration value. But do not
295
+ * modify the size of the container, nor the number of parameters.
296
+ */
297
+ typename Complex::Filtration_value_container& get_filtration_values() { return complex_.get_filtration_values(); }
298
+
299
+ /**
300
+ * @brief Returns a const reference to the filtration value associated to the generator at index \$f i \$f.
301
+ */
302
+ const Filtration_value& get_filtration_value(Index i) const { return complex_.get_filtration_values()[i]; }
303
+
304
+ /**
305
+ * @brief Returns a reference to the filtration value associated to the generator at index \$f i \$f.
306
+ *
307
+ * @warning The value is not const such that the user can easily modify/update the filtration value. But do not
308
+ * modify the number of parameters.
309
+ */
310
+ Filtration_value& get_filtration_value(Index i) { return complex_.get_filtration_values()[i]; }
311
+
312
+ /**
313
+ * @brief Returns a const reference to the dimension container. A value at index \$f i \$f corresponds to the
314
+ * dimension of the generator at index \$f i \$f.
315
+ */
316
+ const std::vector<Dimension>& get_dimensions() const { return complex_.get_dimensions(); }
317
+
318
+ /**
319
+ * @brief Returns the dimension of the generator at index \$f i \$f.
320
+ */
321
+ Dimension get_dimension(Index i) const { return complex_.get_dimensions()[i]; }
322
+
323
+ /**
324
+ * @brief Returns the maximal dimension of a generator in the module.
325
+ */
326
+ Dimension get_max_dimension() const { return complex_.get_max_dimension(); }
327
+
328
+ /**
329
+ * @brief Returns a const reference to the boundary container. The element at index \$f i \$f corresponds to the
330
+ * boundary of the generator at index \$f i \$f.
331
+ */
332
+ const typename Complex::Boundary_container& get_boundaries() const { return complex_.get_boundaries(); }
333
+
334
+ /**
335
+ * @brief Returns the boundary of the generator at index \$f i \$f.
336
+ */
337
+ const typename Complex::Boundary& get_boundary(Index i) const { return complex_.get_boundaries()[i]; }
338
+
339
+ // // TODO: only used to print info in python, so put in some interface instead
340
+ // std::string to_str() const
341
+ // {
342
+ // std::stringstream stream;
343
+ // stream << *this;
344
+ // return stream.str();
345
+ // }
346
+
347
+ // MODIFIERS
348
+
349
+ /**
350
+ * @brief Sets the current slice, that is the 1-parameter filtration values associated to each generator on that line.
351
+ * The value at \$f slice[i] \$f has to corresponds to the value for the generator at index \$f i \$f.
352
+ * One can also sets the slice directly from the line with @ref push_to.
353
+ *
354
+ * @tparam Array Container with a begin() and end() method and whose element can be converted into `T`.
355
+ */
356
+ template <class Array = std::initializer_list<T>>
357
+ void set_slice(const Array& slice)
358
+ {
359
+ slice_ = std::vector<T>(slice.begin(), slice.end());
360
+ }
361
+
362
+ /**
363
+ * @brief Sets the current slice by computing the 1-parameter filtration values fo each generator on the given line.
364
+ *
365
+ * @tparam Line_like Any type convertible to a @ref Line class. Default value: `std::initializer_list<T>`.
366
+ */
367
+ template <class Line_like = std::initializer_list<T>>
368
+ void push_to(const Line_like& line)
369
+ {
370
+ _push_to(complex_, Line<typename Line_like::value_type>(line));
371
+ }
372
+
373
+ /**
374
+ * @brief Sets the current slice by computing the 1-parameter filtration values fo each generator on the given line.
375
+ *
376
+ * @tparam U Template parameter of the given line.
377
+ */
378
+ template <class U>
379
+ void push_to(const Line<U>& line)
380
+ {
381
+ _push_to(complex_, line);
382
+ }
383
+
384
+ /**
385
+ * @brief Removes completely from the module all generator of dimension strictly higher than given. All
386
+ * initializations are invalidated, so the slice has to be reset and @ref initialize_persistence_computation recalled.
387
+ *
388
+ * @warning If the internal complex was not ordered by dimension, the complex is sorted before pruning.
389
+ * So, the indexing changes afterwards.
390
+ *
391
+ * @param maxDim Maximal dimension to keep.
392
+ */
393
+ void prune_above_dimension(int maxDim)
394
+ {
395
+ int idx = complex_.prune_above_dimension(maxDim);
396
+ generatorOrder_.resize(idx);
397
+ generatorOrder_.shrink_to_fit();
398
+ slice_.resize(idx);
399
+ persistence_.reset();
400
+ }
401
+
402
+ /**
403
+ * @brief Projects all filtration values into the given grid. If @p coordinate is false, the entries are set to
404
+ * the nearest upper bound value with the same parameter in the grid. Otherwise, the entries are set to the indices
405
+ * of those nearest upper bound values.
406
+ * An index \f$ i \f$ of the grid corresponds to the same parameter as the index \f$ i \f$ in a generator of the
407
+ * filtration value. The internal vectors correspond to the possible values of the parameters, ordered by increasing
408
+ * value, forming therefore all together a 2D grid.
409
+ *
410
+ * @param grid Vector of vector with size at least number of filtration parameters.
411
+ * @param coordinate If true, the values are set to the coordinates of the projection in the grid. If false,
412
+ * the values are set to the values at the coordinates of the projection. Default value: true.
413
+ */
414
+ void coarsen_on_grid(const std::vector<std::vector<T>>& grid, bool coordinate = true)
415
+ {
416
+ complex_.coarsen_on_grid(grid, coordinate);
417
+ }
418
+
419
+ // PERSISTENCE
420
+
421
+ /**
422
+ * @brief Returns true if and only if @ref initialize_persistence_computation was properly called.
423
+ */
424
+ [[nodiscard]] bool persistence_computation_is_initialized() const { return persistence_.is_initialized(); }
425
+
426
+ /**
427
+ * @brief Initializes the persistence computation of the current slice. If the slice was not set properly as
428
+ * a valid 1-dimensional filtration, the behaviour is undefined.
429
+ *
430
+ * @param ignoreInf If true, all cells at infinity filtration values are ignored for the initialization, resulting
431
+ * potentially in less storage use and better performance. But note that this can be problematic with the use of
432
+ * @ref vineyard_update. Default value: true.
433
+ */
434
+ void initialize_persistence_computation(const bool ignoreInf = true)
435
+ {
436
+ _initialize_persistence_computation(complex_, ignoreInf);
437
+ }
438
+
439
+ /**
440
+ * @brief After the persistence computation was initialized for a slice and the slice changes, this method can
441
+ * update everything necessary for the barcode without re-computing everything from scratch (contrary to
442
+ * @ref initialize_persistence_computation). Furthermore, it guarantees that the new barcode will "match" the
443
+ * precedent one. TODO: explain exactly what it means and how to do the matching.
444
+ * The method will have better performance if the complex is ordered by dimension.
445
+ *
446
+ * Only available if PersistenceAlgorithm::is_vine is true.
447
+ *
448
+ * @pre @ref initialize_persistence_computation has to be called at least once before.
449
+ *
450
+ * @warning If `ignoreInf` was set to true when initializing the persistence computation, any update of the slice has
451
+ * to keep at infinity the boundaries which were before, otherwise the behaviour is undefined (it will throw with
452
+ * high probability).
453
+ */
454
+ void vineyard_update()
455
+ {
456
+ static_assert(Persistence::is_vine, "vineyard_update() not enabled by the chosen PersistenceAlgorithm class.");
457
+
458
+ const bool is_ordered_by_dim = complex_.is_ordered_by_dimension();
459
+ // speed up when ordered by dim, to avoid unnecessary swaps
460
+ auto dim_condition = [&](int curr) {
461
+ if (is_ordered_by_dim) {
462
+ return persistence_.get_dimension(curr) == persistence_.get_dimension(curr - 1);
463
+ }
464
+ return true;
465
+ };
466
+ for (Index i = 1; i < generatorOrder_.size(); i++) {
467
+ int curr = i;
468
+ while (curr > 0 && dim_condition(curr) && slice_[generatorOrder_[curr]] < slice_[generatorOrder_[curr - 1]]) {
469
+ persistence_.vine_swap(curr - 1);
470
+ std::swap(generatorOrder_[curr - 1], generatorOrder_[curr]);
471
+ --curr;
472
+ }
473
+ }
474
+ }
475
+
476
+ /**
477
+ * @brief Returns the barcode of the current slice. The barcode format will change depending on the template values.
478
+ *
479
+ * @pre @ref initialize_persistence_computation has to be called at some point before.
480
+ *
481
+ * @tparam byDim If true, the barcode is returned as @ref Multi_dimensional_barcode, otherwise as @ref Barcode.
482
+ * @tparam Value Type of the birth and death values.
483
+ * @param maxDim Maximal dimension to be included in the barcode. If negative, all dimensions are included.
484
+ * Default value: -1.
485
+ */
486
+ template <bool byDim = true, typename Value = T, bool idx = false>
487
+ std::conditional_t<byDim, Multi_dimensional_barcode<Value>, Barcode<Value>> get_barcode(int maxDim = -1)
488
+ {
489
+ if (maxDim < 0) maxDim = get_max_dimension();
490
+ if constexpr (byDim) {
491
+ return _get_barcode_by_dim<idx, Value>(maxDim);
492
+ } else {
493
+ return _get_barcode<idx, Value>(maxDim);
494
+ }
495
+ }
496
+
497
+ /**
498
+ * @brief Returns the barcode of the current slice. The barcode format will change depending on the template values.
499
+ *
500
+ * @pre @ref initialize_persistence_computation has to be called at some point before.
501
+ *
502
+ * @tparam byDim If true, the barcode is returned as @ref Multi_dimensional_flat_barcode, otherwise as
503
+ * @ref Flat_barcode.
504
+ * @tparam Value Type of the birth and death values.
505
+ * @param maxDim Maximal dimension to be included in the barcode. If negative, all dimensions are included.
506
+ * Default value: -1.
507
+ */
508
+ template <bool byDim = false, typename Value = T, bool idx = false>
509
+ std::conditional_t<byDim, Multi_dimensional_flat_barcode<Value>, Flat_barcode<Value>> get_flat_barcode(
510
+ int maxDim = -1)
511
+ {
512
+ if (maxDim < 0) maxDim = get_max_dimension();
513
+ if constexpr (byDim) {
514
+ return _get_flat_barcode_by_dim<idx, Value>(maxDim);
515
+ } else {
516
+ return _get_flat_barcode<idx, Value>(maxDim);
517
+ }
518
+ }
519
+
520
+ /**
521
+ * @brief Returns the representative cycles of the current slice. All cycles of dimension \f$ d \f$ are stored at
522
+ * index \f$ d \f$ of the returned vector. A cycle is represented by a vector of boundary indices. That is, the index
523
+ * \f$ i \f$ in a cycle represents the cell which boundary can be retrieved by @ref get_boundary "get_boundary(i)".
524
+ *
525
+ * Only available if PersistenceAlgorithm::has_rep_cycles is true.
526
+ *
527
+ * @pre @ref initialize_persistence_computation has to be called at least once before.
528
+ *
529
+ * @param update If true, updates the stored representative cycles, otherwise just returns the container in its
530
+ * current state. So should be true at least the first time the method is used.
531
+ */
532
+ std::vector<std::vector<Cycle>> get_representative_cycles(bool update = true)
533
+ {
534
+ return _get_representative_cycles(complex_, update);
535
+ }
536
+
537
+ Cycle get_most_persistent_cycle(Dimension dim = 1, bool update = true)
538
+ {
539
+ static_assert(Persistence::has_rep_cycles,
540
+ "Representative cycles not enabled by the chosen PersistenceAlgorithm class.");
541
+
542
+ auto barcodeIndices = persistence_.get_barcode();
543
+
544
+ Index maxIndex = -1;
545
+ Index maxBirth = std::numeric_limits<Index>::max();
546
+ T maxLength = 0;
547
+ for (Index i = 0; i < barcodeIndices.size(); ++i) {
548
+ // barcodeIndices[i] does not work
549
+ const auto& bar = barcodeIndices(i);
550
+ if (bar.dim == dim) {
551
+ if (bar.death == Persistence::nullDeath) {
552
+ if (maxBirth > bar.birth) {
553
+ maxBirth = bar.birth;
554
+ maxIndex = i;
555
+ maxLength = Filtration_value::T_inf;
556
+ }
557
+ } else {
558
+ T length = std::abs(slice_[bar.death] - slice_[bar.birth]);
559
+ if (maxLength < length) {
560
+ maxLength = length;
561
+ maxIndex = i;
562
+ }
563
+ }
564
+ }
565
+ }
566
+
567
+ if (maxIndex == static_cast<Index>(-1)) return {};
568
+
569
+ return persistence_.get_representative_cycle(maxIndex, update);
570
+ }
571
+
572
+ // FRIENDS
573
+
574
+ /**
575
+ * @brief Builds a new slicer by reordering the cells in the complex of the given slicer with the given permutation
576
+ * map.
577
+ */
578
+ friend Slicer build_permuted_slicer(const Slicer& slicer, const std::vector<Index>& permutation)
579
+ {
580
+ GUDHI_CHECK(permutation.size() < slicer.get_number_of_cycle_generators(),
581
+ std::invalid_argument(
582
+ "Too many elements in permutation vector. Got perm size: " + std::to_string(permutation.size()) +
583
+ " while this->size: " + std::to_string(slicer.get_number_of_cycle_generators())));
584
+ return Slicer(build_permuted_complex(slicer.complex_, permutation));
585
+ }
586
+
587
+ /**
588
+ * @brief Builds a new slicer by reordering the cells in the complex of the given slicer the same way than
589
+ * @ref Multi_parameter_filtered_complex::sort_by_dimension_co_lexicographically. Returns a pair with the new slicer
590
+ * as first element and the permutation map used as second element.
591
+ */
592
+ friend std::pair<Slicer, std::vector<Index>> build_permuted_slicer(const Slicer& slicer)
593
+ {
594
+ auto [complex, permutation] = build_permuted_complex(slicer.complex_);
595
+ return std::make_pair(Slicer(std::move(complex)), std::move(permutation));
596
+ }
597
+
598
+ /**
599
+ * @brief Builds a new slicer from the given one by projecting its filtration values on a grid.
600
+ * See @ref coarsen_on_grid with the paramater `coordinate` at true.
601
+ */
602
+ friend auto build_slicer_coarsen_on_grid(const Slicer& slicer, const std::vector<std::vector<T>> grid)
603
+ {
604
+ using return_filtration_value = decltype(std::declval<Filtration_value>().template as_type<std::int32_t>());
605
+ using return_complex = decltype(build_complex_coarsen_on_grid(slicer.complex_, grid));
606
+ using return_pers = typename Persistence::template As_type<return_complex>;
607
+ return Slicer<return_filtration_value, return_pers>(build_complex_coarsen_on_grid(slicer.complex_, grid));
608
+ }
609
+
610
+ /**
611
+ * @brief Builds a new slicer using @ref Projective_cover_kernel. TODO: explain what that means.
612
+ */
613
+ friend Slicer build_slicer_from_projective_cover_kernel(const Slicer& slicer, Dimension dim)
614
+ {
615
+ Projective_cover_kernel<Filtration_value> kernel(slicer.complex_, dim);
616
+ return Slicer(kernel.create_complex());
617
+ }
618
+
619
+ /**
620
+ * @brief Writes the given slicer into a file with scc format. Assumes that every index appearing in a boundary of
621
+ * the complex corresponds to an existing index in the complex (for example, the lowest dimension has always empty
622
+ * boundaries).
623
+ * See @ref build_slicer_from_scc_file to build a slicer from a scc format file.
624
+ *
625
+ * @param outFilePath Path with file name into which to write.
626
+ * @param slicer Slicer to write. Every index appearing in a boundary of the complex has to correspond to an
627
+ * existing index in the underlying complex.
628
+ * @param degree TODO Default value: -1.
629
+ * @param rivetCompatible Set to true if the written file has to be Rivet compatible. Note that Rivet only accepts
630
+ * bi-filtrations. Default value: false.
631
+ * @param ignoreLastGenerators Set to true, if the generators with last dimension in the list should be ignored
632
+ * (maximal dimension by default, minimal dimension if `reverse` is true). Default value: false.
633
+ * @param stripComments Set to true, if no comment should be written in the file (comments are lines starting with `#`
634
+ * and which are ignored when read). Default value: false.
635
+ * @param reverse Set to true if the generators should be written in increasing order of dimension instead of
636
+ * decreasing. Default value: false.
637
+ */
638
+ friend void write_slicer_to_scc_file(const std::string& outFilePath,
639
+ const Slicer& slicer,
640
+ int degree = -1,
641
+ bool rivetCompatible = false,
642
+ bool ignoreLastGenerators = false,
643
+ bool stripComments = false,
644
+ bool reverse = false)
645
+ {
646
+ const Complex& cpx =
647
+ slicer.complex_.is_ordered_by_dimension() ? slicer.complex_ : build_permuted_complex(slicer.complex_).first;
648
+ write_complex_to_scc_file<typename Slicer::Filtration_value>(
649
+ outFilePath, cpx, degree, rivetCompatible, ignoreLastGenerators, stripComments, reverse);
650
+ };
651
+
652
+ /**
653
+ * @brief Outstream operator.
654
+ */
655
+ friend std::ostream& operator<<(std::ostream& stream, Slicer& slicer)
656
+ {
657
+ stream << "-------------------- Slicer \n";
658
+
659
+ stream << "--- Filtered complex \n";
660
+ stream << slicer.complex_;
661
+
662
+ stream << "--- Order \n";
663
+ stream << "{";
664
+ for (const auto& idx : slicer.generatorOrder_) stream << idx << ", ";
665
+ stream << "}" << '\n';
666
+
667
+ stream << "--- Current slice filtration\n";
668
+ stream << "{";
669
+ for (const auto& val : slicer.slice_) stream << val << ", ";
670
+ if (!slicer.slice_.empty()) stream << "\b" << "\b";
671
+ stream << "}" << '\n';
672
+
673
+ stream << "--- PersBackend \n";
674
+ stream << slicer.persistence_;
675
+
676
+ return stream;
677
+ }
678
+
679
+ protected:
680
+ friend Thread_safe; // Thread_safe will use the "_*" methods below instead of "*".
681
+
682
+ // For ThreadSafe version
683
+ Slicer(const std::vector<T>& slice, const std::vector<Index>& generatorOrder, const Persistence& persistence)
684
+ : complex_(), slice_(slice), generatorOrder_(generatorOrder), persistence_(persistence, generatorOrder_)
685
+ {}
686
+
687
+ Slicer(std::vector<T>&& slice, std::vector<Index>&& generatorOrder, Persistence&& persistence)
688
+ : complex_(),
689
+ slice_(std::move(slice)),
690
+ generatorOrder_(std::move(generatorOrder)),
691
+ persistence_(std::move(persistence), generatorOrder_)
692
+ {}
693
+
694
+ template <class U>
695
+ void _push_to(const Complex& complex, const Line<U>& line)
696
+ {
697
+ const auto& filtrationValues = complex.get_filtration_values();
698
+ tbb::parallel_for(Index(0), Index(filtrationValues.size()), [&](Index i){
699
+ slice_[i] = line.template compute_forward_intersection<T>(filtrationValues[i]);
700
+ });
701
+ // for (Index i = 0U; i < filtrationValues.size(); i++) {
702
+ // slice_[i] = line.template compute_forward_intersection<T>(filtrationValues[i]);
703
+ // }
704
+ }
705
+
706
+ void _initialize_persistence_computation(const Complex& complex, const bool ignoreInf = true)
707
+ {
708
+ _initialize_order(complex, ignoreInf);
709
+ persistence_.reinitialize(complex, generatorOrder_);
710
+ }
711
+
712
+ std::vector<std::vector<Cycle>> _get_representative_cycles(const Complex& complex, bool update = true)
713
+ {
714
+ static_assert(Persistence::has_rep_cycles,
715
+ "Representative cycles not enabled by the chosen PersistenceAlgorithm class.");
716
+
717
+ const auto& dimensions = complex.get_dimensions();
718
+ auto cycleKeys = persistence_.get_representative_cycles(update);
719
+ auto numCycles = cycleKeys.size();
720
+ std::vector<std::vector<Cycle>> out(complex.get_max_dimension() + 1);
721
+ for (auto& cyclesDim : out) cyclesDim.reserve(numCycles);
722
+ for (const auto& cycle : cycleKeys) {
723
+ GUDHI_CHECK(!cycle.empty(), "A cycle should not be empty...");
724
+ // assumes cycle to be never empty & all faces have same dimension
725
+ out[dimensions[cycle[0]]].push_back(cycle);
726
+ }
727
+ return out;
728
+ }
729
+
730
+ private:
731
+ Complex complex_; /**< Complex storing all boundaries, filtration values and dimensions. */
732
+ std::vector<T> slice_; /**< Filtration values of the current slice. The indices corresponds to those in complex_. */
733
+ std::vector<Index> generatorOrder_; /**< Permutation map from current slice index to complex index. */
734
+ Persistence persistence_; /**< Class for persistence computations. */
735
+
736
+ void _initialize_order(const Complex& complex, const bool ignoreInf = true)
737
+ {
738
+ const auto& dimensions = complex.get_dimensions();
739
+ generatorOrder_.resize(complex.get_number_of_cycle_generators());
740
+ std::iota(generatorOrder_.begin(), generatorOrder_.end(), 0);
741
+ std::sort(generatorOrder_.begin(), generatorOrder_.end(), [&](Index i, Index j) {
742
+ if (ignoreInf) {
743
+ if (slice_[i] != Filtration_value::T_inf && slice_[j] == Filtration_value::T_inf) return true;
744
+ // all elements at inf are considered equal
745
+ if (slice_[i] == Filtration_value::T_inf) return false;
746
+ }
747
+ if (dimensions[i] > dimensions[j]) return false;
748
+ if (dimensions[i] < dimensions[j]) return true;
749
+ // if filtration values are equal, we don't care about order, so considered the same object
750
+ return slice_[i] < slice_[j];
751
+ });
752
+ if (ignoreInf) {
753
+ Index end = generatorOrder_.size();
754
+ while (end > 0 && slice_[generatorOrder_[end - 1]] == Filtration_value::T_inf) --end;
755
+ generatorOrder_.resize(end);
756
+ }
757
+ }
758
+
759
+ template <bool idx, class Interval, typename Value>
760
+ void _retrieve_interval(const Interval& bar, Dimension& dim, Value& birth, Value& death)
761
+ {
762
+ const Value inf = Gudhi::multi_filtration::MF_T_inf<Value>;
763
+ dim = bar.dim;
764
+ if constexpr (idx) {
765
+ birth = bar.birth;
766
+ death = -1;
767
+ if (bar.death != Persistence::nullDeath) death = bar.death;
768
+ } else {
769
+ birth = slice_[bar.birth];
770
+ death = inf;
771
+ if (bar.death != Persistence::nullDeath) death = slice_[bar.death];
772
+ if (!(birth <= death)) {
773
+ birth = inf;
774
+ death = inf;
775
+ }
776
+ }
777
+ }
778
+
779
+ template <bool idx, typename Value>
780
+ Barcode<Value> _get_barcode(int maxDim)
781
+ {
782
+ auto barcodeIndices = persistence_.get_barcode();
783
+ Barcode<Value> out(barcodeIndices.size());
784
+ Index i = 0;
785
+ for (const auto& bar : barcodeIndices) {
786
+ if (bar.dim <= maxDim) {
787
+ _retrieve_interval<idx>(bar, out[i].dim, out[i].birth, out[i].death);
788
+ ++i;
789
+ }
790
+ }
791
+ out.resize(i);
792
+ return out;
793
+ }
794
+
795
+ template <bool idx, typename Value>
796
+ Multi_dimensional_barcode<Value> _get_barcode_by_dim(int maxDim)
797
+ {
798
+ // TODO: This doesn't allow for negative dimensions
799
+ // Hannah: not sure what this comment means ?
800
+ Multi_dimensional_barcode<Value> out(maxDim + 1);
801
+ Value birth, death;
802
+ Dimension dim;
803
+ for (const auto& bar : persistence_.get_barcode()) {
804
+ if (bar.dim <= maxDim) {
805
+ _retrieve_interval<idx>(bar, dim, birth, death);
806
+ out[dim].emplace_back(birth, death, dim);
807
+ }
808
+ }
809
+ return out;
810
+ }
811
+
812
+ template <bool idx, typename Value>
813
+ Flat_barcode<Value> _get_flat_barcode(int maxDim)
814
+ {
815
+ auto barcodeIndices = persistence_.get_barcode();
816
+ Flat_barcode<Value> out(barcodeIndices.size());
817
+ Index i = 0;
818
+ Dimension dim; // dummy
819
+ for (const auto& bar : barcodeIndices) {
820
+ if (bar.dim <= maxDim) {
821
+ _retrieve_interval<idx>(bar, dim, out[i][0], out[i][1]);
822
+ ++i;
823
+ }
824
+ }
825
+ out.resize(i);
826
+ return out;
827
+ }
828
+
829
+ template <bool idx, typename Value>
830
+ Multi_dimensional_flat_barcode<Value> _get_flat_barcode_by_dim(int maxDim)
831
+ {
832
+ Multi_dimensional_flat_barcode<Value> out(maxDim + 1);
833
+ Value birth, death;
834
+ Dimension dim;
835
+ for (const auto& bar : persistence_.get_barcode()) {
836
+ if (bar.dim <= maxDim) {
837
+ _retrieve_interval<idx>(bar, dim, birth, death);
838
+ out[dim].emplace_back(std::array<Value, 2>{birth, death});
839
+ }
840
+ }
841
+ return out;
842
+ }
843
+ };
844
+
845
+ } // namespace multi_persistence
846
+ } // namespace Gudhi
847
+
848
+ #endif // MP_SLICER_H_INCLUDED