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,233 @@
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
+ * - 2024/08 Hannah Schreiber: documentation
9
+ * - 2025/03 Hannah Schreiber: Change of point types.
10
+ * - YYYY/MM Author: Description of the modification
11
+ */
12
+
13
+ /**
14
+ * @file Box.h
15
+ * @author David Loiseaux
16
+ * @brief Contains the @ref Gudhi::multi_persistence::Box class.
17
+ */
18
+
19
+ #ifndef MP_BOX_H_INCLUDED
20
+ #define MP_BOX_H_INCLUDED
21
+
22
+ #include <ostream> //std::ostream
23
+
24
+ #include <gudhi/Debug_utils.h>
25
+ #include <gudhi/Multi_persistence/Point.h>
26
+ #include <gudhi/Multi_filtration/multi_filtration_utils.h>
27
+
28
+ namespace Gudhi {
29
+ namespace multi_persistence {
30
+
31
+ /**
32
+ * @class Box Box.h gudhi/Multi_persistence/Box.h
33
+ * @ingroup multi_persistence
34
+ *
35
+ * @brief Simple box in \f$\mathbb R^n\f$ defined by two diametrically opposite corners.
36
+ *
37
+ * @tparam T Type of the coordinates of the Box.
38
+ */
39
+ template <typename T>
40
+ class Box
41
+ {
42
+ public:
43
+ using Point_t = Point<T>; /**< Type of a point in \f$\mathbb R^n\f$. */
44
+
45
+ /**
46
+ * @brief Default constructor. Constructs a trivial box with corners at minus infinity.
47
+ */
48
+ Box() = default;
49
+
50
+ /**
51
+ * @brief Constructs a box from the two given corners. Assumes that \f$ lowerCorner \le @p upperCorner \f$ and
52
+ * if both are finite values, they have the same dimension.
53
+ *
54
+ * @param lowerCorner First corner of the box. Has to be smaller than `upperCorner`.
55
+ * @param upperCorner Second corner of the box. Has to be greater than `lowerCorner`.
56
+ */
57
+ Box(const Point_t &lowerCorner, const Point_t &upperCorner) : lowerCorner_(lowerCorner), upperCorner_(upperCorner)
58
+ {
59
+ GUDHI_CHECK(lowerCorner.size() == upperCorner.size(),
60
+ std::invalid_argument("The two corners of the box don't have the same dimension."));
61
+ // GUDHI_CHECK(lowerCorner <= upperCorner, std::invalid_argument("The first corner is not smaller than the
62
+ // second."));
63
+ }
64
+
65
+ /**
66
+ * @brief Constructs a box from the two given corners. Assumes that \f$ box.first \le @p box.second \f$ and
67
+ * if both are finite values, they have the same dimension.
68
+ *
69
+ * @param box Pair of corners defining the wished box.
70
+ */
71
+ Box(const std::pair<Point_t, Point_t> &box) : Box(box.first, box.second) {}
72
+
73
+ /**
74
+ * @brief Returns the lowest of both defining corners.
75
+ */
76
+ const Point_t &get_lower_corner() const { return lowerCorner_; }
77
+
78
+ /**
79
+ * @brief Returns the lowest of both defining corners.
80
+ */
81
+ Point_t &get_lower_corner() { return lowerCorner_; }
82
+
83
+ /**
84
+ * @brief Returns the greatest of both defining corners.
85
+ */
86
+ Point_t &get_upper_corner() { return upperCorner_; }
87
+
88
+ /**
89
+ * @brief Returns the greatest of both defining corners.
90
+ */
91
+ const Point_t &get_upper_corner() const { return upperCorner_; }
92
+
93
+ /**
94
+ * @brief Returns a pair of const references to both defining corners.
95
+ */
96
+ std::pair<const Point_t &, const Point_t &> get_bounding_corners() const { return {lowerCorner_, upperCorner_}; }
97
+
98
+ /**
99
+ * @brief Returns a pair of references to both defining corners.
100
+ */
101
+ std::pair<Point_t &, Point_t &> get_bounding_corners() { return {lowerCorner_, upperCorner_}; }
102
+
103
+ /**
104
+ * @brief Returns true if and only if one of the following is true:
105
+ * - one of the corners is empty
106
+ * - one of the corners contains the value NaN
107
+ * - both corners have value infinity
108
+ * - both corners have value minus infinity
109
+ *
110
+ * Throws if both corners don't have the same dimension.
111
+ */
112
+ [[nodiscard]] bool is_trivial() const
113
+ {
114
+ if (lowerCorner_.size() == 0 || upperCorner_.size() == 0) return true;
115
+ if (lowerCorner_.size() != upperCorner_.size())
116
+ throw std::logic_error("Upper and lower corner do not have the same dimension");
117
+
118
+ T inf = Point_t::T_inf;
119
+ T m_inf = Point_t::T_m_inf;
120
+
121
+ bool lowerIsInf = true, lowerIsMinusInf = true;
122
+ bool upperIsInf = true, upperIsMinusInf = true;
123
+ for (unsigned int i = 0; i < lowerCorner_.size(); ++i) {
124
+ T lc = lowerCorner_[i];
125
+ T uc = upperCorner_[i];
126
+ if (Gudhi::multi_filtration::_is_nan(lc) || Gudhi::multi_filtration::_is_nan(uc)) return true;
127
+ if (lc != inf) lowerIsInf = false;
128
+ if (lc != m_inf) lowerIsMinusInf = false;
129
+ if (uc != inf) upperIsInf = false;
130
+ if (uc != m_inf) upperIsMinusInf = false;
131
+ if ((!lowerIsInf && !lowerIsMinusInf) || (!upperIsInf && !upperIsMinusInf)) return false;
132
+ }
133
+ return (lowerIsInf && upperIsInf) || (lowerIsMinusInf && upperIsMinusInf);
134
+ }
135
+
136
+ /**
137
+ * @brief Returns true if and only if the given point is inside the box.
138
+ */
139
+ bool contains(const Point_t &point) const
140
+ {
141
+ GUDHI_CHECK(point.size() == lowerCorner_.size(),
142
+ std::invalid_argument("Point should not have a different dimension than the box."));
143
+
144
+ for (unsigned int i = 0; i < point.size(); ++i) {
145
+ T lc = lowerCorner_[i];
146
+ T uc = upperCorner_[i];
147
+ T p = point[i];
148
+ if (Gudhi::multi_filtration::_is_nan(p) || Gudhi::multi_filtration::_is_nan(lc) ||
149
+ Gudhi::multi_filtration::_is_nan(uc))
150
+ return false;
151
+ if (lc > p || uc < p) return false;
152
+ }
153
+ return true;
154
+ }
155
+
156
+ /**
157
+ * @brief Returns the dimension of the box.
158
+ */
159
+ [[nodiscard]] std::size_t get_dimension() const { return lowerCorner_.size(); }
160
+
161
+ /**
162
+ * @brief Inflates the box by delta.
163
+ *
164
+ * @param delta Inflation coefficient.
165
+ */
166
+ void inflate(T delta)
167
+ {
168
+ lowerCorner_ -= delta;
169
+ upperCorner_ += delta;
170
+ }
171
+
172
+ /**
173
+ * @brief Equality operator. Two boxes are equal if and only if both defining corners are equal.
174
+ */
175
+ friend bool operator==(const Box &a, const Box &b)
176
+ {
177
+ return a.upperCorner_ == b.upperCorner_ && a.lowerCorner_ == b.lowerCorner_;
178
+ }
179
+
180
+ /**
181
+ * @brief Unequality operator. Two boxes are equal if and only if both defining corners are equal.
182
+ */
183
+ friend bool operator!=(const Box &a, const Box &b) { return !(a == b); }
184
+
185
+ /**
186
+ * @brief Outstream operator.
187
+ */
188
+ friend std::ostream &operator<<(std::ostream &os, const Box &box)
189
+ {
190
+ os << "Box -- Bottom corner : ";
191
+ os << box.get_lower_corner();
192
+ os << ", Top corner : ";
193
+ os << box.get_upper_corner();
194
+ return os;
195
+ }
196
+
197
+ /**
198
+ * @brief Returns the smallest box enclosing both given boxes. Both boxes have to have the same dimension.
199
+ * If one of the boxes is trivial, returns the other box. If both are trivial, returns an empty box.
200
+ */
201
+ friend Box get_smallest_enclosing_box(const Box &a, const Box &b)
202
+ {
203
+ if (a.is_trivial()) {
204
+ if (b.is_trivial()) return Box();
205
+ return b;
206
+ }
207
+ if (b.is_trivial()) return a;
208
+
209
+ GUDHI_CHECK(a.get_dimension() == b.get_dimension(), "Both boxes to enclose do not have the same dimension.");
210
+
211
+ Point_t lower(a.get_dimension());
212
+ Point_t upper(a.get_dimension());
213
+ const auto &aLower = a.get_lower_corner();
214
+ const auto &aUpper = a.get_upper_corner();
215
+ const auto &bLower = b.get_lower_corner();
216
+ const auto &bUpper = b.get_upper_corner();
217
+ for (unsigned int i = 0; i < a.get_dimension(); ++i) {
218
+ lower[i] = std::min(aLower[i], bLower[i]);
219
+ upper[i] = std::max(aUpper[i], bUpper[i]);
220
+ }
221
+
222
+ return Box(lower, upper);
223
+ }
224
+
225
+ private:
226
+ Point_t lowerCorner_; /**< Lowest of defining corners. */
227
+ Point_t upperCorner_; /**< Greatest of defining corners. */
228
+ };
229
+
230
+ } // namespace multi_persistence
231
+ } // namespace Gudhi
232
+
233
+ #endif // MP_BOX_H_INCLUDED
@@ -0,0 +1,309 @@
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
+ * - 2024/08 Hannah Schreiber: documentation
9
+ * - 2025/03 Hannah Schreiber: Change of point types.
10
+ * - YYYY/MM Author: Description of the modification
11
+ */
12
+
13
+ /**
14
+ * @file Line.h
15
+ * @author David Loiseaux
16
+ * @brief Contains the @ref Gudhi::multi_persistence::Line class.
17
+ */
18
+
19
+ #ifndef MP_LINE_FILTRATION_H_INCLUDED
20
+ #define MP_LINE_FILTRATION_H_INCLUDED
21
+
22
+ #include <cmath>
23
+ #include <cstddef>
24
+ #include <stdexcept>
25
+
26
+ #include <gudhi/Debug_utils.h>
27
+ #include <gudhi/Multi_persistence/Box.h>
28
+ #include <gudhi/Multi_persistence/Point.h>
29
+ #include <gudhi/Multi_filtration/multi_filtration_utils.h>
30
+
31
+ namespace Gudhi {
32
+ namespace multi_persistence {
33
+
34
+ /**
35
+ * @class Line Line.h gudhi/Multi_persistence/Line.h
36
+ * @ingroup multi_persistence
37
+ *
38
+ * @brief A line in \f$\mathbb R^n\f$, with some helpers to project points on it.
39
+ *
40
+ * @tparam T Type of the coordinate values.
41
+ */
42
+ template <typename T>
43
+ class Line
44
+ {
45
+ public:
46
+ /**
47
+ * @brief Coordinates in \f$\mathbb R^n\f$.
48
+ */
49
+ using Point_t = Point<T>;
50
+
51
+ /**
52
+ * @brief Default constructor. Sets the number of coordinates to 0.
53
+ */
54
+ Line() = default;
55
+
56
+ /**
57
+ * @brief Constructs a line going through the given point with slope 1.
58
+ *
59
+ * @param x A point of the line.
60
+ */
61
+ Line(const Point_t &x) : basePoint_(x), direction_() {} // default direction
62
+
63
+ /**
64
+ * @brief Constructs a line going through the given point with slope 1.
65
+ *
66
+ * @param x A point of the line. Will be moved.
67
+ */
68
+ Line(Point_t &&x) : basePoint_(std::move(x)), direction_() {} // default direction
69
+
70
+ /**
71
+ * @brief Constructs a line going through the given point in the direction of the given vector.
72
+ * If the vector has no coordinates, the slope is assumed to be 1.
73
+ * Otherwise, the vector has to be non trivial and all its coordinates have to be positive.
74
+ *
75
+ * @param x A point of the line.
76
+ * @param vector Direction of the line. Positive and non trivial.
77
+ */
78
+ Line(const Point_t &x, const Point_t &vector) : basePoint_(x), direction_(vector) { _check_direction(); }
79
+
80
+ /**
81
+ * @brief Returns the coordinates of the point on the line with "time" parameter `t`. That is, the point \f$ x \f$
82
+ * such that \f$ x[i] = base\_point[i] + t \times direction[i] \f$ for all \f$ i \in [0, n - 1] \f$ with \f$ n \f$
83
+ * the number of coordinates.
84
+ */
85
+ Point_t operator[](T t) const
86
+ {
87
+ GUDHI_CHECK(direction_.size() == 0 || direction_.size() == basePoint_.size(),
88
+ "Direction and base point do not have the same dimension.");
89
+
90
+ if (Gudhi::multi_filtration::_is_nan(t) || t == Point_t::T_inf || t == Point_t::T_m_inf)
91
+ return Point_t(basePoint_.size(), t);
92
+
93
+ Point_t x(basePoint_.size());
94
+
95
+ if (direction_.size() > 0) {
96
+ for (std::size_t i = 0; i < x.size(); i++) x[i] = basePoint_[i] + t * direction_[i];
97
+ } else
98
+ for (std::size_t i = 0; i < x.size(); i++) x[i] = basePoint_[i] + t;
99
+
100
+ return x;
101
+ }
102
+
103
+ /**
104
+ * @brief Translates the given line in the given direction.
105
+ */
106
+ friend Line &operator+=(Line &to_translate, const Point_t &v)
107
+ {
108
+ to_translate.basePoint_ += v;
109
+ return to_translate;
110
+ }
111
+
112
+ /**
113
+ * @brief Returns a reference to the current base point of the line.
114
+ */
115
+ Point_t &base_point() { return basePoint_; }
116
+
117
+ /**
118
+ * @brief Returns a const reference to the current base point of the line.
119
+ */
120
+ const Point_t &base_point() const { return basePoint_; }
121
+
122
+ /**
123
+ * @brief Returns a reference to the direction vector of the line.
124
+ */
125
+ Point_t &direction() { return direction_; }
126
+
127
+ /**
128
+ * @brief Returns a const reference to the direction vector of the line.
129
+ */
130
+ const Point_t &direction() const { return direction_; }
131
+
132
+ /**
133
+ * @brief Computes the "time" parameter \f$ t \f$ of the starting point \f$ p = base\_point + t \times direction \f$
134
+ * of the intersection between the line and the closed positive cone originating at point `x`.
135
+ *
136
+ * @tparam U Type of the time parameter.
137
+ * @param x Origin of the closed positive cone.
138
+ */
139
+ template <typename U = T>
140
+ U compute_forward_intersection(const Point_t &x) const
141
+ {
142
+ GUDHI_CHECK(basePoint_.size() == x.size(), "x has not as many parameters as the line.");
143
+
144
+ constexpr const U inf = Point<U>::T_inf;
145
+
146
+ U t = Point<U>::T_m_inf;
147
+ for (unsigned int p = 0; p < x.size(); ++p) {
148
+ if (Gudhi::multi_filtration::_is_nan(x[p])) return inf;
149
+ auto div = direction_.size() == 0 ? 1 : direction_[p];
150
+ if (div == 0) {
151
+ if (x[p] > basePoint_[p]) return inf;
152
+ } else {
153
+ t = std::max(t, (static_cast<U>(x[p]) - static_cast<U>(basePoint_[p])) / static_cast<U>(div));
154
+ }
155
+ }
156
+
157
+ return t;
158
+ }
159
+
160
+ /**
161
+ * @brief Computes the "time" parameter \f$ t \f$ of the starting point \f$ p = base\_point + t \times direction \f$
162
+ * of the intersection between the line and the union of closed positive cones originating at
163
+ * multi-parameter filtration value `x`. If `x` contains a NaN value, returns +infinity.
164
+ *
165
+ * @tparam U Type of the time parameter.
166
+ * @tparam FiltrationValue Type of a multi-parameter filtration value. Has to implement the following methods:
167
+ * `num_parameters`, `num_generators`, `operator()(generator_index, parameter_index)`.
168
+ * See @ref Gudhi::multi_filtration::Multi_parameter_filtration for an example.
169
+ * @param x Origin of the closed positive cones.
170
+ */
171
+ template <typename U = T, class FiltrationValue>
172
+ U compute_forward_intersection(const FiltrationValue &x) const
173
+ {
174
+ GUDHI_CHECK(basePoint_.size() == x.num_parameters(), "x has not as many parameters as the line.");
175
+
176
+ constexpr const U inf = Point<U>::T_inf;
177
+
178
+ U t = inf;
179
+ for (unsigned int g = 0; g < x.num_generators(); ++g) {
180
+ U tmp = Point<U>::T_m_inf;
181
+ for (unsigned int p = 0; p < x.num_parameters(); ++p) {
182
+ if (Gudhi::multi_filtration::_is_nan(x(g, p))) return inf;
183
+ auto div = direction_.size() == 0 ? 1 : direction_[p];
184
+ if (div == 0) {
185
+ if (x(g, p) > basePoint_[p]) tmp = inf;
186
+ } else {
187
+ tmp = std::max(tmp, (static_cast<U>(x(g, p)) - static_cast<U>(basePoint_[p])) / static_cast<U>(div));
188
+ }
189
+ }
190
+ t = std::min(t, tmp);
191
+ }
192
+
193
+ return t;
194
+ }
195
+
196
+ /**
197
+ * @brief Computes the "time" parameter \f$ t \f$ of the starting point \f$ p = base\_point + t \times direction \f$
198
+ * of the intersection between the line and the open negative cone originating at point `x`.
199
+ *
200
+ * @tparam U Type of the time parameter.
201
+ * @param x Origin of the open negative cone.
202
+ */
203
+ template <typename U = T>
204
+ U compute_backward_intersection(const Point_t &x) const
205
+ {
206
+ GUDHI_CHECK(basePoint_.size() == x.size(), "x has not as many parameters as the line.");
207
+
208
+ constexpr const U m_inf = Point<U>::T_m_inf;
209
+
210
+ U t = Point<U>::T_inf;
211
+ for (unsigned int p = 0; p < x.size(); ++p) {
212
+ if (Gudhi::multi_filtration::_is_nan(x[p])) return m_inf;
213
+ auto div = direction_.size() == 0 ? 1 : direction_[p];
214
+ if (div == 0) {
215
+ if (x[p] <= basePoint_[p]) return m_inf;
216
+ } else {
217
+ t = std::min(t, (static_cast<U>(x[p]) - static_cast<U>(basePoint_[p])) / static_cast<U>(div));
218
+ }
219
+ }
220
+
221
+ return t;
222
+ }
223
+
224
+ /**
225
+ * @brief Computes the "time" parameter \f$ t \f$ of the starting point \f$ p = base\_point + t \times direction \f$
226
+ * of the intersection between the line and the union of open negative cones originating at
227
+ * multi-parameter filtration value `x`. If `x` contains a NaN value, returns -infinity.
228
+ *
229
+ * @tparam U Type of the time parameter.
230
+ * @tparam FiltrationValue Type of a multi-parameter filtration value. Has to implement the following methods:
231
+ * `num_parameters`, `num_generators`, `operator()(generator_index, parameter_index)`.
232
+ * @param x Origin of the open negative cones.
233
+ */
234
+ template <typename U = T, class FiltrationValue>
235
+ U compute_backward_intersection(const FiltrationValue &x) const
236
+ {
237
+ GUDHI_CHECK(basePoint_.size() == x.num_parameters(), "x has not as many parameters as the line.");
238
+
239
+ constexpr const U m_inf = Point<U>::T_m_inf;
240
+
241
+ U t = m_inf;
242
+ for (unsigned int g = 0; g < x.num_generators(); ++g) {
243
+ U tmp = Point<U>::T_inf;
244
+ for (unsigned int p = 0; p < x.num_parameters(); ++p) {
245
+ if (Gudhi::multi_filtration::_is_nan(x(g, p))) return m_inf;
246
+ auto div = direction_.size() == 0 ? 1 : direction_[p];
247
+ if (div == 0) {
248
+ if (x(g, p) <= basePoint_[p]) tmp = m_inf;
249
+ } else {
250
+ tmp = std::min(tmp, (static_cast<U>(x(g, p)) - static_cast<U>(basePoint_[p])) / static_cast<U>(div));
251
+ }
252
+ }
253
+ t = std::max(t, tmp);
254
+ }
255
+
256
+ return t;
257
+ }
258
+
259
+ /**
260
+ * @brief Given a box, returns "time" parameter of the intersection of this box and the line.
261
+ *
262
+ * @param box Box to intersect.
263
+ * @return A pair representing the two bounding points of the intersection, such that the first element is the
264
+ * smallest of the two. If the box and the line do not intersect or the box is trivial, returns the pair {inf, -inf}.
265
+ */
266
+ std::pair<T, T> get_bounds(const Box<T> &box) const
267
+ {
268
+ if (box.is_trivial()) return {Point_t::T_inf, Point_t::T_m_inf};
269
+
270
+ T bottom = compute_forward_intersection(box.get_lower_corner());
271
+ T top = compute_backward_intersection(box.get_upper_corner());
272
+
273
+ if (bottom > top) return {Point_t::T_inf, Point_t::T_m_inf}; // no intersection
274
+
275
+ return {bottom, top};
276
+ }
277
+
278
+ private:
279
+ Point_t basePoint_; /**< Any point on the line. */
280
+ Point_t direction_; /**< Direction of the line. */
281
+
282
+ /**
283
+ * @brief Checks that the arguments define a correct and positively slopped line.
284
+ */
285
+ void _check_direction() const
286
+ {
287
+ if (direction_.size() == 0) return; // default slope
288
+
289
+ bool is_trivial = true;
290
+ for (T v : direction_) {
291
+ if (v) {
292
+ is_trivial = false;
293
+ }
294
+ if (v < 0) {
295
+ throw std::invalid_argument("Direction should have positive entries.");
296
+ }
297
+ }
298
+ if (is_trivial) {
299
+ throw std::invalid_argument("Direction should have at least one non-trivial entry.");
300
+ }
301
+ if (direction_.size() != basePoint_.size())
302
+ throw std::invalid_argument("The dimensions of base point and direction are not equal.");
303
+ }
304
+ };
305
+
306
+ } // namespace multi_persistence
307
+ } // namespace Gudhi
308
+
309
+ #endif // MP_LINE_FILTRATION_H_INCLUDED