multipers 2.3.3b6__cp312-cp312-manylinux_2_39_x86_64.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.

Potentially problematic release.


This version of multipers might be problematic. Click here for more details.

Files changed (182) hide show
  1. multipers/__init__.py +33 -0
  2. multipers/_signed_measure_meta.py +453 -0
  3. multipers/_slicer_meta.py +211 -0
  4. multipers/array_api/__init__.py +45 -0
  5. multipers/array_api/numpy.py +41 -0
  6. multipers/array_api/torch.py +58 -0
  7. multipers/data/MOL2.py +458 -0
  8. multipers/data/UCR.py +18 -0
  9. multipers/data/__init__.py +1 -0
  10. multipers/data/graphs.py +466 -0
  11. multipers/data/immuno_regions.py +27 -0
  12. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  13. multipers/data/pytorch2simplextree.py +91 -0
  14. multipers/data/shape3d.py +101 -0
  15. multipers/data/synthetic.py +113 -0
  16. multipers/distances.py +202 -0
  17. multipers/filtration_conversions.pxd +229 -0
  18. multipers/filtration_conversions.pxd.tp +84 -0
  19. multipers/filtrations/__init__.py +18 -0
  20. multipers/filtrations/density.py +574 -0
  21. multipers/filtrations/filtrations.py +361 -0
  22. multipers/filtrations.pxd +224 -0
  23. multipers/function_rips.cpython-312-x86_64-linux-gnu.so +0 -0
  24. multipers/function_rips.pyx +105 -0
  25. multipers/grids.cpython-312-x86_64-linux-gnu.so +0 -0
  26. multipers/grids.pyx +433 -0
  27. multipers/gudhi/Persistence_slices_interface.h +132 -0
  28. multipers/gudhi/Simplex_tree_interface.h +239 -0
  29. multipers/gudhi/Simplex_tree_multi_interface.h +551 -0
  30. multipers/gudhi/cubical_to_boundary.h +59 -0
  31. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
  32. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
  33. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
  34. multipers/gudhi/gudhi/Debug_utils.h +45 -0
  35. multipers/gudhi/gudhi/Fields/Multi_field.h +484 -0
  36. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -0
  37. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -0
  38. multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -0
  39. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -0
  40. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -0
  41. multipers/gudhi/gudhi/Fields/Z2_field.h +355 -0
  42. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -0
  43. multipers/gudhi/gudhi/Fields/Zp_field.h +420 -0
  44. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -0
  45. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -0
  46. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
  47. multipers/gudhi/gudhi/Matrix.h +2107 -0
  48. multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -0
  49. multipers/gudhi/gudhi/Multi_persistence/Box.h +174 -0
  50. multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -0
  51. multipers/gudhi/gudhi/Off_reader.h +173 -0
  52. multipers/gudhi/gudhi/One_critical_filtration.h +1441 -0
  53. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -0
  54. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -0
  55. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -0
  56. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -0
  57. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -0
  58. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -0
  59. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -0
  60. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -0
  61. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -0
  62. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -0
  63. multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -0
  64. multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -0
  65. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -0
  66. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -0
  67. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -0
  68. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -0
  69. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -0
  70. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -0
  71. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -0
  72. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -0
  73. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -0
  74. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -0
  75. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -0
  76. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -0
  77. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -0
  78. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -0
  79. multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -0
  80. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -0
  81. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -0
  82. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -0
  83. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -0
  84. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -0
  85. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -0
  86. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -0
  87. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
  88. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
  89. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
  90. multipers/gudhi/gudhi/Persistent_cohomology.h +745 -0
  91. multipers/gudhi/gudhi/Points_off_io.h +171 -0
  92. multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
  93. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -0
  94. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
  95. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -0
  96. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
  97. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
  98. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
  99. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -0
  100. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -0
  101. multipers/gudhi/gudhi/Simplex_tree.h +2794 -0
  102. multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -0
  103. multipers/gudhi/gudhi/distance_functions.h +62 -0
  104. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
  105. multipers/gudhi/gudhi/persistence_interval.h +253 -0
  106. multipers/gudhi/gudhi/persistence_matrix_options.h +170 -0
  107. multipers/gudhi/gudhi/reader_utils.h +367 -0
  108. multipers/gudhi/mma_interface_coh.h +256 -0
  109. multipers/gudhi/mma_interface_h0.h +223 -0
  110. multipers/gudhi/mma_interface_matrix.h +293 -0
  111. multipers/gudhi/naive_merge_tree.h +536 -0
  112. multipers/gudhi/scc_io.h +310 -0
  113. multipers/gudhi/truc.h +1403 -0
  114. multipers/io.cpython-312-x86_64-linux-gnu.so +0 -0
  115. multipers/io.pyx +644 -0
  116. multipers/ml/__init__.py +0 -0
  117. multipers/ml/accuracies.py +90 -0
  118. multipers/ml/invariants_with_persistable.py +79 -0
  119. multipers/ml/kernels.py +176 -0
  120. multipers/ml/mma.py +713 -0
  121. multipers/ml/one.py +472 -0
  122. multipers/ml/point_clouds.py +352 -0
  123. multipers/ml/signed_measures.py +1589 -0
  124. multipers/ml/sliced_wasserstein.py +461 -0
  125. multipers/ml/tools.py +113 -0
  126. multipers/mma_structures.cpython-312-x86_64-linux-gnu.so +0 -0
  127. multipers/mma_structures.pxd +128 -0
  128. multipers/mma_structures.pyx +2786 -0
  129. multipers/mma_structures.pyx.tp +1094 -0
  130. multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -0
  131. multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -0
  132. multipers/multi_parameter_rank_invariant/function_rips.h +322 -0
  133. multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -0
  134. multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -0
  135. multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -0
  136. multipers/multiparameter_edge_collapse.py +41 -0
  137. multipers/multiparameter_module_approximation/approximation.h +2330 -0
  138. multipers/multiparameter_module_approximation/combinatory.h +129 -0
  139. multipers/multiparameter_module_approximation/debug.h +107 -0
  140. multipers/multiparameter_module_approximation/euler_curves.h +0 -0
  141. multipers/multiparameter_module_approximation/format_python-cpp.h +286 -0
  142. multipers/multiparameter_module_approximation/heap_column.h +238 -0
  143. multipers/multiparameter_module_approximation/images.h +79 -0
  144. multipers/multiparameter_module_approximation/list_column.h +174 -0
  145. multipers/multiparameter_module_approximation/list_column_2.h +232 -0
  146. multipers/multiparameter_module_approximation/ru_matrix.h +347 -0
  147. multipers/multiparameter_module_approximation/set_column.h +135 -0
  148. multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -0
  149. multipers/multiparameter_module_approximation/unordered_set_column.h +166 -0
  150. multipers/multiparameter_module_approximation/utilities.h +403 -0
  151. multipers/multiparameter_module_approximation/vector_column.h +223 -0
  152. multipers/multiparameter_module_approximation/vector_matrix.h +331 -0
  153. multipers/multiparameter_module_approximation/vineyards.h +464 -0
  154. multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -0
  155. multipers/multiparameter_module_approximation.cpython-312-x86_64-linux-gnu.so +0 -0
  156. multipers/multiparameter_module_approximation.pyx +235 -0
  157. multipers/pickle.py +90 -0
  158. multipers/plots.py +456 -0
  159. multipers/point_measure.cpython-312-x86_64-linux-gnu.so +0 -0
  160. multipers/point_measure.pyx +395 -0
  161. multipers/simplex_tree_multi.cpython-312-x86_64-linux-gnu.so +0 -0
  162. multipers/simplex_tree_multi.pxd +134 -0
  163. multipers/simplex_tree_multi.pyx +10840 -0
  164. multipers/simplex_tree_multi.pyx.tp +2009 -0
  165. multipers/slicer.cpython-312-x86_64-linux-gnu.so +0 -0
  166. multipers/slicer.pxd +3034 -0
  167. multipers/slicer.pxd.tp +234 -0
  168. multipers/slicer.pyx +20481 -0
  169. multipers/slicer.pyx.tp +1088 -0
  170. multipers/tensor/tensor.h +672 -0
  171. multipers/tensor.pxd +13 -0
  172. multipers/test.pyx +44 -0
  173. multipers/tests/__init__.py +62 -0
  174. multipers/torch/__init__.py +1 -0
  175. multipers/torch/diff_grids.py +240 -0
  176. multipers/torch/rips_density.py +310 -0
  177. multipers-2.3.3b6.dist-info/METADATA +128 -0
  178. multipers-2.3.3b6.dist-info/RECORD +182 -0
  179. multipers-2.3.3b6.dist-info/WHEEL +5 -0
  180. multipers-2.3.3b6.dist-info/licenses/LICENSE +21 -0
  181. multipers-2.3.3b6.dist-info/top_level.txt +1 -0
  182. multipers.libs/libtbb-ca48af5c.so.12.16 +0 -0
@@ -0,0 +1,174 @@
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: doc
9
+ * - YYYY/MM Author: Description of the modification
10
+ */
11
+
12
+ /**
13
+ * @file Box.h
14
+ * @author David Loiseaux
15
+ * @brief Contains the @ref Gudhi::multi_persistence::Box class.
16
+ */
17
+
18
+ #ifndef BOX_H_INCLUDED
19
+ #define BOX_H_INCLUDED
20
+
21
+ #include <ostream> //std::ostream
22
+
23
+ #include <gudhi/Debug_utils.h>
24
+ #include <gudhi/One_critical_filtration.h>
25
+
26
+ namespace Gudhi{
27
+ namespace multi_persistence {
28
+
29
+ /**
30
+ * @class Box Box.h gudhi/Multi_persistence/Box.h
31
+ * @ingroup multi_persistence
32
+ *
33
+ * @brief Simple box in \f$\mathbb R^n\f$ defined by two diametrically opposite corners.
34
+ *
35
+ * @tparam T Type of the coordinates of the Box. Has to follow the conditions of the template parameter of
36
+ * @ref One_critical_filtration "".
37
+ */
38
+ template <typename T>
39
+ class Box {
40
+ public:
41
+ using Point = Gudhi::multi_filtration::One_critical_filtration<T>; /**< Type of a point in \f$\mathbb R^n\f$. */
42
+
43
+ /**
44
+ * @brief Default constructor. Constructs a trivial box with corners at minus infinity.
45
+ */
46
+ Box() {}
47
+
48
+ /**
49
+ * @brief Constructs a box from the two given corners. Assumes that \f$ lowerCorner \le @p upperCorner \f$ and
50
+ * if both are finite values, they have the same dimension.
51
+ *
52
+ * @param lowerCorner First corner of the box. Has to be smaller than `upperCorner`.
53
+ * @param upperCorner Second corner of the box. Has to be greater than `lowerCorner`.
54
+ */
55
+ Box(const Point &lowerCorner, const Point &upperCorner) : lowerCorner_(lowerCorner), upperCorner_(upperCorner) {
56
+ GUDHI_CHECK(lowerCorner.size() == upperCorner.size() || !lowerCorner.is_finite() || !upperCorner.is_finite(),
57
+ "The two corners of the box don't have the same dimension.");
58
+ }
59
+
60
+ /**
61
+ * @brief Constructs a box from the two given corners. Assumes that \f$ box.first \le @p box.second \f$ and
62
+ * if both are finite values, they have the same dimension.
63
+ *
64
+ * @param box Pair of corners defining the wished box.
65
+ */
66
+ Box(const std::pair<Point, Point> &box) : Box(box.first, box.second) {}
67
+
68
+ /**
69
+ * @brief Returns the lowest of both defining corners.
70
+ */
71
+ const Point &get_lower_corner() const { return lowerCorner_; }
72
+
73
+ /**
74
+ * @brief Returns the lowest of both defining corners.
75
+ */
76
+ Point &get_lower_corner() { return lowerCorner_; }
77
+
78
+ /**
79
+ * @brief Returns the greatest of both defining corners.
80
+ */
81
+ Point &get_upper_corner() { return upperCorner_; }
82
+
83
+ /**
84
+ * @brief Returns the greatest of both defining corners.
85
+ */
86
+ const Point &get_upper_corner() const { return upperCorner_; }
87
+
88
+ /**
89
+ * @brief Returns a pair of const references to both defining corners.
90
+ */
91
+ std::pair<const Point &, const Point &> get_bounding_corners() const { return {lowerCorner_, upperCorner_}; }
92
+
93
+ /**
94
+ * @brief Returns a pair of references to both defining corners.
95
+ */
96
+ std::pair<Point &, Point &> get_bounding_corners() { return {lowerCorner_, upperCorner_}; }
97
+
98
+ /**
99
+ * @brief Returns true if and only if one of the following is true:
100
+ * - one of the corners is empty
101
+ * - one of the corners has value NaN
102
+ * - both corners have value infinity
103
+ * - both corners have value minus infinity
104
+ * - both corners are finite but don't have the same dimension.
105
+ */
106
+ bool is_trivial() const {
107
+ return lowerCorner_.empty() || upperCorner_.empty() || lowerCorner_.is_nan() || upperCorner_.is_nan() ||
108
+ (lowerCorner_.is_plus_inf() && upperCorner_.is_plus_inf()) ||
109
+ (lowerCorner_.is_minus_inf() && upperCorner_.is_minus_inf()) ||
110
+ (lowerCorner_.is_finite() && upperCorner_.is_finite() &&
111
+ lowerCorner_.num_parameters() != upperCorner_.num_parameters());
112
+ }
113
+
114
+ /**
115
+ * @brief Returns true if and only if the given point is inside the box.
116
+ * If the box is not {-infinity, infinity} and the given point is finite, but has not the same dimension
117
+ * than the box, the point is considered outside.
118
+ */
119
+ bool contains(const Point &point) const {
120
+ if (point.is_nan() || is_trivial()) return false;
121
+ if (point.is_plus_inf()) return upperCorner_.is_plus_inf();
122
+ if (point.is_minus_inf()) return lowerCorner_.is_minus_inf();
123
+
124
+ if ((lowerCorner_.is_finite() && point.size() != lowerCorner_.size()) ||
125
+ (upperCorner_.is_finite() && point.size() != upperCorner_.size())) {
126
+ // TODO: make it a warning, with future GUDHI_CHECK version?
127
+ // std::cerr << "Box and point are not of the same dimension." << std::endl;
128
+ return false;
129
+ }
130
+
131
+ return lowerCorner_ <= point && point <= upperCorner_;
132
+ }
133
+
134
+ /**
135
+ * @brief Returns the dimension of the box. If the box is trivial or both corners are infinite, the dimension is 0.
136
+ */
137
+ std::size_t dimension() const {
138
+ if (is_trivial()) return 0;
139
+ if (lowerCorner_.is_minus_inf() && upperCorner_.is_plus_inf()) return 0; // not so sure what we want to do here
140
+ return lowerCorner_.is_finite() ? lowerCorner_.size() : upperCorner_.size();
141
+ }
142
+
143
+ /**
144
+ * @brief Inflates the box by delta.
145
+ *
146
+ * @param delta Inflation coefficient.
147
+ */
148
+ void inflate(T delta) {
149
+ lowerCorner_ -= delta;
150
+ upperCorner_ += delta;
151
+ }
152
+ friend bool operator==(const Box& a, const Box&b){
153
+ return a.upperCorner_ == b.upperCorner_ && a.lowerCorner_ == b.lowerCorner_;
154
+ }
155
+
156
+ /**
157
+ * @brief Outstream operator.
158
+ */
159
+ friend std::ostream &operator<<(std::ostream &os, const Box<T> &box) {
160
+ os << "Box -- Bottom corner : ";
161
+ os << box.get_lower_corner();
162
+ os << ", Top corner : ";
163
+ os << box.get_upper_corner();
164
+ return os;
165
+ }
166
+
167
+ private:
168
+ Point lowerCorner_; /**< Lowest of defining corners. */
169
+ Point upperCorner_; /**< Greatest of defining corners. */
170
+ };
171
+
172
+ }} // namespace Gudhi::multi_persistence
173
+
174
+ #endif // BOX_H_INCLUDED
@@ -0,0 +1,282 @@
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: doc
9
+ * - YYYY/MM Author: Description of the modification
10
+ */
11
+
12
+ /**
13
+ * @file Line.h
14
+ * @author David Loiseaux
15
+ * @brief Contains the @ref Gudhi::multi_persistence::Line class.
16
+ */
17
+
18
+ #ifndef LINE_FILTRATION_TRANSLATION_H_INCLUDED
19
+ #define LINE_FILTRATION_TRANSLATION_H_INCLUDED
20
+
21
+ #include <cmath>
22
+ #include <cstddef>
23
+ #include <stdexcept>
24
+ #include <limits>
25
+
26
+ #include <gudhi/Debug_utils.h>
27
+ #include <gudhi/One_critical_filtration.h>
28
+ #include <gudhi/Multi_critical_filtration.h>
29
+ #include <gudhi/Multi_persistence/Box.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. Has to follow the conditions of the template parameter of
41
+ * @ref One_critical_filtration "".
42
+ */
43
+ template <typename T>
44
+ class Line {
45
+ public:
46
+ /**
47
+ * @brief Coordinates in \f$\mathbb R^n\f$.
48
+ */
49
+ using Point = Gudhi::multi_filtration::One_critical_filtration<T>;
50
+ /**
51
+ * @brief Set of coordinates in \f$\mathbb R^n\f$.
52
+ */
53
+ using K_critical_point = Gudhi::multi_filtration::Multi_critical_filtration<T>;
54
+
55
+ /**
56
+ * @brief Default constructor. Sets the number of coordinates to 0.
57
+ */
58
+ Line() : basePoint_(0), direction_(0) {} // has to be explicitly set to 0, otherwise becomes -inf
59
+ /**
60
+ * @brief Constructs a line going through the given point with slope 1.
61
+ *
62
+ * @param x A point of the line.
63
+ */
64
+ Line(const Point &x) : basePoint_(x), direction_(0) {} // default direction
65
+ /**
66
+ * @brief Constructs a line going through the given point with slope 1.
67
+ *
68
+ * @param x A point of the line. Will be moved.
69
+ */
70
+ Line(Point &&x) : basePoint_(std::move(x)), direction_(0) {} // default direction
71
+ /**
72
+ * @brief Constructs a line going through the given point in the direction of the given vector.
73
+ * If the vector has no coordinates, the slope is assumed to be 1.
74
+ * Otherwise, the vector has to be non trivial and all its coordinates have to be positive.
75
+ *
76
+ * @param x A point of the line.
77
+ * @param vector Direction of the line. Positive and non trivial.
78
+ */
79
+ Line(const Point &x, const Point &vector) : basePoint_(x), direction_(vector) { check_direction_(); }
80
+
81
+ /**
82
+ * @brief Returns the coordinates of the point on the line with "time" parameter `t`. That is, the point \f$ x \f$
83
+ * 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$
84
+ * the number of coordinates.
85
+ */
86
+ Point operator[](T t) const {
87
+ GUDHI_CHECK(direction_.empty() || direction_.size() == basePoint_.size(),
88
+ "Direction and base point do not have the same dimension.");
89
+
90
+ if constexpr (std::numeric_limits<T>::has_quiet_NaN){ //to avoid windows error
91
+ if (std::isnan(t)) return Point::nan();
92
+ }
93
+ if (t == Point::T_inf) return Point::inf();
94
+ if (t == -Point::T_inf) return Point::minus_inf();
95
+
96
+ Point x(basePoint_.size());
97
+
98
+ if (direction_.size() > 0) {
99
+ for (std::size_t i = 0; i < x.size(); i++) x[i] = basePoint_[i] + t * direction_[i];
100
+ } else
101
+ for (std::size_t i = 0; i < x.size(); i++) x[i] = basePoint_[i] + t;
102
+
103
+ return x;
104
+ }
105
+
106
+ /**
107
+ * @brief Translates the given line in the given direction.
108
+ */
109
+ friend Line &operator+=(Line &to_translate, const Point &v) {
110
+ to_translate.basePoint_ += v;
111
+ return to_translate;
112
+ }
113
+
114
+ /**
115
+ * @brief Returns a reference to the current base point of the line.
116
+ */
117
+ Point &base_point() { return basePoint_; }
118
+ /**
119
+ * @brief Returns a const reference to the current base point of the line.
120
+ */
121
+ const Point &base_point() const { return basePoint_; }
122
+
123
+ /**
124
+ * @brief Returns a reference to the direction vector of the line.
125
+ */
126
+ Point &direction() { return direction_; }
127
+ /**
128
+ * @brief Returns a const reference to the direction vector of the line.
129
+ */
130
+ const Point &direction() const { return direction_; }
131
+
132
+ // TODO: factorize forward and backward version by adding a `co` to One_critical_filtration?
133
+ // Could make problems with One_critical_filtration being the type of basePoint_ and direction_
134
+
135
+ /**
136
+ * @brief Computes the "time" parameter \f$ t \f$ of the starting point \f$ p = base\_point + t \times direction \f$
137
+ * of the intersection between the line and the closed positive cone originating at `x`.
138
+ *
139
+ * @tparam U Type of the time parameter.
140
+ * @param x Origin of the closed positive cone.
141
+ */
142
+ template <typename U = T>
143
+ U compute_forward_intersection(const Point &x) const {
144
+ GUDHI_CHECK(direction_.empty() || direction_.size() == x.size(), "x has not as many parameters as the line.");
145
+
146
+ constexpr const U inf =
147
+ std::numeric_limits<U>::has_infinity ? std::numeric_limits<U>::infinity() : std::numeric_limits<U>::max();
148
+ if (x.is_plus_inf() || x.is_nan()) return inf;
149
+ if (x.is_minus_inf()) return -inf;
150
+ U t = -inf;
151
+ if (direction_.size()) {
152
+ for (std::size_t i = 0; i < x.size(); i++) {
153
+ if (direction_[i] == 0) {
154
+ if (x[i] > basePoint_[i]) return inf;
155
+ } else {
156
+ t = std::max(t, (static_cast<U>(x[i]) - static_cast<U>(basePoint_[i])) / static_cast<U>((direction_[i])));
157
+ }
158
+ }
159
+ } else {
160
+ for (std::size_t i = 0; i < x.size(); i++) t = std::max(t, static_cast<U>(x[i]) - static_cast<U>(basePoint_[i]));
161
+ }
162
+
163
+ return t;
164
+ }
165
+
166
+ /**
167
+ * @brief Computes the "time" parameter \f$ t \f$ of the starting point \f$ p = base\_point + t \times direction \f$
168
+ * of the intersection between the line and the union of closed positive cones originating at the points in `x`.
169
+ *
170
+ * @tparam U Type of the time parameter.
171
+ * @param x Set of origins for the closed positive cones.
172
+ */
173
+ template <typename U = T>
174
+ U compute_forward_intersection(const K_critical_point &x) const {
175
+ constexpr const U inf =
176
+ std::numeric_limits<U>::has_infinity ? std::numeric_limits<U>::infinity() : std::numeric_limits<U>::max();
177
+ if (x.is_plus_inf() || x.is_nan()) return inf;
178
+ if (x.is_minus_inf()) return -inf;
179
+ U t = inf;
180
+ for (const auto &y : x) {
181
+ t = std::min(t, compute_forward_intersection<U>(y));
182
+ }
183
+ return t;
184
+ }
185
+
186
+ /**
187
+ * @brief Computes the "time" parameter \f$ t \f$ of the starting point \f$ p = base\_point + t \times direction \f$
188
+ * of the intersection between the line and the open negative cone originating at `x`.
189
+ *
190
+ * @tparam U Type of the time parameter.
191
+ * @param x Origin of the open negative cone.
192
+ */
193
+ template <typename U = T>
194
+ U compute_backward_intersection(const Point &x) const {
195
+ constexpr const U inf =
196
+ std::numeric_limits<U>::has_infinity ? std::numeric_limits<U>::infinity() : std::numeric_limits<U>::max();
197
+ if (x.is_plus_inf()) return inf;
198
+ if (x.is_minus_inf() || x.is_nan()) return -inf;
199
+ U t = inf;
200
+
201
+ if (direction_.size()) {
202
+ for (std::size_t i = 0; i < x.size(); i++) {
203
+ if (direction_[i] == 0) {
204
+ if (x[i] <= basePoint_[i]) return -inf;
205
+ } else {
206
+ t = std::min(t, (static_cast<U>(x[i]) - static_cast<U>(basePoint_[i])) / static_cast<U>(direction_[i]));
207
+ }
208
+ }
209
+ } else {
210
+ for (std::size_t i = 0; i < x.size(); i++) t = std::min(t, static_cast<U>(x[i] - basePoint_[i]));
211
+ }
212
+ return t;
213
+ }
214
+
215
+ /**
216
+ * @brief Computes the "time" parameter \f$ t \f$ of the starting point \f$ p = base\_point + t \times direction \f$
217
+ * of the intersection between the line and the union of open negative cones originating at the points in `x`.
218
+ *
219
+ * @tparam U Type of the time parameter.
220
+ * @param x Set of origins for the open negative cones.
221
+ */
222
+ template <typename U = T>
223
+ U compute_backward_intersection(const K_critical_point &x) const {
224
+ constexpr const U inf =
225
+ std::numeric_limits<U>::has_infinity ? std::numeric_limits<U>::infinity() : std::numeric_limits<U>::max();
226
+ if (x.is_plus_inf()) return inf;
227
+ if (x.is_minus_inf() || x.is_nan()) return -inf;
228
+ U t = -inf;
229
+ for (const auto &y : x) {
230
+ t = std::max(t, compute_backward_intersection<U>(y));
231
+ }
232
+ return t;
233
+ }
234
+
235
+ /**
236
+ * @brief Given a box, returns "time" parameter of the intersection of this box and the line.
237
+ *
238
+ * @param box Box to intersect.
239
+ * @return A pair representing the two bounding points of the intersection, such that the first element is the
240
+ * smallest of the two. If the box and the line do not intersect or the box is trivial, returns the pair {inf, -inf}.
241
+ */
242
+ std::pair<T, T> get_bounds(const Box<T> &box) const {
243
+ if (box.is_trivial()) return {Point::T_inf, -Point::T_inf};
244
+
245
+ T bottom = compute_forward_intersection(box.get_lower_corner());
246
+ T top = compute_backward_intersection(box.get_upper_corner());
247
+
248
+ if (bottom > top) return {Point::T_inf, -Point::T_inf}; // no intersection
249
+
250
+ return {bottom, top};
251
+ }
252
+
253
+ private:
254
+ Point basePoint_; /**< Any point on the line. */
255
+ Point direction_; /**< Direction of the line. */
256
+
257
+ /**
258
+ * @brief Checks that the arguments define a correct and positively slopped line.
259
+ */
260
+ void check_direction_() const {
261
+ if (direction_.size() == 0) return; // default slope
262
+
263
+ bool is_trivial = true;
264
+ for (T v : direction_) {
265
+ if (v) {
266
+ is_trivial = false;
267
+ }
268
+ if (v < 0) {
269
+ throw std::invalid_argument("Direction should have positive entries.");
270
+ }
271
+ }
272
+ if (is_trivial) {
273
+ throw std::invalid_argument("Direction should have at least one non-trivial entry.");
274
+ }
275
+ if (direction_.size() != basePoint_.size())
276
+ throw std::invalid_argument("The dimensions of base point and direction are not equal.");
277
+ }
278
+ };
279
+
280
+ }} // namespace Gudhi::multi_persistence
281
+
282
+ #endif // LINE_FILTRATION_TRANSLATION_H_INCLUDED
@@ -0,0 +1,173 @@
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 Salinas
4
+ *
5
+ * Copyright (C) 2014 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+
12
+ #ifndef OFF_READER_H_
13
+ #define OFF_READER_H_
14
+
15
+
16
+ #include <sstream>
17
+ #include <iostream>
18
+ #include <iterator>
19
+ #include <string>
20
+ #include <vector>
21
+ #include <fstream>
22
+
23
+ namespace Gudhi {
24
+
25
+ /** \brief OFF file reader top class visitor.
26
+ *
27
+ * OFF file must be conform to \ref FileFormatsOFF
28
+ */
29
+ class Off_reader {
30
+ public:
31
+ Off_reader(std::ifstream& stream) : stream_(stream) { }
32
+
33
+ ~Off_reader() {
34
+ stream_.close();
35
+ }
36
+
37
+ /** \brief
38
+ * Read an OFF file and calls the following methods :
39
+ *
40
+ * <CODE>void init(int dim,int num_vertices,int num_faces,int num_edges); // from file header - num_edges may not be set
41
+ *
42
+ * void point(const std::vector<double>& point); // for each point read
43
+ *
44
+ * void maximal_face(const std::list<int>& face); // for each face read
45
+ *
46
+ * void done(); // upon file read is finished</CODE>
47
+ *
48
+ * of the visitor when reading a point or a maximal face. Edges are not taken into account.
49
+ */
50
+ template<typename OffVisitor>
51
+ bool read(OffVisitor& off_visitor) {
52
+ bool success_read_off_preamble = read_off_preamble(off_visitor);
53
+ if (!success_read_off_preamble) {
54
+ std::cerr << "could not read off preambule\n";
55
+ return false;
56
+ }
57
+
58
+ bool success_read_off_points = read_off_points(off_visitor);
59
+ if (!success_read_off_points) {
60
+ std::cerr << "could not read off points\n";
61
+ return false;
62
+ }
63
+
64
+ bool success_read_off_faces = read_off_faces(off_visitor);
65
+ if (!success_read_off_faces) {
66
+ std::cerr << "could not read off faces\n";
67
+ return false;
68
+ }
69
+
70
+ off_visitor.done();
71
+ return success_read_off_preamble && success_read_off_points && success_read_off_faces;
72
+ }
73
+
74
+ private:
75
+ std::ifstream& stream_;
76
+
77
+ struct Off_info {
78
+ int dim;
79
+ int num_vertices;
80
+ int num_edges;
81
+ int num_faces;
82
+ };
83
+
84
+ Off_info off_info_;
85
+
86
+ template<typename OffVisitor>
87
+ bool read_off_preamble(OffVisitor& off_visitor) {
88
+ std::string line;
89
+ if (!goto_next_uncomment_line(line)) return false;
90
+
91
+ bool is_off_file = (line.find("OFF") != std::string::npos);
92
+ bool is_noff_file = (line.find("nOFF") != std::string::npos);
93
+
94
+
95
+
96
+ if (!is_off_file && !is_noff_file) {
97
+ std::cerr << line << std::endl;
98
+ std::cerr << "missing off header\n";
99
+ return false;
100
+ }
101
+
102
+ if (is_noff_file) {
103
+ // Should be on a separate line, but we accept it on the same line as the number of vertices
104
+ stream_ >> off_info_.dim;
105
+ } else {
106
+ off_info_.dim = 3;
107
+ }
108
+
109
+ if (!goto_next_uncomment_line(line)) return false;
110
+ std::istringstream iss(line);
111
+ if (!(iss >> off_info_.num_vertices >> off_info_.num_faces >> off_info_.num_edges)) {
112
+ std::cerr << "incorrect number of vertices/faces/edges\n";
113
+ return false;
114
+ }
115
+ off_visitor.init(off_info_.dim, off_info_.num_vertices, off_info_.num_faces, off_info_.num_edges);
116
+
117
+ return true;
118
+ }
119
+
120
+ bool goto_next_uncomment_line(std::string& uncomment_line) {
121
+ do {
122
+ // skip whitespace, including empty lines
123
+ if (!std::ifstream::sentry(stream_)) return false;
124
+ std::getline(stream_, uncomment_line);
125
+ } while (uncomment_line[0] == '#');
126
+ return static_cast<bool>(stream_);
127
+ }
128
+
129
+ template<typename OffVisitor>
130
+ bool read_off_points(OffVisitor& visitor) {
131
+ int num_vertices_to_read = off_info_.num_vertices;
132
+ while (num_vertices_to_read--) {
133
+ std::string line;
134
+ if (!goto_next_uncomment_line(line)) return false;
135
+ std::vector<double> point;
136
+ std::istringstream iss(line);
137
+ point.assign(std::istream_iterator<double>(iss), std::istream_iterator<double>());
138
+ // if(point.size() != off_info_.dim) return false;
139
+ visitor.point(point);
140
+ }
141
+ return true;
142
+ }
143
+
144
+ template<typename OffVisitor>
145
+ bool read_off_faces(OffVisitor& visitor) {
146
+ std::string line;
147
+ while (goto_next_uncomment_line(line)) {
148
+ std::istringstream iss(line);
149
+ int num_face_vertices;
150
+ iss >> num_face_vertices;
151
+ std::vector<int> face;
152
+ face.assign(std::istream_iterator<int>(iss), std::istream_iterator<int>());
153
+ // if (face.size() != (off_info_.dim + 1)) return false;
154
+ visitor.maximal_face(face);
155
+ }
156
+ return true;
157
+ }
158
+ };
159
+
160
+ template<typename OFFVisitor>
161
+ void read_off(const std::string& name_file_off, OFFVisitor& vis) {
162
+ std::ifstream stream(name_file_off);
163
+ if (!stream.is_open()) {
164
+ std::cerr << "could not open file \n";
165
+ } else {
166
+ Off_reader off_reader(stream);
167
+ off_reader.read(vis);
168
+ }
169
+ }
170
+
171
+ } // namespace Gudhi
172
+
173
+ #endif // OFF_READER_H_