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,463 @@
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): Hannah Schreiber
4
+ *
5
+ * Copyright (C) 2025 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+ /**
12
+ * @file Persistence_interface_matrix.h
13
+ * @author Hannah Schreiber
14
+ * @brief Contains the @ref Gudhi::multi_persistence::Persistence_interface_matrix class.
15
+ */
16
+
17
+ #ifndef MP_PERSISTENCE_INTERFACE_MATRIX_H_INCLUDED
18
+ #define MP_PERSISTENCE_INTERFACE_MATRIX_H_INCLUDED
19
+
20
+ #include <cstddef>
21
+ #include <optional>
22
+ #include <utility>
23
+ #include <vector>
24
+
25
+ #include <boost/range/iterator_range_core.hpp>
26
+
27
+ #include <gudhi/Matrix.h>
28
+ #include <gudhi/Debug_utils.h>
29
+
30
+ namespace Gudhi {
31
+ namespace multi_persistence {
32
+
33
+ /**
34
+ * @class Persistence_interface_matrix Persistence_interface_matrix.h \
35
+ * gudhi/Multi_persistence/Persistence_interface_matrix.h
36
+ * @ingroup multi_persistence
37
+ *
38
+ * @brief Interface respecting the @ref PersistenceAlgorithm concept to use @ref Slicer with the homology, vineyard
39
+ * and representative cycle algorithms implemented in @ref Gudhi::persistence_matrix::Matrix.
40
+ *
41
+ * @tparam PosIdxPersistenceMatrixOptions Options respecting the
42
+ * @ref Gudhi::persistence_matrix::PersistenceMatrixOptions concept such that, either
43
+ * @ref Gudhi::persistence_matrix::PersistenceMatrixOptions::column_indexation_type "column_indexation_type" is
44
+ * @ref Gudhi::persistence_matrix::Column_indexation_types::POSITION "POSITION", or,
45
+ * @ref Gudhi::persistence_matrix::PersistenceMatrixOptions::is_of_boundary_type "is_of_boundary_type" is true and
46
+ * @ref Gudhi::persistence_matrix::PersistenceMatrixOptions::column_indexation_type "column_indexation_type" is
47
+ * @ref Gudhi::persistence_matrix::Column_indexation_types::CONTAINER "CONTAINER".
48
+ */
49
+ template <class PosIdxPersistenceMatrixOptions>
50
+ class Persistence_interface_matrix
51
+ {
52
+ public:
53
+ using Options = PosIdxPersistenceMatrixOptions;
54
+ using Matrix = Gudhi::persistence_matrix::Matrix<Options>; /**< Complex type */
55
+ using Dimension = typename Options::Dimension; /**< Dimension type */
56
+ using Index = typename Options::Index; /**< Index type */
57
+ using Map = std::vector<Index>; /**< Map type */
58
+ using Bar = typename Matrix::Bar; /**< Bar type */
59
+ using Cycle = typename Matrix::Cycle; /**< Cycle type */
60
+ template<class Complex>
61
+ using As_type = Persistence_interface_matrix<PosIdxPersistenceMatrixOptions>; /**< This type. */
62
+
63
+ class Barcode_iterator
64
+ : public boost::iterator_facade<Barcode_iterator, const Bar, boost::random_access_traversal_tag>
65
+ {
66
+ private:
67
+ using Base = boost::iterator_facade<Barcode_iterator, const Bar, boost::random_access_traversal_tag>;
68
+
69
+ public:
70
+ using Barcode = typename Matrix::Barcode;
71
+
72
+ using difference_type = typename Base::difference_type;
73
+ using size_type = std::size_t;
74
+ using const_reference = const Bar&;
75
+
76
+ Barcode_iterator(const Barcode& barcode, const Map& permutation, size_type pos)
77
+ : barcode_(&barcode),
78
+ permutation_(&permutation),
79
+ currPos_(pos > barcode.size() ? barcode.size() : pos),
80
+ currBar_()
81
+ {
82
+ // end otherwise
83
+ if (currPos_ < barcode.size()) _update_bar();
84
+ }
85
+
86
+ // necessary for boost::iterator_range to be able to use operator().
87
+ // operator[] not possible in this particular case
88
+ Bar operator[](difference_type n) const
89
+ {
90
+ const auto& b = (*barcode_)[currPos_ + n]; // n is out of range if currPos_ + n is out of range from barcode_
91
+ return Bar(_posToIndex(b.birth), b.death == Bar::inf ? b.death : _posToIndex(b.death), b.dim);
92
+ }
93
+
94
+ private:
95
+ using Pos_index = typename std::tuple_element<2, Bar>::type;
96
+
97
+ friend class boost::iterator_core_access;
98
+
99
+ bool equal(Barcode_iterator const& other) const
100
+ {
101
+ return barcode_ == other.barcode_ && permutation_ == other.permutation_ && currPos_ == other.currPos_;
102
+ }
103
+
104
+ const_reference dereference() const { return currBar_; }
105
+
106
+ void increment()
107
+ {
108
+ ++currPos_;
109
+ if (currPos_ < barcode_->size()) _update_bar();
110
+ }
111
+
112
+ void decrement()
113
+ {
114
+ --currPos_;
115
+ if (currPos_ < barcode_->size()) _update_bar();
116
+ }
117
+
118
+ void advance(difference_type n)
119
+ {
120
+ currPos_ += n;
121
+ if (currPos_ < barcode_->size()) _update_bar();
122
+ }
123
+
124
+ difference_type distance_to(const Barcode_iterator& other) const { return other.currPos_ - currPos_; }
125
+
126
+ Pos_index _posToIndex(Pos_index pos) const { return (*permutation_)[pos]; }
127
+
128
+ void _update_bar()
129
+ {
130
+ const auto& b = (*barcode_)[currPos_];
131
+ currBar_.dim = b.dim;
132
+ currBar_.birth = _posToIndex(b.birth);
133
+ currBar_.death = b.death == Bar::inf ? b.death : _posToIndex(b.death);
134
+ }
135
+
136
+ Barcode const* barcode_;
137
+ Map const* permutation_;
138
+ size_type currPos_;
139
+ Bar currBar_;
140
+ };
141
+
142
+ class Cycles_iterator
143
+ : public boost::iterator_facade<Cycles_iterator, const Cycle, boost::random_access_traversal_tag>
144
+ {
145
+ private:
146
+ using Base = boost::iterator_facade<Barcode_iterator, const Bar, boost::random_access_traversal_tag>;
147
+
148
+ public:
149
+ using Cycles = std::vector<Cycle>;
150
+
151
+ using difference_type = typename Base::difference_type;
152
+ using size_type = std::size_t;
153
+ using const_reference = const Cycle&;
154
+
155
+ Cycles_iterator(const Cycles& cycles, const Map& permutation, Map const* idToPos, size_type pos)
156
+ : cycles_(&cycles),
157
+ permutation_(&permutation),
158
+ idToPos_(idToPos),
159
+ currPos_(pos > cycles.size() ? cycles.size() : pos),
160
+ currCycle_()
161
+ {
162
+ if constexpr (Options::has_vine_update && !Options::is_of_boundary_type) {
163
+ GUDHI_CHECK(idToPos_ != nullptr, "ID to position map has to be set for chain matrices using vineyard.");
164
+ }
165
+ // end otherwise
166
+ if (currPos_ < cycles.size()) _update_cycle();
167
+ }
168
+
169
+ // necessary for boost::iterator_range to be able to use operator().
170
+ // operator[] not possible in this particular case
171
+ Cycle operator[](difference_type n) const
172
+ {
173
+ Cycle res((*cycles_)[currPos_ + n]);
174
+ for (auto& id : res) {
175
+ if constexpr (PosIdxPersistenceMatrixOptions::is_z2) {
176
+ id = _id_to_index(id);
177
+ } else {
178
+ id.first = _id_to_index(id.first);
179
+ }
180
+ }
181
+ return res;
182
+ }
183
+
184
+ private:
185
+ friend class boost::iterator_core_access;
186
+
187
+ bool equal(Cycles_iterator const& other) const
188
+ {
189
+ return cycles_ == other.cycles_ && permutation_ == other.permutation_ && currPos_ == other.currPos_;
190
+ }
191
+
192
+ const_reference dereference() const { return currCycle_; }
193
+
194
+ void increment()
195
+ {
196
+ ++currPos_;
197
+ if (currPos_ < cycles_->size()) _update_cycle();
198
+ }
199
+
200
+ void decrement()
201
+ {
202
+ --currPos_;
203
+ if (currPos_ < cycles_->size()) _update_cycle();
204
+ }
205
+
206
+ void advance(difference_type n)
207
+ {
208
+ currPos_ += n;
209
+ if (currPos_ < cycles_->size()) _update_cycle();
210
+ }
211
+
212
+ difference_type distance_to(const Cycles_iterator& other) const { return other.currPos_ - currPos_; }
213
+
214
+ Index _id_to_index(Index id) const
215
+ {
216
+ if constexpr (Options::is_of_boundary_type || !Options::has_vine_update) {
217
+ // works for RU because id == pos, but does not work for chain with vine
218
+ // we need a id to pos map in that case
219
+ return (*permutation_)[id];
220
+ } else {
221
+ return (*permutation_)[(*idToPos_)[id]];
222
+ }
223
+ }
224
+
225
+ void _update_cycle()
226
+ {
227
+ const auto& c = (*cycles_)[currPos_];
228
+ currCycle_.resize(c.size());
229
+ for (size_type i = 0; i < c.size(); ++i) {
230
+ if constexpr (PosIdxPersistenceMatrixOptions::is_z2) {
231
+ currCycle_[i] = _id_to_index(c[i]);
232
+ } else {
233
+ currCycle_[i].first = _id_to_index(c[i]);
234
+ }
235
+ }
236
+ }
237
+
238
+ Cycles const* cycles_;
239
+ Map const* permutation_;
240
+ Map const* idToPos_;
241
+ size_type currPos_;
242
+ Cycle currCycle_;
243
+ };
244
+
245
+ using Barcode = boost::iterator_range<Barcode_iterator>; /**< Barcode type */
246
+ using Cycles = boost::iterator_range<Cycles_iterator>; /**< Cycle container type */
247
+
248
+ static constexpr const auto nullDeath = Bar::inf;
249
+ /**
250
+ * @brief True if and only if PosIdxPersistenceMatrixOptions::has_vine_update is true.
251
+ */
252
+ static constexpr const bool is_vine = Options::has_vine_update;
253
+ /**
254
+ * @brief True if and only if PosIdxPersistenceMatrixOptions::can_retrieve_representative_cycles is true.
255
+ */
256
+ static constexpr const bool has_rep_cycles = Options::can_retrieve_representative_cycles;
257
+
258
+ Persistence_interface_matrix() : permutation_(nullptr) {}
259
+
260
+ // `permutation` is assumed to have stable size, i.e., its address never changes
261
+ template <class Complex>
262
+ Persistence_interface_matrix(const Complex& cpx, const Map& permutation)
263
+ : matrix_(permutation.size()), permutation_(&permutation)
264
+ {
265
+ static_assert(
266
+ Options::column_indexation_type == Gudhi::persistence_matrix::Column_indexation_types::POSITION ||
267
+ (Options::is_of_boundary_type &&
268
+ Options::column_indexation_type == Gudhi::persistence_matrix::Column_indexation_types::CONTAINER),
269
+ "Matrix has a non supported index scheme.");
270
+
271
+ _initialize(cpx);
272
+ }
273
+
274
+ Persistence_interface_matrix(const Persistence_interface_matrix& other) = delete;
275
+
276
+ // permutation is assumed to be the same than from the copied object, just its address can change
277
+ Persistence_interface_matrix(const Persistence_interface_matrix& other, const Map& permutation)
278
+ : matrix_(other.matrix_), permutation_(other.is_initialized() ? &permutation : nullptr), idToPos_(other.idToPos_)
279
+ {
280
+ GUDHI_CHECK(!other.is_initialized() || permutation == *other.permutation_,
281
+ "Only the address of the permutation vector is allowed to change, not its content.");
282
+ }
283
+
284
+ Persistence_interface_matrix(Persistence_interface_matrix&& other) = delete;
285
+
286
+ // permutation is assumed to be the same than from the moved object, just its address can change
287
+ Persistence_interface_matrix(Persistence_interface_matrix&& other, const Map& permutation)
288
+ : matrix_(std::move(other.matrix_)),
289
+ permutation_(other.is_initialized() ? &permutation : nullptr),
290
+ idToPos_(std::move(other.idToPos_))
291
+ {
292
+ other.permutation_ = nullptr;
293
+ }
294
+
295
+ ~Persistence_interface_matrix() = default;
296
+
297
+ Persistence_interface_matrix& operator=(const Persistence_interface_matrix& other) = delete;
298
+ Persistence_interface_matrix& operator=(Persistence_interface_matrix&& other) noexcept = delete;
299
+
300
+ // TODO: swap?
301
+
302
+ template <class Complex>
303
+ void reinitialize(const Complex& cpx, const Map& permutation)
304
+ {
305
+ matrix_ = Matrix(permutation.size());
306
+ permutation_ = &permutation;
307
+ _initialize(cpx);
308
+ }
309
+
310
+ void reset()
311
+ {
312
+ matrix_ = Matrix();
313
+ permutation_ = nullptr;
314
+ if constexpr (Options::has_vine_update && !Options::is_of_boundary_type) {
315
+ if (idToPos_) idToPos_->clear();
316
+ }
317
+ }
318
+
319
+ [[nodiscard]] bool is_initialized() const { return permutation_ != nullptr; }
320
+
321
+ Dimension get_dimension(Index i) const
322
+ {
323
+ GUDHI_CHECK(is_initialized(), "Dimension can not be computed uninitialized.");
324
+ return matrix_.get_column_dimension(i);
325
+ }
326
+
327
+ Barcode get_barcode()
328
+ {
329
+ GUDHI_CHECK(is_initialized(), "Barcode can not be computed uninitialized.");
330
+
331
+ const auto& barcode = matrix_.get_current_barcode();
332
+ return Barcode(Barcode_iterator(barcode, *permutation_, 0),
333
+ Barcode_iterator(barcode, *permutation_, barcode.size()));
334
+ }
335
+
336
+ void vine_swap(Index i)
337
+ {
338
+ static_assert(is_vine, "`vine_swap` is not enabled with the given options.");
339
+ GUDHI_CHECK(is_initialized(), "Vineyard can not be computed uninitialized.");
340
+
341
+ if constexpr (!Options::is_of_boundary_type) {
342
+ auto id1 = matrix_.get_pivot(i);
343
+ auto id2 = matrix_.get_pivot(i + 1);
344
+ std::swap((*idToPos_)[id1], (*idToPos_)[id2]);
345
+ }
346
+ matrix_.vine_swap(i);
347
+ }
348
+
349
+ Cycles get_representative_cycles(bool update)
350
+ {
351
+ static_assert(has_rep_cycles, "`get_representative_cycles` is not enabled with the given options.");
352
+ GUDHI_CHECK(is_initialized(), "Representative cycles can not be computed uninitialized.");
353
+
354
+ if (update) matrix_.update_representative_cycles();
355
+
356
+ const auto& cycles = matrix_.get_representative_cycles();
357
+ Map* idToPosPtr = nullptr;
358
+ if constexpr (Options::has_vine_update && !Options::is_of_boundary_type) {
359
+ idToPosPtr = &(*idToPos_);
360
+ }
361
+ return Cycles(Cycles_iterator(cycles, *permutation_, idToPosPtr, 0),
362
+ Cycles_iterator(cycles, *permutation_, idToPosPtr, cycles.size()));
363
+ }
364
+
365
+ Cycle get_representative_cycle(Index barcodeIndex, bool update)
366
+ {
367
+ static_assert(has_rep_cycles, "`get_representative_cycle` is not enabled with the given options.");
368
+ GUDHI_CHECK(is_initialized(), "Representative cycles can not be computed uninitialized.");
369
+
370
+ auto id_to_index = [&](Index id) -> Index {
371
+ if constexpr (Options::is_of_boundary_type || !Options::has_vine_update) {
372
+ // works for RU because id == pos, but does not work for chain with vine
373
+ // we need a id to pos map in that case
374
+ return (*permutation_)[id];
375
+ } else {
376
+ return (*permutation_)[(*idToPos_)[id]];
377
+ }
378
+ };
379
+
380
+ if (update) matrix_.update_representative_cycles();
381
+
382
+ const auto& c = matrix_.get_representative_cycle(matrix_.get_current_barcode()[barcodeIndex]);
383
+
384
+ Cycle cycle(c.size());
385
+ for (Index i = 0; i < c.size(); ++i) {
386
+ if constexpr (PosIdxPersistenceMatrixOptions::is_z2) {
387
+ cycle[i] = id_to_index(c[i]);
388
+ } else {
389
+ cycle[i].first = id_to_index(c[i]);
390
+ }
391
+ }
392
+ return cycle;
393
+ }
394
+
395
+ /**
396
+ * @brief Outstream operator.
397
+ */
398
+ friend std::ostream& operator<<(std::ostream& stream, Persistence_interface_matrix& pers)
399
+ {
400
+ stream << "Matrix:\n";
401
+ stream << "[\n";
402
+ for (auto i = 0U; i < pers.matrix_.get_number_of_columns(); i++) {
403
+ stream << "[";
404
+ for (const auto& v : pers.matrix_.get_column(i)) stream << v << ", ";
405
+ stream << "]\n";
406
+ }
407
+ stream << "]\n";
408
+ stream << "Permutation:\n";
409
+ if (pers.permutation_ != nullptr) {
410
+ for (auto v : *pers.permutation_) {
411
+ stream << v << " ";
412
+ }
413
+ }
414
+ stream << "\n";
415
+ if constexpr (Options::has_vine_update && !Options::is_of_boundary_type) {
416
+ stream << "ID to position map:\n";
417
+ for (auto v : *pers.idToPos_) {
418
+ stream << v << " ";
419
+ }
420
+ stream << "\n";
421
+ }
422
+
423
+ return stream;
424
+ }
425
+
426
+ private:
427
+ Matrix matrix_;
428
+ Map const* permutation_;
429
+ std::optional<Map> idToPos_;
430
+
431
+ template <class Complex>
432
+ void _initialize(const Complex& cpx)
433
+ {
434
+ if constexpr (Options::has_vine_update && !Options::is_of_boundary_type) {
435
+ idToPos_.emplace();
436
+ idToPos_->reserve(permutation_->size());
437
+ }
438
+ const auto& boundaries = cpx.get_boundaries();
439
+ const auto& dimensions = cpx.get_dimensions();
440
+ // simplex IDs need to be increasing in order, so the original ones cannot be used
441
+ Map permutationInv(cpx.get_number_of_cycle_generators());
442
+ Map translated_boundary;
443
+ std::size_t id = 0;
444
+ for (auto i : *permutation_) {
445
+ permutationInv[i] = id; // permutation is assumed to be a valid filtration
446
+ translated_boundary.resize(boundaries[i].size());
447
+ for (std::size_t j = 0; j < boundaries[i].size(); ++j) {
448
+ translated_boundary[j] = permutationInv[boundaries[i][j]];
449
+ }
450
+ std::sort(translated_boundary.begin(), translated_boundary.end());
451
+ matrix_.insert_boundary(id, translated_boundary, dimensions[i]);
452
+ if constexpr (Options::has_vine_update && !Options::is_of_boundary_type) {
453
+ idToPos_->push_back(id);
454
+ }
455
+ ++id; // IDs corresponds to the indices in permutation_
456
+ }
457
+ }
458
+ };
459
+
460
+ } // namespace multi_persistence
461
+ } // namespace Gudhi
462
+
463
+ #endif // MP_PERSISTENCE_INTERFACE_MATRIX_H_INCLUDED