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,171 @@
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): Vincent Rouvreau
4
+ *
5
+ * Copyright (C) 2015 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+ #ifndef POINTS_OFF_IO_H_
11
+ #define POINTS_OFF_IO_H_
12
+
13
+ #include <gudhi/Off_reader.h>
14
+
15
+ #include <string>
16
+ #include <vector>
17
+ #include <fstream>
18
+ #include <map>
19
+
20
+ namespace Gudhi {
21
+
22
+ /**
23
+ * \brief OFF file visitor implementation according to Off_reader in order to read points from an OFF file.
24
+ */
25
+ template<typename Point_d>
26
+ class Points_off_visitor_reader {
27
+ private:
28
+ std::vector<Point_d> point_cloud;
29
+
30
+ public:
31
+ /** \brief Off_reader visitor init implementation.
32
+ *
33
+ * The init parameters are set from OFF file header.
34
+ * Dimension value is required in order to construct a vector of points.
35
+ *
36
+ * @param[in] dim space dimension of vertices.
37
+ * @param[in] num_vertices number of vertices in the OFF file (not used).
38
+ * @param[in] num_faces number of faces in the OFF file (not used).
39
+ * @param[in] num_edges number of edges in the OFF file (not used).
40
+ */
41
+ void init(int dim, int num_vertices, int num_faces, int num_edges) {
42
+ #ifdef DEBUG_TRACES
43
+ std::clog << "Points_off_visitor_reader::init - dim=" << dim << " - num_vertices=" <<
44
+ num_vertices << " - num_faces=" << num_faces << " - num_edges=" << num_edges << std::endl;
45
+ #endif // DEBUG_TRACES
46
+ if (num_faces > 0) {
47
+ std::cerr << "Points_off_visitor_reader::init faces are not taken into account from OFF file for Points.\n";
48
+ }
49
+ if (num_edges > 0) {
50
+ std::cerr << "Points_off_visitor_reader::init edges are not taken into account from OFF file for Points.\n";
51
+ }
52
+ }
53
+
54
+ /** @brief Off_reader visitor point implementation.
55
+ *
56
+ * The point function is called on each vertex line from OFF file.
57
+ * This function inserts the vertex in the vector of points.
58
+ *
59
+ * @param[in] point vector of vertex coordinates.
60
+ *
61
+ * @details
62
+ * Point_d must have a constructor with the following form:
63
+ *
64
+ * @code template<class InputIterator > Point_d::Point_d(InputIterator first, InputIterator last) @endcode
65
+ *
66
+ */
67
+ void point(const std::vector<double>& point) {
68
+ #ifdef DEBUG_TRACES
69
+ std::clog << "Points_off_visitor_reader::point ";
70
+ for (auto coordinate : point) {
71
+ std::clog << coordinate << " | ";
72
+ }
73
+ std::clog << std::endl;
74
+ #endif // DEBUG_TRACES
75
+ // Fill the point cloud
76
+ point_cloud.push_back(Point_d(point.begin(), point.end()));
77
+ }
78
+
79
+ // Off_reader visitor maximal_face implementation - Only points are read
80
+ void maximal_face(const std::vector<int>& face) { }
81
+
82
+ // Off_reader visitor done implementation - Only points are read
83
+ void done() { }
84
+
85
+ /** \brief Point cloud getter.
86
+ *
87
+ * @return point_cloud.
88
+ */
89
+ const std::vector<Point_d>& get_point_cloud() const {
90
+ return point_cloud;
91
+ }
92
+ };
93
+
94
+ /**
95
+ * \brief OFF file reader implementation in order to read points from an OFF file.
96
+ *
97
+ * This class is using the Points_off_visitor_reader to visit the OFF file according to Off_reader.
98
+ *
99
+ * Point_d must have a constructor with the following form:
100
+ *
101
+ * \code template<class InputIterator > Point_d::Point_d(int d, InputIterator first, InputIterator last) \endcode
102
+ *
103
+ * where d is the point dimension.
104
+ *
105
+ * \section pointoffioexample Example
106
+ *
107
+ * This example loads points from an OFF file and builds a vector of points (vector of double).
108
+ * Then, it is asked to display the points.
109
+ *
110
+ * \include example_vector_double_points_off_reader.cpp
111
+ *
112
+ * When launching:
113
+ *
114
+ * \code $> ./vector_double_off_reader ../../data/points/alphacomplexdoc.off
115
+ * \endcode
116
+ *
117
+ * the program outputs a file ../../data/points/alphacomplexdoc.off.txt:
118
+ *
119
+ * \include vectordoubleoffreader_result.txt
120
+ */
121
+ template<typename Point_d>
122
+ class Points_off_reader {
123
+ public:
124
+ /** \brief Reads the OFF file and constructs a vector of points from the points
125
+ * that are in the OFF file.
126
+ *
127
+ * @param[in] name_file OFF file to read.
128
+ *
129
+ * \post Check with is_valid() function to see if read operation was successful.
130
+ */
131
+ Points_off_reader(const std::string& name_file)
132
+ : valid_(false) {
133
+ std::ifstream stream(name_file);
134
+ if (stream.is_open()) {
135
+ Off_reader off_reader(stream);
136
+ Points_off_visitor_reader<Point_d> off_visitor;
137
+ valid_ = off_reader.read(off_visitor);
138
+ if (valid_) {
139
+ point_cloud = off_visitor.get_point_cloud();
140
+ }
141
+ } else {
142
+ std::cerr << "Points_off_reader::Points_off_reader could not open file " << name_file << "\n";
143
+ }
144
+ }
145
+
146
+ /** \brief Returns if the OFF file read operation was successful or not.
147
+ *
148
+ * @return OFF file read status.
149
+ */
150
+ bool is_valid() const {
151
+ return valid_;
152
+ }
153
+
154
+ /** \brief Point cloud getter.
155
+ *
156
+ * @return point_cloud.
157
+ */
158
+ const std::vector<Point_d>& get_point_cloud() const {
159
+ return point_cloud;
160
+ }
161
+
162
+ private:
163
+ /** \brief point_cloud.*/
164
+ std::vector<Point_d> point_cloud;
165
+ /** \brief OFF file read status.*/
166
+ bool valid_;
167
+ };
168
+
169
+ } // namespace Gudhi
170
+
171
+ #endif // POINTS_OFF_IO_H_
@@ -0,0 +1,379 @@
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
+ * - 2025/04 Hannah Schreiber: Reorganization + documentation.
9
+ * - YYYY/MM Author: Description of the modification
10
+ */
11
+
12
+ /**
13
+ * @file Projective_cover_kernel.h
14
+ * @author David Loiseaux
15
+ * @brief Contains the @ref Gudhi::multi_persistence::Projective_cover_kernel class.
16
+ */
17
+
18
+ #ifndef MP_PROJECTIVE_COVER_KERNEL_H_INCLUDED
19
+ #define MP_PROJECTIVE_COVER_KERNEL_H_INCLUDED
20
+
21
+ #include <stdexcept> //std::invalid_argument, std::runtime_error
22
+ #include <utility> //std::move
23
+ #include <vector>
24
+ #include <set>
25
+
26
+ #include <gudhi/Debug_utils.h>
27
+ #include <gudhi/Multi_parameter_filtered_complex.h>
28
+ #include <gudhi/Matrix.h>
29
+
30
+ namespace Gudhi {
31
+ namespace multi_persistence {
32
+
33
+ /**
34
+ * @class Projective_cover_kernel Projective_cover_kernel.h gudhi/Projective_cover_kernel.h
35
+ * @ingroup multi_persistence
36
+ *
37
+ * @brief TODO (what it is + mention that it only works for 2 parameters)
38
+ *
39
+ * @tparam MultiFiltrationValue Filtration value class respecting the @ref MultiFiltrationValue concept.
40
+ * @tparam columnType Column type to use for the matrix used internally. Default value:
41
+ * @ref Gudhi::persistence_matrix::Column_types::NAIVE_VECTOR "NAIVE_VECTOR".
42
+ */
43
+ template <class MultiFiltrationValue,
44
+ Gudhi::persistence_matrix::Column_types columnType = Gudhi::persistence_matrix::Column_types::NAIVE_VECTOR>
45
+ class Projective_cover_kernel
46
+ {
47
+ private:
48
+ /**
49
+ * @brief Options for matrix type.
50
+ */
51
+ struct Matrix_options : Gudhi::persistence_matrix::Default_options<columnType, true> {
52
+ using Index = std::uint32_t;
53
+ };
54
+
55
+ public:
56
+ using Filtration_value = MultiFiltrationValue; /**< Filtration value type. */
57
+ using Complex = Multi_parameter_filtered_complex<Filtration_value>; /**< Complex data type. */
58
+ using Index = typename Complex::Index; /**< Index type. */
59
+ using Dimension = typename Complex::Dimension; /**< Dimension type. */
60
+ using Filtration_value_container = typename Complex::Filtration_value_container; /**< Filt. value container type. */
61
+ using Boundary_container = typename Complex::Boundary_container; /**< Boundary container type. */
62
+ using Dimension_container = typename Complex::Dimension_container; /**< Dimension container type. */
63
+ using Matrix = Gudhi::persistence_matrix::Matrix<Matrix_options>; /**< Matrix type. */
64
+
65
+ // TODO: this only works for 2 parameter modules. Optimize w.r.t. this.
66
+ /**
67
+ * @brief Constructor.
68
+ *
69
+ * @param complex Complex containing the boundaries, dimensions and 2-parameter filtration values necessary,
70
+ * ordered by dimension and then co-lexicographically with respect to the filtration values.
71
+ * @param dim Dimension for which to compute the kernel.
72
+ */
73
+ Projective_cover_kernel(const Complex &complex, Dimension dim)
74
+ {
75
+ using namespace Gudhi::multi_filtration;
76
+
77
+ if (complex.get_number_of_parameters() != 2) throw std::invalid_argument("Only available for 2-parameter modules.");
78
+ if (!complex.is_ordered_by_dimension()) throw std::invalid_argument("Complex has to be ordered by dimension.");
79
+
80
+ const auto &boundaries = complex.get_boundaries();
81
+ const auto &filtValues = complex.get_filtration_values();
82
+ const auto &dimensions = complex.get_dimensions();
83
+
84
+ GUDHI_CHECK_code(
85
+ Index i = 0;
86
+ for (; i < complex.get_number_of_cycle_generators() - 1; ++i) {
87
+ GUDHI_CHECK(filtValues[i].num_generators() == 1,
88
+ std::invalid_argument("Only available for 1-critical modules."));
89
+ GUDHI_CHECK(dimensions[i] <= dimensions[i + 1],
90
+ std::invalid_argument("Cells have to be ordered by dimension."));
91
+ if (dimensions[i] == dimensions[i + 1])
92
+ GUDHI_CHECK(is_less_or_equal_than_lexicographically<true>(filtValues[i], filtValues[i + 1]),
93
+ std::invalid_argument("Cells with same dimension have to be ordered co-lexicographically."));
94
+ }
95
+ GUDHI_CHECK(filtValues[i].num_generators() == 1,
96
+ std::invalid_argument("Only available for 1-critical modules."));
97
+ )
98
+
99
+ Index startDim1, startDim2, end;
100
+ _get_complex_indices(complex, dim, startDim1, startDim2, end);
101
+
102
+ Index nberDim = startDim2 - startDim1;
103
+ Index nberDim1 = end - startDim2;
104
+ Index nberGen = nberDim + nberDim1;
105
+ Index shift = startDim1;
106
+
107
+ Matrix M(nberGen);
108
+ Matrix N(nberGen); // slave
109
+ std::vector<bool> isReduced(nberGen);
110
+ // TODO : pivot caches are small : maybe use a flat container instead ?
111
+ std::vector<std::set<int>> pivotCache(nberGen); // this[pivot] = cols of given pivot
112
+
113
+ auto get_pivot = [&M, shift](Index i) { return _get_pivot(M, i, shift); };
114
+
115
+ _initialize_matrices(startDim1, end, boundaries, M, N);
116
+ _initialize_containers(nberDim, nberGen, shift, filtValues, dimensions, get_pivot, pivotCache, isReduced);
117
+ SmallQueue lexicoIt = _initialize_lex_queue(nberDim, nberGen, shift, filtValues, pivotCache, get_pivot);
118
+
119
+ while (!lexicoIt.empty()) {
120
+ Filtration_value gridValue = lexicoIt.pop();
121
+ for (int i : lexicoIt.get_current_cols()) {
122
+ while (_reduce_column(complex, i, isReduced, pivotCache, M, N, gridValue, get_pivot));
123
+ _update_after_new_pivot(i, lexicoIt, pivotCache, filtValues, gridValue, get_pivot);
124
+ }
125
+ }
126
+ }
127
+
128
+ /**
129
+ * @brief Returns the kernel generators. (? TODO)
130
+ */
131
+ Boundary_container build_generators()
132
+ {
133
+ Index start = 0;
134
+ while (dimensions_[start] == dimensions_[0]) ++start;
135
+ return Boundary_container(boundaries_.begin() + start, boundaries_.end());
136
+ }
137
+
138
+ /**
139
+ * @brief Returns a complex representing the projective cover kernel.
140
+ */
141
+ Complex create_complex() { return Complex(boundaries_, dimensions_, filtrationValues_); }
142
+
143
+ private:
144
+ /**
145
+ * @brief Lexicographically ordered queue. Each filtration value is represented once and contains the list of indices
146
+ * of the columns with this filtration value.
147
+ */
148
+ struct SmallQueue {
149
+ SmallQueue() = default;
150
+
151
+ struct MFWrapper {
152
+ MFWrapper(const Filtration_value &g) : g(g) {};
153
+
154
+ MFWrapper(const Filtration_value &g, int col) : g(g) { someCols.insert(col); }
155
+
156
+ MFWrapper(const Filtration_value &g, std::initializer_list<int> cols) : g(g), someCols(cols.begin(), cols.end())
157
+ {}
158
+
159
+ void insert(int col) const { someCols.insert(col); }
160
+
161
+ bool operator<(const MFWrapper &other) const { return is_strict_less_than_lexicographically(g, other.g); }
162
+
163
+ public:
164
+ Filtration_value g;
165
+ mutable std::set<int> someCols;
166
+ };
167
+
168
+ void insert(const Filtration_value &g, int col)
169
+ {
170
+ auto it = queue.find(g);
171
+ if (it != queue.end()) {
172
+ it->insert(col);
173
+ } else {
174
+ queue.emplace(g, col);
175
+ }
176
+ };
177
+
178
+ void insert(const Filtration_value &g, const std::initializer_list<int> &cols)
179
+ {
180
+ auto it = queue.find(g);
181
+ if (it != queue.end()) {
182
+ for (int c : cols) it->insert(c);
183
+ } else {
184
+ queue.emplace(g, cols);
185
+ }
186
+ };
187
+
188
+ [[nodiscard]] bool empty() const { return queue.empty(); }
189
+
190
+ Filtration_value pop()
191
+ {
192
+ if (queue.empty()) throw std::runtime_error("Queue is empty");
193
+
194
+ auto out = std::move(*queue.begin());
195
+ queue.erase(queue.begin());
196
+ std::swap(lastCols, out.someCols);
197
+ return out.g;
198
+ }
199
+
200
+ const auto &get_current_cols() const { return lastCols; }
201
+
202
+ private:
203
+ std::set<MFWrapper> queue;
204
+ std::set<int> lastCols;
205
+ };
206
+
207
+ Boundary_container boundaries_; /** Boundary container. */
208
+ Dimension_container dimensions_; /** Dimension container. */
209
+ Filtration_value_container filtrationValues_; /** Filtration value container. */
210
+
211
+ static void _get_complex_indices(const Complex &complex,
212
+ Dimension dim,
213
+ Index &startDim1,
214
+ Index &startDim2,
215
+ Index &end)
216
+ {
217
+ const auto &dims = complex.get_dimensions();
218
+ startDim1 = 0;
219
+ startDim2 = 0;
220
+ end = 0;
221
+
222
+ Index i = 0;
223
+ auto size = complex.get_number_of_cycle_generators();
224
+ for (; i < size && dims[i] < dim; ++i);
225
+ if (i == size) throw std::invalid_argument("Given dimension has no generators.");
226
+ startDim1 = i;
227
+ for (; i < size && dims[i] == dim; ++i);
228
+ if (i == size || dims[i] > dim + 1) throw std::invalid_argument("Given dimension has no generators.");
229
+ startDim2 = i;
230
+ for (; i < size && dims[i] == dim + 1; ++i);
231
+ end = i;
232
+ }
233
+
234
+ static int _get_pivot(Matrix &M, Index i, Index shift)
235
+ {
236
+ const auto &col = M.get_column(i);
237
+ return col.size() > 0 ? (*col.rbegin()).get_row_index() - shift : -1;
238
+ }
239
+
240
+ static void _initialize_matrices(Index start, Index end, const Boundary_container &boundaries, Matrix &M, Matrix &N)
241
+ {
242
+ for (Index i = start; i < end; i++) {
243
+ M.insert_boundary(boundaries[i]);
244
+ N.insert_boundary({i - start});
245
+ }
246
+ }
247
+
248
+ template <typename F>
249
+ static SmallQueue _initialize_lex_queue(Index nberDim,
250
+ Index nberGen,
251
+ Index shift,
252
+ const Filtration_value_container &filtValues,
253
+ const std::vector<std::set<int>> &pivotCache,
254
+ F &&get_pivot)
255
+ {
256
+ SmallQueue lexicoIt;
257
+ for (Index i = nberDim; i < nberGen; ++i) {
258
+ int pivot = std::forward<F>(get_pivot)(i);
259
+ if (pivot >= 0) {
260
+ lexicoIt.insert(filtValues[i + shift], i);
261
+ auto it = pivotCache[pivot].find(i);
262
+ GUDHI_CHECK(it != pivotCache[pivot].end(), std::runtime_error("Column not registered in pivot cache."));
263
+ it++;
264
+ for (; it != pivotCache[pivot].end(); ++it) {
265
+ int colIdx = *it;
266
+ GUDHI_CHECK(static_cast<Index>(colIdx) > i, std::runtime_error("Column not registered in the right order."));
267
+ auto prev = filtValues[colIdx + shift];
268
+ prev.push_to_least_common_upper_bound(filtValues[i + shift]);
269
+ lexicoIt.insert(std::move(prev), colIdx);
270
+ }
271
+ }
272
+ }
273
+ return lexicoIt;
274
+ }
275
+
276
+ template <typename F>
277
+ static void _update_after_new_pivot(Index i,
278
+ SmallQueue &lexicoIt,
279
+ std::vector<std::set<int>> &pivotCache,
280
+ const Filtration_value_container &filtValues,
281
+ const Filtration_value &gridValue,
282
+ F &&get_pivot)
283
+ {
284
+ int pivot = std::forward<F>(get_pivot)(i);
285
+
286
+ if (pivot < 0) return;
287
+
288
+ auto [it, wasThere] = pivotCache[pivot].insert(i);
289
+ it++;
290
+ for (; it != pivotCache[pivot].end(); ++it) {
291
+ int colIdx = *it;
292
+ GUDHI_CHECK(static_cast<Index>(colIdx) > i,
293
+ std::runtime_error("(update) Column not registered in the right order."));
294
+ auto prev = filtValues[colIdx];
295
+ if (!(prev >= filtValues[i])) {
296
+ prev.push_to_least_common_upper_bound(filtValues[i]);
297
+ if (is_strict_less_than_lexicographically(gridValue, prev)) {
298
+ lexicoIt.insert(prev, colIdx);
299
+ }
300
+ }
301
+ }
302
+ }
303
+
304
+ template <typename F>
305
+ void _initialize_containers(Index nberDim,
306
+ Index nberGen,
307
+ Index shift,
308
+ const Filtration_value_container &filtValues,
309
+ const Dimension_container &dimensions,
310
+ F &&get_pivot,
311
+ std::vector<std::set<int>> &pivotCache,
312
+ std::vector<bool> &isReduced)
313
+ {
314
+ Index size = (nberGen - nberDim) * 2;
315
+ boundaries_.reserve(size);
316
+ filtrationValues_.reserve(size);
317
+ dimensions_.reserve(size);
318
+
319
+ for (Index i = nberDim; i < nberGen; ++i) {
320
+ boundaries_.emplace_back();
321
+ filtrationValues_.push_back(filtValues[i + shift]);
322
+ dimensions_.push_back(dimensions[i + shift]);
323
+ int pivot = std::forward<F>(get_pivot)(i);
324
+ if (pivot < 0) {
325
+ isReduced[i] = true;
326
+ } else {
327
+ auto &currentCache = pivotCache[pivot];
328
+ currentCache.emplace_hint(currentCache.cend(), i); // j is increasing
329
+ }
330
+ }
331
+ }
332
+
333
+ template <typename F>
334
+ bool _reduce_column(const Complex &complex,
335
+ Index i,
336
+ std::vector<bool> &isReduced,
337
+ std::vector<std::set<int>> &pivotCache,
338
+ Matrix &M,
339
+ Matrix &N,
340
+ const Filtration_value &gridValue,
341
+ F &&get_pivot)
342
+ {
343
+ int pivot = std::forward<F>(get_pivot)(i);
344
+ if (pivot < 0) {
345
+ if (!isReduced[i]) {
346
+ const auto &col = N.get_column(i);
347
+ boundaries_.emplace_back(col.begin(), col.end());
348
+ filtrationValues_.emplace_back(gridValue);
349
+ dimensions_.emplace_back(complex.get_dimensions()[i] + 1);
350
+ isReduced[i] = true;
351
+ }
352
+ return false;
353
+ }
354
+ // WARN : we lazy update variables linked with col i...
355
+ if (pivotCache[pivot].size() == 0) {
356
+ return false;
357
+ }
358
+ const auto &filtValues = complex.get_filtration_values();
359
+ for (Index k : pivotCache[pivot]) {
360
+ if (k >= i) { // cannot reduce more here. this is a (local) pivot.
361
+ return false;
362
+ }
363
+ if (filtValues[k] <= gridValue) {
364
+ M.add_to(k, i);
365
+ N.add_to(k, i);
366
+ pivotCache[pivot].erase(i);
367
+ // WARN : we update the pivot cache after the update loop
368
+ GUDHI_CHECK(std::forward<F>(get_pivot)(i) < pivot, std::runtime_error("Column addition failed."));
369
+ return true; // pivot has changed
370
+ }
371
+ }
372
+ return false; // for loop exhausted (i may not be there because of lazy)
373
+ }
374
+ };
375
+
376
+ } // namespace multi_persistence
377
+ } // namespace Gudhi
378
+
379
+ #endif // MP_PROJECTIVE_COVER_KERNEL_H_INCLUDED
@@ -0,0 +1,69 @@
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): Marc Glisse
4
+ *
5
+ * Copyright (C) 2015 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+ #ifndef SIMPLE_OBJECT_POOL_H_
12
+ #define SIMPLE_OBJECT_POOL_H_
13
+
14
+ #include <boost/pool/pool.hpp>
15
+ #include <utility>
16
+
17
+ namespace Gudhi {
18
+
19
+ /** \private
20
+ * This is a simpler version of boost::object_pool, that requires
21
+ * that users explicitly destroy all objects. This lets the
22
+ * performance scale much better, see
23
+ * https://svn.boost.org/trac/boost/ticket/3789 .
24
+ */
25
+ template <class T>
26
+ class Simple_object_pool : protected boost::pool<boost::default_user_allocator_malloc_free> {
27
+ protected:
28
+ typedef boost::pool<boost::default_user_allocator_malloc_free> Base;
29
+ typedef T* pointer;
30
+
31
+ Base& base() {
32
+ return *this;
33
+ }
34
+
35
+ Base const& base()const {
36
+ return *this;
37
+ }
38
+
39
+ public:
40
+ typedef T element_type;
41
+ typedef boost::default_user_allocator_malloc_free user_allocator;
42
+ typedef typename Base::size_type size_type;
43
+ typedef typename Base::difference_type difference_type;
44
+
45
+ template<class...U>
46
+ Simple_object_pool(U&&...u) : Base(sizeof (T), std::forward<U>(u)...) { }
47
+
48
+ template<class...U>
49
+ pointer construct(U&&...u) {
50
+ void* p = base().malloc BOOST_PREVENT_MACRO_SUBSTITUTION();
51
+ assert(p);
52
+ try {
53
+ new(p) T(std::forward<U>(u)...);
54
+ } catch (...) {
55
+ base().free BOOST_PREVENT_MACRO_SUBSTITUTION(p);
56
+ throw;
57
+ }
58
+ return static_cast<pointer> (p);
59
+ }
60
+
61
+ void destroy(pointer p) {
62
+ p->~T();
63
+ base().free BOOST_PREVENT_MACRO_SUBSTITUTION(p);
64
+ }
65
+ };
66
+
67
+ } // namespace Gudhi
68
+
69
+ #endif // SIMPLE_OBJECT_POOL_H_