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,562 @@
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) 2022-24 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+ /**
12
+ * @file ru_vine_swap.h
13
+ * @author Hannah Schreiber
14
+ * @brief Contains the @ref Gudhi::persistence_matrix::RU_vine_swap class, as well as the
15
+ * @ref Gudhi::persistence_matrix::Dummy_ru_vine_swap and
16
+ * @ref Gudhi::persistence_matrix::Dummy_ru_vine_pairing structures.
17
+ */
18
+
19
+ #ifndef PM_RU_VINE_SWAP_H
20
+ #define PM_RU_VINE_SWAP_H
21
+
22
+ #include <cassert>
23
+ #include <utility> //std::move
24
+ #include <stdexcept> //std::invalid_argument
25
+
26
+ #include <gudhi/Persistence_matrix/ru_pairing.h>
27
+
28
+ namespace Gudhi {
29
+ namespace persistence_matrix {
30
+
31
+ /**
32
+ * @ingroup persistence_matrix
33
+ *
34
+ * @brief Empty structure.
35
+ * Inherited instead of @ref RU_vine_swap, when vine swaps are not enabled.
36
+ */
37
+ struct Dummy_ru_vine_swap {
38
+ using RUP = void;
39
+
40
+ friend void swap([[maybe_unused]] Dummy_ru_vine_swap& d1, [[maybe_unused]] Dummy_ru_vine_swap& d2) noexcept {}
41
+ };
42
+
43
+ /**
44
+ * @ingroup persistence_matrix
45
+ *
46
+ * @brief Empty structure.
47
+ * Inherited instead of @ref RU_pairing, when the barcode is not stored.
48
+ */
49
+ struct Dummy_ru_vine_pairing {
50
+ friend void swap([[maybe_unused]] Dummy_ru_vine_pairing& d1, [[maybe_unused]] Dummy_ru_vine_pairing& d2) noexcept {}
51
+ };
52
+
53
+ /**
54
+ * @ingroup persistence_matrix
55
+ *
56
+ * @brief Class managing the barcode for @ref RU_vine_swap.
57
+ *
58
+ * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced.
59
+ */
60
+ template <typename Master_matrix>
61
+ class RU_barcode_swap : public RU_pairing<Master_matrix>
62
+ {
63
+ public:
64
+ using Index = typename Master_matrix::Index; /**< @ref MatIdx index type. */
65
+ using ID_index = typename Master_matrix::ID_index; /**< @ref IDIdx index type. */
66
+ using Pos_index = typename Master_matrix::Pos_index; /**< @ref PosIdx index type. */
67
+ // RUP = RU Pairing
68
+ using RUP = RU_pairing<Master_matrix>;
69
+
70
+ /**
71
+ * @brief Default constructor.
72
+ */
73
+ RU_barcode_swap() = default;
74
+ /**
75
+ * @brief Copy constructor.
76
+ *
77
+ * @param toCopy Matrix to copy.
78
+ */
79
+ RU_barcode_swap(const RU_barcode_swap& toCopy) : RUP(static_cast<const RUP&>(toCopy)) {};
80
+ /**
81
+ * @brief Move constructor.
82
+ *
83
+ * @param other Matrix to move.
84
+ */
85
+ RU_barcode_swap(RU_barcode_swap&& other) noexcept : RUP(std::move(static_cast<RUP&>(other))) {};
86
+
87
+ ~RU_barcode_swap() = default;
88
+
89
+ RU_barcode_swap& operator=(const RU_barcode_swap& other)
90
+ {
91
+ RUP::operator=(other);
92
+ return *this;
93
+ }
94
+
95
+ RU_barcode_swap& operator=(RU_barcode_swap&& other) noexcept
96
+ {
97
+ RUP::operator=(std::move(other));
98
+ return *this;
99
+ }
100
+
101
+ friend void swap(RU_barcode_swap& swap1, RU_barcode_swap& swap2) noexcept
102
+ {
103
+ swap(static_cast<RUP&>(swap1), static_cast<RUP&>(swap2));
104
+ }
105
+
106
+ protected:
107
+ void _positive_transpose_barcode(Index columnIndex)
108
+ {
109
+ _birth(columnIndex) = columnIndex + 1;
110
+ _birth(columnIndex + 1) = columnIndex;
111
+ std::swap(RUP::indexToBar_.at(columnIndex), RUP::indexToBar_.at(columnIndex + 1));
112
+ }
113
+
114
+ void _negative_transpose_barcode(Index columnIndex)
115
+ {
116
+ _death(columnIndex) = columnIndex + 1;
117
+ _death(columnIndex + 1) = columnIndex;
118
+ std::swap(RUP::indexToBar_.at(columnIndex), RUP::indexToBar_.at(columnIndex + 1));
119
+ }
120
+
121
+ void _positive_negative_transpose_barcode(Index columnIndex)
122
+ {
123
+ _birth(columnIndex) = columnIndex + 1;
124
+ _death(columnIndex + 1) = columnIndex;
125
+ std::swap(RUP::indexToBar_.at(columnIndex), RUP::indexToBar_.at(columnIndex + 1));
126
+ }
127
+
128
+ void _negative_positive_transpose_barcode(Index columnIndex)
129
+ {
130
+ _death(columnIndex) = columnIndex + 1;
131
+ _birth(columnIndex + 1) = columnIndex;
132
+ std::swap(RUP::indexToBar_.at(columnIndex), RUP::indexToBar_.at(columnIndex + 1));
133
+ }
134
+
135
+ Pos_index _death_val(Pos_index index) const
136
+ {
137
+ if constexpr (Master_matrix::Option_list::has_removable_columns) {
138
+ return RUP::indexToBar_.at(index)->death;
139
+ } else {
140
+ return RUP::barcode_.at(RUP::indexToBar_.at(index)).death;
141
+ }
142
+ }
143
+
144
+ Pos_index _birth_val(Pos_index index) const
145
+ {
146
+ if constexpr (Master_matrix::Option_list::has_removable_columns) {
147
+ return RUP::indexToBar_.at(index)->birth;
148
+ } else {
149
+ return RUP::barcode_.at(RUP::indexToBar_.at(index)).birth;
150
+ }
151
+ }
152
+
153
+ void _reset() { RUP::_reset(); }
154
+
155
+ private:
156
+ Pos_index& _death(Pos_index index)
157
+ {
158
+ if constexpr (Master_matrix::Option_list::has_removable_columns) {
159
+ return RUP::indexToBar_.at(index)->death;
160
+ } else {
161
+ return RUP::barcode_.at(RUP::indexToBar_.at(index)).death;
162
+ }
163
+ }
164
+
165
+ Pos_index& _birth(Pos_index index)
166
+ {
167
+ if constexpr (Master_matrix::Option_list::has_removable_columns) {
168
+ return RUP::indexToBar_.at(index)->birth;
169
+ } else {
170
+ return RUP::barcode_.at(RUP::indexToBar_.at(index)).birth;
171
+ }
172
+ }
173
+ };
174
+
175
+ /**
176
+ * @class RU_vine_swap ru_vine_swap.h gudhi/Persistence_matrix/ru_vine_swap.h
177
+ * @ingroup persistence_matrix
178
+ *
179
+ * @brief Class managing the vine swaps for @ref RU_matrix.
180
+ *
181
+ * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced.
182
+ */
183
+ template <class Master_matrix>
184
+ class RU_vine_swap
185
+ {
186
+ public:
187
+ using Index = typename Master_matrix::Index; /**< @ref MatIdx index type. */
188
+ using ID_index = typename Master_matrix::ID_index; /**< @ref IDIdx index type. */
189
+ using Pos_index = typename Master_matrix::Pos_index; /**< @ref PosIdx index type. */
190
+
191
+ /**
192
+ * @brief Default constructor.
193
+ */
194
+ RU_vine_swap() = default;
195
+
196
+ /**
197
+ * @brief Does the same than @ref vine_swap, but assumes that the swap is non trivial and
198
+ * therefore skips a part of the case study.
199
+ *
200
+ * @param index @ref PosIdx index of the first cell to swap. The second one has to be at `position + 1`.
201
+ * @return true If the barcode changed from the swap.
202
+ * @return false Otherwise.
203
+ */
204
+ bool vine_swap_with_z_eq_1_case(Pos_index index);
205
+ /**
206
+ * @brief Does a vine swap between two cells which are consecutive in the filtration.
207
+ * Roughly, if \f$ F \f$ is the current filtration represented by the matrix, the method modifies the matrix
208
+ * such that the new state corresponds to a valid state for the filtration \f$ F' \f$ equal to \f$ F \f$ but
209
+ * with the two cells at position `position` and `position + 1` swapped. Of course, the two cells should
210
+ * not have a face/coface relation which each other ; \f$ F' \f$ has to be a valid filtration.
211
+ * See @cite vineyards for more information about vine and vineyards.
212
+ *
213
+ * @param index @ref PosIdx index of the first cell to swap. The second one has to be at `position + 1`.
214
+ * @return true If the barcode changed from the swap.
215
+ * @return false Otherwise.
216
+ */
217
+ bool vine_swap(Pos_index index);
218
+
219
+ /**
220
+ * @brief Swap operator.
221
+ */
222
+ friend void swap([[maybe_unused]] RU_vine_swap& swap1, [[maybe_unused]] RU_vine_swap& swap2) noexcept {}
223
+
224
+ private:
225
+ using Master_RU_matrix = typename Master_matrix::Master_RU_matrix;
226
+
227
+ bool _is_paired(Index columnIndex);
228
+ void _swap_at_index(Index columnIndex);
229
+ void _add_to(Index sourceIndex, Index targetIndex);
230
+ void _positive_transpose(Index columnIndex);
231
+ void _negative_transpose(Index columnIndex);
232
+ void _positive_negative_transpose(Index columnIndex);
233
+ void _negative_positive_transpose(Index columnIndex);
234
+ bool _positive_vine_swap(Index columnIndex);
235
+ bool _negative_vine_swap(Index columnIndex);
236
+ bool _positive_negative_vine_swap(Index columnIndex);
237
+ bool _negative_positive_vine_swap(Index columnIndex);
238
+ Pos_index _get_death(Index simplexIndex);
239
+ Pos_index _get_birth(Index simplexIndex);
240
+ ID_index _get_row_id_from_position(Pos_index position) const;
241
+
242
+ constexpr Master_RU_matrix* _matrix() { return static_cast<Master_RU_matrix*>(this); }
243
+
244
+ constexpr const Master_RU_matrix* _matrix() const { return static_cast<const Master_RU_matrix*>(this); }
245
+ };
246
+
247
+ template <class Master_matrix>
248
+ inline bool RU_vine_swap<Master_matrix>::vine_swap_with_z_eq_1_case(Pos_index index)
249
+ {
250
+ GUDHI_CHECK(index < _matrix()->reducedMatrixR_.get_number_of_columns() - 1,
251
+ std::invalid_argument("RU_vine_swap::vine_swap_with_z_eq_1_case - Index to swap out of bound."));
252
+
253
+ bool iIsPositive = _matrix()->reducedMatrixR_.is_zero_column(index);
254
+ bool iiIsPositive = _matrix()->reducedMatrixR_.is_zero_column(index + 1);
255
+
256
+ if (iIsPositive && iiIsPositive) {
257
+ _matrix()->mirrorMatrixU_.zero_entry(index, _get_row_id_from_position(index + 1));
258
+ return _positive_vine_swap(index);
259
+ }
260
+ if (!iIsPositive && !iiIsPositive) {
261
+ return _negative_vine_swap(index);
262
+ }
263
+ if (iIsPositive && !iiIsPositive) {
264
+ return _positive_negative_vine_swap(index);
265
+ }
266
+ return _negative_positive_vine_swap(index);
267
+ }
268
+
269
+ template <class Master_matrix>
270
+ inline bool RU_vine_swap<Master_matrix>::vine_swap(Pos_index index)
271
+ {
272
+ GUDHI_CHECK(index < _matrix()->reducedMatrixR_.get_number_of_columns() - 1,
273
+ std::invalid_argument("RU_vine_swap::vine_swap - Index to swap out of bound."));
274
+
275
+ bool iIsPositive = _matrix()->reducedMatrixR_.is_zero_column(index);
276
+ bool iiIsPositive = _matrix()->reducedMatrixR_.is_zero_column(index + 1);
277
+
278
+ if (iIsPositive && iiIsPositive) {
279
+ if (_matrix()->reducedMatrixR_.get_column_dimension(index) !=
280
+ _matrix()->reducedMatrixR_.get_column_dimension(index + 1)) {
281
+ _positive_transpose(index);
282
+ _swap_at_index(index);
283
+ return true;
284
+ }
285
+ if (!_matrix()->mirrorMatrixU_.is_zero_entry(index, _get_row_id_from_position(index + 1))) {
286
+ _matrix()->mirrorMatrixU_.zero_entry(index, _get_row_id_from_position(index + 1));
287
+ }
288
+ return _positive_vine_swap(index);
289
+ }
290
+ if (!iIsPositive && !iiIsPositive) {
291
+ if (_matrix()->reducedMatrixR_.get_column_dimension(index) !=
292
+ _matrix()->reducedMatrixR_.get_column_dimension(index + 1) ||
293
+ _matrix()->mirrorMatrixU_.is_zero_entry(index, _get_row_id_from_position(index + 1))) {
294
+ _negative_transpose(index);
295
+ _swap_at_index(index);
296
+ return true;
297
+ }
298
+ return _negative_vine_swap(index);
299
+ }
300
+ if (iIsPositive && !iiIsPositive) {
301
+ if (_matrix()->reducedMatrixR_.get_column_dimension(index) !=
302
+ _matrix()->reducedMatrixR_.get_column_dimension(index + 1) ||
303
+ _matrix()->mirrorMatrixU_.is_zero_entry(index, _get_row_id_from_position(index + 1))) {
304
+ _positive_negative_transpose(index);
305
+ _swap_at_index(index);
306
+ return true;
307
+ }
308
+ return _positive_negative_vine_swap(index);
309
+ }
310
+ if (_matrix()->reducedMatrixR_.get_column_dimension(index) !=
311
+ _matrix()->reducedMatrixR_.get_column_dimension(index + 1) ||
312
+ _matrix()->mirrorMatrixU_.is_zero_entry(index, _get_row_id_from_position(index + 1))) {
313
+ _negative_positive_transpose(index);
314
+ _swap_at_index(index);
315
+ return true;
316
+ }
317
+ return _negative_positive_vine_swap(index);
318
+ }
319
+
320
+ template <class Master_matrix>
321
+ inline bool RU_vine_swap<Master_matrix>::_is_paired(Index columnIndex)
322
+ {
323
+ if constexpr (Master_matrix::Option_list::has_column_pairings) {
324
+ return _get_death(columnIndex) != Master_matrix::template get_null_value<Pos_index>();
325
+ } else {
326
+ if (!_matrix()->reducedMatrixR_.is_zero_column(columnIndex)) return true;
327
+
328
+ if constexpr (Master_matrix::Option_list::has_map_column_container) {
329
+ return _matrix()->pivotToColumnIndex_.find(columnIndex) != _matrix()->pivotToColumnIndex_.end();
330
+ } else {
331
+ if (_matrix()->pivotToColumnIndex_.size() <= columnIndex) return false;
332
+ return _matrix()->pivotToColumnIndex_[columnIndex] != Master_matrix::template get_null_value<Index>();
333
+ }
334
+ }
335
+ }
336
+
337
+ template <class Master_matrix>
338
+ inline void RU_vine_swap<Master_matrix>::_swap_at_index(Index columnIndex)
339
+ {
340
+ _matrix()->reducedMatrixR_.swap_columns(columnIndex, columnIndex + 1);
341
+ _matrix()->reducedMatrixR_.swap_rows(_get_row_id_from_position(columnIndex),
342
+ _get_row_id_from_position(columnIndex + 1));
343
+ _matrix()->mirrorMatrixU_.swap_columns(columnIndex, columnIndex + 1);
344
+ _matrix()->mirrorMatrixU_.swap_rows(_get_row_id_from_position(columnIndex),
345
+ _get_row_id_from_position(columnIndex + 1));
346
+ }
347
+
348
+ template <class Master_matrix>
349
+ inline void RU_vine_swap<Master_matrix>::_add_to(Index sourceIndex, Index targetIndex)
350
+ {
351
+ _matrix()->reducedMatrixR_.add_to(sourceIndex, targetIndex);
352
+ _matrix()->mirrorMatrixU_.add_to(targetIndex, sourceIndex);
353
+ }
354
+
355
+ template <class Master_matrix>
356
+ inline void RU_vine_swap<Master_matrix>::_positive_transpose(Index columnIndex)
357
+ {
358
+ if constexpr (Master_matrix::Option_list::has_map_column_container) {
359
+ if (_is_paired(columnIndex) && _is_paired(columnIndex + 1)) {
360
+ std::swap(_matrix()->pivotToColumnIndex_.at(columnIndex), _matrix()->pivotToColumnIndex_.at(columnIndex + 1));
361
+ } else if (_is_paired(columnIndex)) {
362
+ _matrix()->pivotToColumnIndex_.emplace(columnIndex + 1, _matrix()->pivotToColumnIndex_.at(columnIndex));
363
+ _matrix()->pivotToColumnIndex_.erase(columnIndex);
364
+ } else if (_is_paired(columnIndex + 1)) {
365
+ _matrix()->pivotToColumnIndex_.emplace(columnIndex, _matrix()->pivotToColumnIndex_.at(columnIndex + 1));
366
+ _matrix()->pivotToColumnIndex_.erase(columnIndex + 1);
367
+ }
368
+ } else {
369
+ if (_is_paired(columnIndex) || _is_paired(columnIndex + 1)) {
370
+ if (columnIndex + 1 >= _matrix()->pivotToColumnIndex_.size()) {
371
+ // pivotToColumnIndex_ has at least size columnIndex + 1
372
+ _matrix()->pivotToColumnIndex_.push_back(Master_matrix::template get_null_value<Index>());
373
+ }
374
+ std::swap(_matrix()->pivotToColumnIndex_[columnIndex], _matrix()->pivotToColumnIndex_[columnIndex + 1]);
375
+ }
376
+ }
377
+
378
+ if constexpr (Master_matrix::Option_list::has_column_pairings) {
379
+ _matrix()->_positive_transpose_barcode(columnIndex);
380
+ }
381
+ }
382
+
383
+ template <class Master_matrix>
384
+ inline void RU_vine_swap<Master_matrix>::_negative_transpose(Index columnIndex)
385
+ {
386
+ if constexpr (Master_matrix::Option_list::has_column_pairings) {
387
+ _matrix()->_negative_transpose_barcode(columnIndex);
388
+ }
389
+ if constexpr (Master_matrix::Option_list::has_map_column_container) {
390
+ std::swap(_matrix()->pivotToColumnIndex_.at(_get_birth(columnIndex)),
391
+ _matrix()->pivotToColumnIndex_.at(_get_birth(columnIndex + 1)));
392
+ } else {
393
+ std::swap(_matrix()->pivotToColumnIndex_[_get_birth(columnIndex)],
394
+ _matrix()->pivotToColumnIndex_[_get_birth(columnIndex + 1)]);
395
+ }
396
+ }
397
+
398
+ template <class Master_matrix>
399
+ inline void RU_vine_swap<Master_matrix>::_positive_negative_transpose(Index columnIndex)
400
+ {
401
+ if constexpr (Master_matrix::Option_list::has_map_column_container) {
402
+ _matrix()->pivotToColumnIndex_.at(_get_birth(columnIndex + 1)) = columnIndex;
403
+ if (_is_paired(columnIndex)) {
404
+ _matrix()->pivotToColumnIndex_.emplace(columnIndex + 1, _matrix()->pivotToColumnIndex_.at(columnIndex));
405
+ _matrix()->pivotToColumnIndex_.erase(columnIndex);
406
+ }
407
+ } else {
408
+ _matrix()->pivotToColumnIndex_[_get_birth(columnIndex + 1)] = columnIndex;
409
+ if (_is_paired(columnIndex)){
410
+ if (columnIndex + 1 >= _matrix()->pivotToColumnIndex_.size()) {
411
+ // pivotToColumnIndex_ has at least size columnIndex + 1
412
+ _matrix()->pivotToColumnIndex_.push_back(Master_matrix::template get_null_value<Index>());
413
+ }
414
+ _matrix()->pivotToColumnIndex_[columnIndex + 1] = _matrix()->pivotToColumnIndex_[columnIndex];
415
+ _matrix()->pivotToColumnIndex_[columnIndex] = Master_matrix::template get_null_value<Index>();
416
+ }
417
+ }
418
+
419
+ if constexpr (Master_matrix::Option_list::has_column_pairings) {
420
+ _matrix()->_positive_negative_transpose_barcode(columnIndex);
421
+ }
422
+ }
423
+
424
+ template <class Master_matrix>
425
+ inline void RU_vine_swap<Master_matrix>::_negative_positive_transpose(Index columnIndex)
426
+ {
427
+ if constexpr (Master_matrix::Option_list::has_map_column_container) {
428
+ _matrix()->pivotToColumnIndex_.at(_get_birth(columnIndex)) = columnIndex + 1;
429
+ if (_is_paired(columnIndex + 1)) {
430
+ _matrix()->pivotToColumnIndex_.emplace(columnIndex, _matrix()->pivotToColumnIndex_.at(columnIndex + 1));
431
+ _matrix()->pivotToColumnIndex_.erase(columnIndex + 1);
432
+ }
433
+ } else {
434
+ _matrix()->pivotToColumnIndex_[_get_birth(columnIndex)] = columnIndex + 1;
435
+ if (_is_paired(columnIndex + 1)){
436
+ _matrix()->pivotToColumnIndex_[columnIndex] = _matrix()->pivotToColumnIndex_[columnIndex + 1];
437
+ _matrix()->pivotToColumnIndex_[columnIndex + 1] = Master_matrix::template get_null_value<Index>();
438
+ }
439
+ }
440
+
441
+ if constexpr (Master_matrix::Option_list::has_column_pairings) {
442
+ _matrix()->_negative_positive_transpose_barcode(columnIndex);
443
+ }
444
+ }
445
+
446
+ template <class Master_matrix>
447
+ inline bool RU_vine_swap<Master_matrix>::_positive_vine_swap(Index columnIndex)
448
+ {
449
+ const Pos_index iDeath = _get_death(columnIndex);
450
+ const Pos_index iiDeath = _get_death(columnIndex + 1);
451
+
452
+ if (iDeath != Master_matrix::template get_null_value<Pos_index>() &&
453
+ iiDeath != Master_matrix::template get_null_value<Pos_index>() &&
454
+ !(_matrix()->reducedMatrixR_.is_zero_entry(iiDeath, _get_row_id_from_position(columnIndex)))) {
455
+ if (iDeath < iiDeath) {
456
+ _swap_at_index(columnIndex);
457
+ _add_to(iDeath, iiDeath);
458
+ _positive_transpose(columnIndex);
459
+ return true;
460
+ }
461
+
462
+ _swap_at_index(columnIndex);
463
+ _add_to(iiDeath, iDeath);
464
+ return false;
465
+ }
466
+
467
+ _swap_at_index(columnIndex);
468
+
469
+ if (iDeath != Master_matrix::template get_null_value<Pos_index>() ||
470
+ iiDeath == Master_matrix::template get_null_value<Pos_index>() ||
471
+ _matrix()->reducedMatrixR_.is_zero_entry(iiDeath, _get_row_id_from_position(columnIndex + 1))) {
472
+ _positive_transpose(columnIndex);
473
+ return true;
474
+ }
475
+ return false;
476
+ }
477
+
478
+ template <class Master_matrix>
479
+ inline bool RU_vine_swap<Master_matrix>::_negative_vine_swap(Index columnIndex)
480
+ {
481
+ const Pos_index iBirth = _get_birth(columnIndex);
482
+ const Pos_index iiBirth = _get_birth(columnIndex + 1);
483
+
484
+ _add_to(columnIndex, columnIndex + 1);
485
+ _swap_at_index(columnIndex);
486
+
487
+ if (iBirth < iiBirth) {
488
+ _negative_transpose(columnIndex);
489
+ return true;
490
+ }
491
+
492
+ _add_to(columnIndex, columnIndex + 1);
493
+
494
+ return false;
495
+ }
496
+
497
+ template <class Master_matrix>
498
+ inline bool RU_vine_swap<Master_matrix>::_positive_negative_vine_swap(Index columnIndex)
499
+ {
500
+ _matrix()->mirrorMatrixU_.zero_entry(columnIndex, _get_row_id_from_position(columnIndex + 1));
501
+
502
+ _positive_negative_transpose(columnIndex);
503
+ _swap_at_index(columnIndex);
504
+
505
+ return true;
506
+ }
507
+
508
+ template <class Master_matrix>
509
+ inline bool RU_vine_swap<Master_matrix>::_negative_positive_vine_swap(Index columnIndex)
510
+ {
511
+ _add_to(columnIndex, columnIndex + 1); // useless for R?
512
+ _swap_at_index(columnIndex); // if additions not made for R, do not swap R columns, just rows
513
+ _add_to(columnIndex, columnIndex + 1); // useless for R?
514
+
515
+ return false;
516
+ }
517
+
518
+ template <class Master_matrix>
519
+ inline typename RU_vine_swap<Master_matrix>::Pos_index RU_vine_swap<Master_matrix>::_get_death(Index simplexIndex)
520
+ {
521
+ if constexpr (Master_matrix::Option_list::has_column_pairings) {
522
+ return _matrix()->_death_val(simplexIndex);
523
+ } else {
524
+ if (!_matrix()->reducedMatrixR_.is_zero_column(simplexIndex))
525
+ return _matrix()->reducedMatrixR_.get_column(simplexIndex).get_pivot();
526
+
527
+ if constexpr (Master_matrix::Option_list::has_map_column_container) {
528
+ auto it = _matrix()->pivotToColumnIndex_.find(simplexIndex);
529
+ if (it == _matrix()->pivotToColumnIndex_.end()) return Master_matrix::template get_null_value<Pos_index>();
530
+ return it->second;
531
+ } else {
532
+ if (simplexIndex >= _matrix()->pivotToColumnIndex_.size())
533
+ return Master_matrix::template get_null_value<Pos_index>();
534
+ return _matrix()->pivotToColumnIndex_[simplexIndex];
535
+ }
536
+ }
537
+ }
538
+
539
+ template <class Master_matrix>
540
+ inline typename RU_vine_swap<Master_matrix>::Pos_index RU_vine_swap<Master_matrix>::_get_birth(
541
+ Index negativeSimplexIndex)
542
+ {
543
+ if constexpr (Master_matrix::Option_list::has_column_pairings) {
544
+ return _matrix()->_birth_val(negativeSimplexIndex);
545
+ } else {
546
+ return _matrix()->reducedMatrixR_.get_pivot(negativeSimplexIndex);
547
+ }
548
+ }
549
+
550
+ template <class Master_matrix>
551
+ inline typename RU_vine_swap<Master_matrix>::ID_index RU_vine_swap<Master_matrix>::_get_row_id_from_position(
552
+ Pos_index position) const
553
+ {
554
+ const auto& map = _matrix()->positionToID_;
555
+ auto it = map.find(position);
556
+ return it == map.end() ? position : it->second;
557
+ }
558
+
559
+ } // namespace persistence_matrix
560
+ } // namespace Gudhi
561
+
562
+ #endif // PM_RU_VINE_SWAP_H