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,428 @@
1
+ /* This file is part of the MMA Library -
2
+ * https://gitlab.inria.fr/dloiseau/multipers - which is released under MIT. See
3
+ * file LICENSE for full license details. Author(s): Hannah Schreiber
4
+ *
5
+ * Copyright (C) 2022 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+ #ifndef UTILITIES_H
12
+ #define UTILITIES_H
13
+
14
+ #include <cassert>
15
+ #include <initializer_list>
16
+ #include <limits>
17
+ #include <utility>
18
+ #include <vector>
19
+
20
+ #include "../gudhi/gudhi/multi_simplex_tree_helpers.h"
21
+ #include "../gudhi/gudhi/Multi_persistence/Box.h"
22
+ #include "../gudhi/Persistence_slices_interface.h"
23
+
24
+ namespace Gudhi::multiparameter::mma {
25
+
26
+ constexpr const bool verbose = false;
27
+
28
+ using index = unsigned int;
29
+ using value_type = double;
30
+ using filtration_type = multipers::tmp_interface::Filtration_value<value_type>;
31
+ using multifiltration_type = std::vector<filtration_type>;
32
+ using python_filtration_type = std::vector<value_type>;
33
+ using python_multifiltration_type = std::vector<python_filtration_type>;
34
+
35
+ using dimension_type = int;
36
+ using persistence_pair = std::pair<value_type, value_type>;
37
+ using boundary_type = std::vector<index>;
38
+ using boundary_matrix = std::vector<boundary_type>;
39
+ using permutation_type = std::vector<std::size_t>;
40
+ using point_type = Gudhi::multi_persistence::Box<value_type>::Point_t;
41
+ // using corner_type = Gudhi::multi_filtration::One_critical_filtration<value_type>;
42
+ // using corners_type = std::pair<std::vector<corner_type>, std::vector<corner_type>>;
43
+ // using python_bar =
44
+ // std::pair<std::vector<value_type>,
45
+ // std::vector<value_type>>; // This type is for python
46
+ using multipers_barcode = std::vector<std::vector<value_type>>;
47
+ const value_type inf = std::numeric_limits<value_type>::infinity();
48
+ const value_type negInf = -1 * inf;
49
+ using interval_type = std::pair<point_type, point_type>;
50
+
51
+ // template<typename T>
52
+ // bool is_smaller(const std::vector<T>& x, const std::vector<T>& y)
53
+ // {
54
+ // for (unsigned int i = 0; i < std::min(x.size(), y.size()); i++)
55
+ // if (x[i] > y[i]) return false;
56
+ // return true;
57
+ // }
58
+ // template<typename T>
59
+ // bool is_greater(const std::vector<T>& x, const std::vector<T>& y)
60
+ // {
61
+ // for (unsigned int i = 0; i < std::min(x.size(), y.size()); i++)
62
+ // if (x[i] < y[i]) return false;
63
+ // return true;
64
+ // }
65
+
66
+ struct Bar {
67
+ Bar() : dim(-1), birth(-1), death(-1) {}
68
+
69
+ Bar(dimension_type dim, int birth, int death) : dim(dim), birth(birth), death(death) {}
70
+
71
+ dimension_type dim;
72
+ int birth;
73
+ int death;
74
+ };
75
+
76
+ using barcode_type = std::vector<Bar>;
77
+
78
+ struct Diagram_point {
79
+ Diagram_point() : dim(-1), birth(-1), death(-1) {}
80
+
81
+ Diagram_point(dimension_type dim, value_type birth, value_type death) : dim(dim), birth(birth), death(death) {}
82
+
83
+ dimension_type dim;
84
+ value_type birth;
85
+ value_type death;
86
+ };
87
+
88
+ using diagram_type = std::vector<Diagram_point>;
89
+
90
+ template <typename filtration_type = filtration_type>
91
+ struct MultiDiagram_point {
92
+ public:
93
+ MultiDiagram_point() : dim(-1), birth({}), death({}) {}
94
+
95
+ MultiDiagram_point(dimension_type dim, filtration_type birth, filtration_type death)
96
+ : dim(dim), birth(birth), death(death) {}
97
+
98
+ dimension_type get_dimension() const { return dim; }
99
+
100
+ const filtration_type &get_birth() const { return birth; }
101
+
102
+ const filtration_type &get_death() const { return death; }
103
+
104
+ private:
105
+ dimension_type dim;
106
+ filtration_type birth;
107
+ filtration_type death;
108
+ };
109
+
110
+ template <typename filtration_type, typename value_type>
111
+ struct MultiDiagram { // for python interface
112
+ static_assert(std::is_same_v<typename filtration_type::value_type, value_type>,
113
+ "filtration_type and value_type must be the same");
114
+
115
+ public:
116
+ using iterator = typename std::vector<MultiDiagram_point<filtration_type>>::const_iterator;
117
+
118
+ MultiDiagram() {}
119
+
120
+ MultiDiagram(std::vector<MultiDiagram_point<filtration_type>> &m) : multiDiagram(m) {}
121
+
122
+ using python_fil = std::vector<typename filtration_type::value_type>;
123
+ using python_bar = std::pair<python_fil, python_fil>; // This type is for python
124
+
125
+ std::vector<python_bar> get_points(const dimension_type dimension = -1) const { // dump for python interface
126
+ std::vector<python_bar> out;
127
+ out.reserve(multiDiagram.size());
128
+ for (const MultiDiagram_point<filtration_type> &pt : multiDiagram) {
129
+ if (dimension == -1 || pt.get_dimension() == dimension) {
130
+ if (pt.get_birth().num_generators() > 0 && pt.get_death().num_generators() > 0 &&
131
+ !pt.get_birth().is_plus_inf() && !pt.get_death().is_minus_inf()) {
132
+ const auto &b = pt.get_birth();
133
+ const auto &d = pt.get_death();
134
+ assert(b.num_parameters() == d.num_parameters());
135
+ python_fil first(b.num_parameters());
136
+ python_fil second(b.num_parameters());
137
+ for (unsigned int i = 0; i < b.num_parameters(); ++i) {
138
+ first[i] = b(0, i);
139
+ second[i] = d(0, i);
140
+ }
141
+ out.push_back(std::make_pair(std::move(first), std::move(second)));
142
+ }
143
+ }
144
+ }
145
+ /* out.shrink_to_fit(); */
146
+ return out;
147
+ }
148
+
149
+ std::vector<std::vector<double>> to_multipers(
150
+ const dimension_type dimension = -1) const { // dump for python interface
151
+ std::vector<std::vector<double>> out;
152
+ out.reserve(multiDiagram.size());
153
+ for (const MultiDiagram_point<filtration_type> &pt : multiDiagram) {
154
+ if (dimension == -1 || pt.get_dimension() == dimension) {
155
+ const auto &b = pt.get_birth();
156
+ const auto &d = pt.get_death();
157
+ assert(!(b.is_plus_inf() || b.is_minus_inf() || d.is_plus_inf() || d.is_minus_inf()));
158
+ out.emplace_back(std::initializer_list<double>{b(0, 0), d(0, 0), b(0, 1), d(0, 1)});
159
+ }
160
+ }
161
+ out.shrink_to_fit();
162
+ return out;
163
+ }
164
+
165
+ iterator begin() const { return this->multiDiagram.begin(); }
166
+
167
+ iterator end() const { return this->multiDiagram.end(); }
168
+
169
+ unsigned int size() { return this->multiDiagram.size(); }
170
+
171
+ void set(std::vector<MultiDiagram_point<filtration_type>> &m) { this->multiDiagram.swap(m); }
172
+
173
+ std::vector<MultiDiagram_point<filtration_type>> &getref() { return this->multiDiagram; }
174
+
175
+ MultiDiagram_point<filtration_type> &operator[](unsigned int i) { return this->multiDiagram[i]; }
176
+
177
+ MultiDiagram_point<filtration_type> &at(const unsigned int i) { return multiDiagram[i]; }
178
+
179
+ private:
180
+ std::vector<MultiDiagram_point<filtration_type>> multiDiagram;
181
+ };
182
+
183
+ template <typename filtration_type, typename value_type>
184
+ struct MultiDiagrams {
185
+ static_assert(std::is_same_v<typename filtration_type::value_type, value_type>,
186
+ "filtration_type and value_type must be the same");
187
+
188
+ public:
189
+ using iterator = typename std::vector<MultiDiagram<filtration_type, value_type>>::const_iterator;
190
+ using nciterator = typename std::vector<MultiDiagram<filtration_type, value_type>>::iterator;
191
+
192
+ MultiDiagrams() {}
193
+
194
+ MultiDiagrams(unsigned int size) : multiDiagrams(size) {}
195
+
196
+ std::vector<std::vector<std::vector<double>>> to_multipers() {
197
+ unsigned int nsummands = this->multiDiagrams.front().size();
198
+ unsigned int nlines = this->multiDiagrams.size();
199
+ // std::vector<std::vector<std::vector<double>>> out(nsummands,
200
+ // std::vector<std::vector<double>>(nlines, std::vector<double>(5)));
201
+ std::vector<std::vector<std::vector<double>>> out(nsummands);
202
+ for (unsigned int i = 0; i < nsummands; i++) {
203
+ out[i].reserve(nlines);
204
+ for (unsigned int j = 0; j < nlines; j++) {
205
+ const MultiDiagram_point<filtration_type> &pt = this->multiDiagrams[j][i];
206
+ /* if(pt.get_birth().is_plus_inf() || pt.get_death().is_minus_inf()) */
207
+ /* out[i].push_back({0, 0, 0, 0,static_cast<value_type>(j)}); */
208
+ /* else */
209
+ double a, b, c, d;
210
+ double inf = std::numeric_limits<double>::infinity();
211
+ if (pt.get_birth().is_plus_inf()) {
212
+ a = 0;
213
+ b = 0;
214
+ } else if (pt.get_birth().is_minus_inf()) {
215
+ a = -inf;
216
+ b = -inf;
217
+ } else {
218
+ a = pt.get_birth()(0, 0);
219
+ b = pt.get_birth()(0, 1);
220
+ }
221
+ if (pt.get_death().is_plus_inf()) {
222
+ c = inf;
223
+ d = inf;
224
+ }
225
+ if (pt.get_death().is_minus_inf()) {
226
+ c = 0;
227
+ d = 0;
228
+ } else {
229
+ c = pt.get_death()(0, 0);
230
+ d = pt.get_death()(0, 1);
231
+ }
232
+ /* out[i].push_back({pt.get_birth()[0], pt.get_death()[0],
233
+ * pt.get_birth()[1], pt.get_death()[1],static_cast<value_type>(j)}); */
234
+ out[i].push_back({a, c, b, d, static_cast<double>(j)});
235
+ }
236
+ }
237
+ return out;
238
+ }
239
+
240
+ using _for_python_plot_type = std::pair<std::vector<std::pair<double, double>>, std::vector<unsigned int>>;
241
+
242
+ _for_python_plot_type _for_python_plot(dimension_type dimension = -1, value_type min_persistence = 0) {
243
+ _for_python_plot_type out;
244
+ auto &bars = out.first;
245
+ auto &summand_idx = out.second;
246
+ bars.reserve(this->multiDiagrams.size() * this->multiDiagrams[0].size() * 2);
247
+ summand_idx.reserve(this->multiDiagrams.size() * this->multiDiagrams[0].size());
248
+ for (const MultiDiagram<filtration_type, value_type> &multiDiagram : this->multiDiagrams) {
249
+ unsigned int count = 0;
250
+ for (const MultiDiagram_point<filtration_type> &bar : multiDiagram) {
251
+ const auto &birth = bar.get_birth();
252
+ const auto &death = bar.get_death();
253
+ if ((dimension == -1 || bar.get_dimension() == dimension) && birth.is_finite() && death.is_finite() &&
254
+ (death(0, 0) > birth(0, 0) + min_persistence)) {
255
+ // Checking is_finite ensures that filtration is not inf or -inf or nan.
256
+ bars.push_back(std::pair<double, double>(birth(0, 0), death(0, 0)));
257
+ bars.push_back(std::pair<double, double>(birth(0, 1), death(0, 1)));
258
+ summand_idx.push_back(count);
259
+ }
260
+ count++;
261
+ }
262
+ }
263
+ return out;
264
+ }
265
+
266
+ MultiDiagram<filtration_type, value_type> &operator[](const unsigned int i) { return multiDiagrams[i]; }
267
+
268
+ MultiDiagram<filtration_type, value_type> &at(const unsigned int i) { return multiDiagrams[i]; }
269
+
270
+ iterator begin() const { return this->multiDiagrams.begin(); } // cython bug : iterators like bc in bcs crash)
271
+
272
+ iterator end() const { return this->multiDiagrams.end(); }
273
+
274
+ using python_fil = std::vector<value_type>;
275
+ using python_bar = std::pair<std::vector<value_type>,
276
+ std::vector<value_type>>; // This type is for python
277
+ using barcodes = std::vector<std::vector<python_bar>>;
278
+
279
+ barcodes get_points() {
280
+ unsigned int nsummands = this->multiDiagrams.front().size();
281
+ unsigned int nlines = this->multiDiagrams.size();
282
+ // std::vector<std::vector<std::vector<double>>> out(nsummands,
283
+ // std::vector<std::vector<double>>(nlines, std::vector<double>(5)));
284
+ barcodes out(nlines, std::vector<python_bar>(nsummands));
285
+ for (unsigned int i = 0; i < nlines; i++) {
286
+ for (unsigned int j = 0; j < nsummands; j++) {
287
+ const MultiDiagram_point<filtration_type> &pt = this->multiDiagrams[i][j];
288
+ const auto &b = pt.get_birth();
289
+ const auto &d = pt.get_death();
290
+ assert(b.num_parameters() == d.num_parameters());
291
+ python_fil first(b.num_parameters());
292
+ python_fil second(b.num_parameters());
293
+ for (unsigned int i = 0; i < b.num_parameters(); ++i) {
294
+ first[i] = b(0, i);
295
+ second[i] = d(0, i);
296
+ }
297
+ out[i][j] = std::make_pair(std::move(first), std::move(second));
298
+ }
299
+ }
300
+ return out;
301
+ }
302
+
303
+ unsigned int size() const { return this->multiDiagrams.size(); }
304
+
305
+ private:
306
+ std::vector<MultiDiagram<filtration_type, value_type>> multiDiagrams;
307
+ /* inline bool _is_inf(const std::vector<value_type> &truc) const{ */
308
+ /* for (const auto coord : truc) */
309
+ /* if (coord != inf) return false; */
310
+ /* return true; */
311
+ /* } */
312
+ /* inline bool _is_negInf(const std::vector<value_type> &truc) const{ */
313
+ /* for (const auto coord : truc) */
314
+ /* if (coord != negInf) return false; */
315
+ /* return true; */
316
+ /* } */
317
+ };
318
+
319
+ void inline threshold_up(point_type &point,
320
+ const Gudhi::multi_persistence::Box<value_type> &box,
321
+ const point_type &basepoint) {
322
+ point_type point_(point);
323
+ // if (is_smaller(point, box.get_upper_corner())) return;
324
+ if (point_ <= box.get_upper_corner()) return;
325
+
326
+ // if (verbose && Debug::debug) Debug::disp_vect(point);
327
+
328
+ if (basepoint[0] == negInf) [[unlikely]]
329
+ return;
330
+
331
+ // ie. point at infinity, assumes [basepoint,0] is smaller than box.second
332
+ if (point.back() == inf) [[unlikely]] {
333
+ // if (verbose) std::cout << " Infinite point" << std::endl;
334
+
335
+ value_type threshold = box.get_upper_corner().back();
336
+ for (unsigned int i = 0; i < point.size(); i++) {
337
+ threshold = std::min(threshold, box.get_upper_corner()[i] - basepoint[i]);
338
+ }
339
+ for (unsigned int i = 0; i < point.size() - 1; i++) point[i] = basepoint[i] + threshold;
340
+ point.back() = threshold;
341
+
342
+ return;
343
+ }
344
+
345
+ // if (!is_greater(point, box.get_lower_corner())) {
346
+ if (box.get_lower_corner() <= point_) {
347
+ point[0] = inf; // puts point to infinity
348
+ // if (verbose) std::cout << "buggy point" << std::endl;
349
+ return;
350
+ }
351
+ // in this last case, at least 1 coord of point is is_greater than a coord of
352
+ // box.second
353
+
354
+ value_type threshold = point[0] - box.get_upper_corner()[0];
355
+ for (std::size_t i = 1; i < point.size(); i++) {
356
+ threshold = std::max(threshold, point[i] - box.get_upper_corner()[i]);
357
+ }
358
+
359
+ // if (verbose)
360
+ // std::cout << "Thresholding the point with "<< threshold << " at
361
+ // ";
362
+
363
+ for (std::size_t i = 0; i < point.size(); i++) point[i] -= threshold;
364
+
365
+ // if (verbose && Debug::debug) Debug::disp_vect(point);
366
+ }
367
+
368
+ /**
369
+ * @brief Threshold a point to the positive cone of b=box.first
370
+ * (ie. the set \f$\{x \in \mathbb R^n \mid x \ge b\})
371
+ * along the slope 1 line crossing this point.
372
+ *
373
+ * @param point The point to threshold.
374
+ * @param box box.fist is the point defining where to threshold.
375
+ * @param basepoint Basepoint of the slope 1 line crossing the point.
376
+ * Meant to handle infinite cases (when the point have infinite coordinates,
377
+ * we cannot infer the line).
378
+ */
379
+
380
+ void inline threshold_down(point_type &point,
381
+ const Gudhi::multi_persistence::Box<value_type> &box,
382
+ const point_type &basepoint) {
383
+ if (basepoint[0] == negInf) [[unlikely]]
384
+ return;
385
+
386
+ if (point.back() == inf) [[unlikely]] { // ie. point at infinity -> feature never appearing
387
+ return;
388
+ }
389
+
390
+ // if (is_greater(point, box.get_lower_corner())) return;
391
+ if (point >= box.get_lower_corner()) return;
392
+
393
+ // if (!is_smaller(point, box.get_upper_corner())) {
394
+ if (!(point <= box.get_upper_corner())) {
395
+ point[0] = inf; // puts point to infinity
396
+ return;
397
+ }
398
+
399
+ value_type threshold = box.get_lower_corner()[0] - point[0];
400
+ for (unsigned int i = 1; i < point.size(); i++) {
401
+ threshold = std::max(threshold, box.get_lower_corner()[i] - point[i]);
402
+ }
403
+ for (unsigned int i = 0; i < point.size(); i++) point[i] += threshold;
404
+ }
405
+
406
+
407
+
408
+ } // namespace Gudhi::multiparameter::mma
409
+
410
+ //// Different implementations of the matrix columns. Set seems to be the
411
+ /// fastest / in our tests. / using Vineyard_matrix_type =
412
+ /// RU_matrix<Heap_column>; / using Vineyard_matrix_type =
413
+ /// RU_matrix<List_column>; / using Vineyard_matrix_type =
414
+ /// RU_matrix<Vector_column>; / using Vineyard_matrix_type =
415
+ /// RU_matrix<Unordered_set_column>;
416
+ // #include "ru_matrix.h"
417
+ ///*#include "heap_column.h"*/
418
+ ///*#include "list_column.h"*/
419
+ //// #include "list_column_2.h"
420
+ ///*#include "vector_column.h"*/
421
+ // #include "set_column.h"
422
+ ///*#include "unordered_set_column.h"*/
423
+ //
424
+ // namespace Gudhi::multiparameter::mma {
425
+ // using Vineyard_matrix_type = RU_matrix<Set_column>;
426
+ //}
427
+
428
+ #endif // UTILITIES_H