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,149 @@
1
+ #pragma once
2
+
3
+ #include <oneapi/tbb/task_arena.h>
4
+ #include "../gudhi/gudhi/Flag_complex_edge_collapser.h"
5
+ #include "../gudhi/gudhi/Persistent_cohomology.h"
6
+ #include "../gudhi/gudhi/Multi_persistence/Box.h"
7
+ #include "../gudhi/gudhi/Simplex_tree/simplex_tree_options.h"
8
+ #include "../gudhi/gudhi/Simplex_tree.h"
9
+
10
+ namespace Gudhi {
11
+ namespace multiparameter {
12
+
13
+ struct Simplex_tree_float : Gudhi::Simplex_tree_options_default { // smaller simplextrees
14
+ typedef std::int32_t Vertex_handle;
15
+ typedef float Filtration_value;
16
+ // TODO: OPTIMIZATION, maybe make the simplextree contiguous when calling grid_squeeze ?
17
+ // static const bool contiguous_vertices = true;
18
+ static const bool link_nodes_by_label = true;
19
+ };
20
+
21
+ // using Simplex_tree_float = Simplex_tree_options_fast_persistence;
22
+
23
+ using Gudhi::multi_persistence::Box;
24
+ using Simplex_tree_std = Simplex_tree<Simplex_tree_float>;
25
+
26
+ using Barcode = std::vector<std::pair<Simplex_tree_std::Filtration_value, Simplex_tree_std::Filtration_value>>;
27
+
28
+ inline Barcode compute_dgm(Simplex_tree_std &st, int degree) {
29
+ st.initialize_filtration(true);
30
+ constexpr int coeff_field_characteristic = 11;
31
+ constexpr Simplex_tree_std::Filtration_value min_persistence = 0;
32
+ bool persistence_dim_max = st.dimension() == degree;
33
+ Gudhi::persistent_cohomology::Persistent_cohomology<Simplex_tree_std, Gudhi::persistent_cohomology::Field_Zp> pcoh(
34
+ st, persistence_dim_max);
35
+ pcoh.init_coefficients(coeff_field_characteristic);
36
+ pcoh.compute_persistent_cohomology(min_persistence);
37
+ const auto &persistent_pairs = pcoh.intervals_in_dimension(degree);
38
+ if constexpr (false) {
39
+ std::cout << "Number of bars : " << persistent_pairs.size() << "\n";
40
+ }
41
+ return persistent_pairs;
42
+ }
43
+
44
+ template <typename degree_type, class interface_std_like>
45
+ inline std::vector<Barcode> compute_dgms(interface_std_like &st,
46
+ const std::vector<degree_type> &degrees,
47
+ int num_collapses,
48
+ int expansion_dim) {
49
+
50
+ std::vector<Barcode> out(degrees.size());
51
+ // static_assert(!interface_std_like::Options::is_multi_parameter,
52
+ // "Can only compute persistence for 1-parameter simplextrees.");
53
+ const bool verbose = false;
54
+ if (num_collapses > 0) {
55
+ auto collapsed_st = collapse_edges(st, num_collapses);
56
+ return compute_dgms(collapsed_st, degrees, 0, expansion_dim);
57
+ }
58
+ // if (expansion_dim == -1){
59
+ // int max_dim = *std::max_element(degrees.begin(), degrees.end()) +1;
60
+ // st.expansion(max_dim);
61
+ // }
62
+ else if (expansion_dim > 0) {
63
+ st.expansion(expansion_dim);
64
+ }
65
+ tbb::task_arena arena(1);
66
+ arena.execute(
67
+ [&]{
68
+ st.initialize_filtration(true); // true is ignore_infinite_values
69
+ }
70
+ );
71
+ constexpr int coeff_field_characteristic = 11;
72
+ constexpr typename interface_std_like::Filtration_value min_persistence = 0;
73
+
74
+ bool persistence_dim_max = false;
75
+ for (auto degree : degrees) {
76
+ if (st.dimension() == degree) {
77
+ persistence_dim_max = true;
78
+ break;
79
+ }
80
+ }
81
+ //
82
+ if constexpr (verbose) {
83
+ std::cout << "Computing dgm of st:\n";
84
+ for (auto &sh : st.filtration_simplex_range()) {
85
+ std::cout << "dim: " << st.dimension(sh) << " vertices: ";
86
+ for (auto v : st.simplex_vertex_range(sh)) {
87
+ std::cout << v << " ";
88
+ }
89
+ std::cout << " filtration: ";
90
+ std::cout << st.filtration(sh) << "\n";
91
+ }
92
+ return out;
93
+ }
94
+
95
+ Gudhi::persistent_cohomology::Persistent_cohomology<interface_std_like, Gudhi::persistent_cohomology::Field_Zp> pcoh(
96
+ st, persistence_dim_max);
97
+ pcoh.init_coefficients(coeff_field_characteristic);
98
+ pcoh.compute_persistent_cohomology(min_persistence);
99
+ for (auto i = 0u; i < degrees.size(); i++) {
100
+ out[i] = pcoh.intervals_in_dimension(degrees[i]);
101
+ }
102
+ return out;
103
+ }
104
+
105
+ // small wrapper
106
+ template <typename degree_type, class interface_std_like>
107
+ inline std::vector<Barcode> compute_dgms(interface_std_like &st,
108
+ const std::vector<degree_type> &degrees,
109
+ int expand_collapse_dim = 0) {
110
+ if (expand_collapse_dim > 0) return compute_dgms(st, degrees, 10, expand_collapse_dim);
111
+ return compute_dgms(st, degrees, 0, 0);
112
+ }
113
+
114
+ // Adapted version from the Simplextree interface
115
+ template <class simplextree_like>
116
+ inline simplextree_like collapse_edges(simplextree_like &st, int num_collapses) {
117
+ using Filtered_edge = std::tuple<typename simplextree_like::Vertex_handle,
118
+ typename simplextree_like::Vertex_handle,
119
+ typename simplextree_like::Filtration_value>;
120
+ std::vector<Filtered_edge> edges;
121
+ for (auto sh : st.skeleton_simplex_range(1)) {
122
+ if (st.dimension(sh) == 1) {
123
+ const auto filtration = st.filtration(sh);
124
+ if (filtration == std::numeric_limits<typename simplextree_like::Filtration_value>::infinity()) continue;
125
+ typename simplextree_like::Simplex_vertex_range rg = st.simplex_vertex_range(sh);
126
+ auto vit = rg.begin();
127
+ typename simplextree_like::Vertex_handle v = *vit;
128
+ typename simplextree_like::Vertex_handle w = *++vit;
129
+ edges.emplace_back(v, w, filtration);
130
+ }
131
+ }
132
+ for (int iteration = 0; iteration < num_collapses; iteration++) {
133
+ auto current_size = edges.size();
134
+ edges = Gudhi::collapse::flag_complex_collapse_edges(std::move(edges));
135
+ if (edges.size() >= current_size) break; // no need to do more
136
+ }
137
+ simplextree_like collapsed_stree;
138
+ // Copy the original 0-skeleton
139
+ for (auto sh : st.skeleton_simplex_range(0)) {
140
+ collapsed_stree.insert_simplex({*(st.simplex_vertex_range(sh).begin())}, st.filtration(sh));
141
+ }
142
+ // Insert remaining edges
143
+ for (auto [x, y, filtration] : edges) {
144
+ collapsed_stree.insert_simplex({x, y}, filtration);
145
+ }
146
+ return collapsed_stree;
147
+ }
148
+
149
+ }} // namespace Gudhi::multiparameter
@@ -0,0 +1,350 @@
1
+ #pragma once
2
+
3
+ #include <algorithm>
4
+ #include <cstddef>
5
+ #include <oneapi/tbb/enumerable_thread_specific.h>
6
+ #include <oneapi/tbb/parallel_for.h>
7
+ #include <ostream>
8
+ #include <utility> // std::pair
9
+ #include <vector>
10
+
11
+ #include "../gudhi/gudhi/multi_simplex_tree_helpers.h"
12
+ #include "../gudhi/gudhi/Slicer.h"
13
+ #include "../tensor/tensor.h"
14
+ #include "persistence_slices.h"
15
+
16
+ namespace Gudhi {
17
+ namespace multiparameter {
18
+ namespace rank_invariant {
19
+ // using Index = truc_interface::index_type;
20
+
21
+ // using Elbow = std::vector<std::pair<>>;grid
22
+ template <typename index_type>
23
+ inline void push_in_elbow(index_type &i, index_type &j, const index_type I, const index_type J) {
24
+ if (j < J) {
25
+ j++;
26
+ return;
27
+ }
28
+ if (i < I) {
29
+ i++;
30
+ return;
31
+ }
32
+ j++;
33
+ return;
34
+ }
35
+
36
+ template <typename index_type, typename value_type>
37
+ inline value_type get_slice_rank_filtration(const value_type x,
38
+ const value_type y,
39
+ const index_type I,
40
+ const index_type J) {
41
+ if (x > static_cast<value_type>(I))
42
+ return std::numeric_limits<value_type>::has_infinity ? std::numeric_limits<value_type>::infinity()
43
+ : std::numeric_limits<value_type>::max();
44
+ if (y > static_cast<value_type>(J)) return I + static_cast<index_type>(y);
45
+ return J + static_cast<index_type>(x);
46
+ }
47
+
48
+ template <typename index_type>
49
+ inline std::pair<index_type, index_type> get_coordinates(index_type in_slice_value, index_type I, index_type J) {
50
+ if (in_slice_value <= J) return {0, J};
51
+ if (in_slice_value <= I + J) return {in_slice_value - J, J};
52
+ return {I, in_slice_value - I};
53
+ }
54
+
55
+ template <typename dtype, typename index_type, typename Filtration>
56
+ inline void compute_2d_rank_invariant_of_elbow(
57
+ Simplex_tree<Gudhi::multi_persistence::Simplex_tree_options_multidimensional_filtration<Filtration>> &st_multi,
58
+ Simplex_tree_std &_st_container, // copy of st_multi
59
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
60
+ const index_type I,
61
+ const index_type J,
62
+ const std::vector<index_type> &grid_shape,
63
+ const std::vector<index_type> &degrees,
64
+ const int expand_collapse_max_dim = 0) {
65
+ // const bool verbose = false; // verbose
66
+ using value_type = typename Simplex_tree_std::Filtration_value;
67
+ constexpr const value_type inf = std::numeric_limits<value_type>::infinity();
68
+
69
+ // const auto X = grid_shape[1], Y = grid_shape[2]; // First axis is degree
70
+ const auto Y = grid_shape[2];
71
+ // Fills the filtration in the container
72
+ // TODO : C++23 zip, when Apples clang will stop being obsolete
73
+ auto sh_standard = _st_container.complex_simplex_range().begin();
74
+ auto _end = _st_container.complex_simplex_range().end();
75
+ auto sh_multi = st_multi.complex_simplex_range().begin();
76
+ for (; sh_standard != _end; ++sh_multi, ++sh_standard) {
77
+ const Filtration &multi_filtration = st_multi.filtration(*sh_multi);
78
+ value_type filtration_in_slice = inf;
79
+ for (unsigned int g = 0; g < multi_filtration.num_generators(); ++g){
80
+ value_type x = multi_filtration(g, 0);
81
+ value_type y = multi_filtration(g, 1);
82
+ filtration_in_slice = std::min(filtration_in_slice, get_slice_rank_filtration(x, y, I, J));
83
+ }
84
+ _st_container.assign_filtration(*sh_standard, filtration_in_slice);
85
+ }
86
+ const std::vector<Barcode> &barcodes = compute_dgms(_st_container, degrees, expand_collapse_max_dim);
87
+ index_type degree_index = 0;
88
+ for (const auto &barcode : barcodes) { // TODO range view cartesian product
89
+ for (const auto &bar : barcode) {
90
+ auto birth = static_cast<index_type>(bar.first);
91
+ auto death = static_cast<index_type>(
92
+ std::min(bar.second,
93
+ static_cast<typename Simplex_tree_std::Filtration_value>(Y + I))); // I,J atteints, pas X ni Y
94
+
95
+ // todo : optimize
96
+ // auto [a,b] = get_coordinates(birth, I,J);
97
+ for (auto intermediate_birth = birth; intermediate_birth < death; intermediate_birth++) {
98
+ for (auto intermediate_death = intermediate_birth; intermediate_death < death; intermediate_death++) {
99
+ auto [i, j] = get_coordinates(intermediate_birth, I, J);
100
+ auto [k, l] = get_coordinates(intermediate_death, I, J);
101
+ if (((i < k || j == J) && (j < l || k == I))) {
102
+ // std::vector<index_type> coordinates_to_remove =
103
+ // {degree_index,i,j,k,l}; out[coordinates_to_remove]++;
104
+ out[{degree_index, i, j, k, l}]++;
105
+ }
106
+ }
107
+ }
108
+ }
109
+ degree_index++;
110
+ }
111
+ }
112
+
113
+ template <typename dtype, typename index_type, typename Filtration>
114
+ inline void compute_2d_rank_invariant(
115
+ Simplex_tree<Gudhi::multi_persistence::Simplex_tree_options_multidimensional_filtration<Filtration>> &st_multi,
116
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
117
+ const std::vector<index_type> &grid_shape,
118
+ const std::vector<index_type> &degrees,
119
+ bool expand_collapse) {
120
+ if (degrees.size() == 0) return;
121
+ assert(st_multi.num_parameters() == 2);
122
+ // copies the st_multi to a standard 1-pers simplextree
123
+ Simplex_tree_std st_ = Gudhi::multi_persistence::make_one_dimensional<Gudhi::multiparameter::Simplex_tree_float>(st_multi, 0);
124
+ const int max_dim = expand_collapse ? *std::max_element(degrees.begin(), degrees.end()) + 1 : 0;
125
+ index_type X = grid_shape[1];
126
+ index_type Y = grid_shape[2]; // First axis is degree
127
+ tbb::enumerable_thread_specific<Simplex_tree_std> thread_simplex_tree(st_); // initialize with a good simplextree
128
+ tbb::parallel_for(0, X, [&](index_type I) {
129
+ tbb::parallel_for(0, Y, [&](index_type J) {
130
+ auto &st_container = thread_simplex_tree.local();
131
+ compute_2d_rank_invariant_of_elbow<dtype, index_type, Filtration>(
132
+ st_multi, st_container, out, I, J, grid_shape, degrees, max_dim);
133
+ });
134
+ });
135
+ }
136
+
137
+ template <typename Filtration, typename dtype, typename indices_type, typename... Args>
138
+ void compute_rank_invariant_python(
139
+ Simplex_tree<Gudhi::multi_persistence::Simplex_tree_options_multidimensional_filtration<Filtration>> &st_multi,
140
+ dtype *data_ptr,
141
+ const std::vector<indices_type> grid_shape,
142
+ const std::vector<indices_type> degrees,
143
+ indices_type n_jobs,
144
+ bool expand_collapse) {
145
+ if (degrees.size() == 0) return;
146
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr, grid_shape); // assumes its a zero tensor
147
+
148
+ oneapi::tbb::task_arena arena(n_jobs); // limits the number of threads
149
+ arena.execute([&] {
150
+ compute_2d_rank_invariant<dtype, indices_type, Filtration>(
151
+ st_multi, container, grid_shape, degrees, expand_collapse);
152
+ });
153
+
154
+ return;
155
+ }
156
+
157
+ template <class PersBackend,
158
+ class MultiFiltration,
159
+ typename dtype,
160
+ typename index_type>
161
+ inline void compute_2d_rank_invariant_of_elbow(
162
+ typename Gudhi::multi_persistence::Slicer<MultiFiltration, PersBackend>::Thread_safe &slicer, // truc slicer
163
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
164
+ const index_type I,
165
+ const index_type J,
166
+ const std::vector<index_type> &grid_shape,
167
+ const std::vector<index_type> &degrees,
168
+ // std::vector<Index> &order_container, // constant size
169
+ // std::vector<typename MultiFiltration::value_type> &one_persistence, // constant size
170
+ const bool flip_death = false,
171
+ const bool ignore_inf = true) {
172
+ using value_type = typename MultiFiltration::value_type;
173
+ const auto &filtrations_values = slicer.get_filtration_values();
174
+ auto num_generators = filtrations_values.size();
175
+ // one_persistence.resize(num_generators); // local variable should be
176
+ // initialized correctly
177
+ const auto Y = grid_shape[2];
178
+ constexpr const bool verbose = false;
179
+ if constexpr (verbose) std::cout << "filtration_in_slice : [ ";
180
+ for (auto i = 0u; i < num_generators; ++i) {
181
+ const auto &f = filtrations_values[i];
182
+ value_type filtration_in_slice = MultiFiltration::T_inf;
183
+ for (unsigned int g = 0; g < f.num_generators(); ++g) {
184
+ value_type x = f(g,0);
185
+ value_type y = f(g,1);
186
+
187
+ filtration_in_slice = std::min(filtration_in_slice, get_slice_rank_filtration(x, y, I, J));
188
+ }
189
+ if constexpr (verbose) std::cout << filtration_in_slice << ",";
190
+ slicer.get_slice()[i] = filtration_in_slice;
191
+ }
192
+ if constexpr (verbose) std::cout << "\b]" << std::endl;
193
+
194
+ index_type degree_index = 0;
195
+ // order_container.resize(slicer.num_generators()); // local variable should
196
+ // be initialized correctly
197
+ // TODO : use slicer::Thread_safe instead of maintaining one_pers & order
198
+ // BUG : This will break as soon as slicer interface change
199
+
200
+ using bc_type = typename Gudhi::multi_persistence::Slicer<MultiFiltration, PersBackend>::template Multi_dimensional_flat_barcode<>;
201
+ if constexpr (PersBackend::is_vine) {
202
+ // slicer.set_one_filtration(one_persistence);
203
+ if (I == 0 && J == 0) [[unlikely]] // this is dangerous, assumes it starts at 0 0
204
+ {
205
+ // TODO : This is a good optimization but needs a patch on
206
+ // PersistenceMatrix std::vector<bool>
207
+ // degrees_index(slicer.get_dimensions().back()+1, false); for (const auto
208
+ // &degree : degrees) {
209
+ // if (degree <= slicer.get_dimensions())
210
+ // degrees_index[degree] = true;
211
+ // }
212
+ // slicer.compute_persistence(degrees_index);
213
+ slicer.initialize_persistence_computation();
214
+ } else {
215
+ slicer.vineyard_update();
216
+ }
217
+ } else {
218
+ slicer.initialize_persistence_computation(ignore_inf);
219
+ }
220
+ bc_type barcodes = slicer.template get_flat_barcode<true>();
221
+
222
+ // note one_pers not necesary when vine, but does the same computation
223
+
224
+ for (auto degree : degrees) {
225
+ // this assumes barcodes degrees starts from 0
226
+ if constexpr (verbose) std::cout << "Adding Barcode of degree " << degree << std::endl;
227
+ if (degree >= static_cast<index_type>(barcodes.size())) continue;
228
+ const auto &barcode = barcodes[degree];
229
+ for (const auto &bar : barcode) {
230
+ if (bar[0] > Y + I) continue;
231
+ if constexpr (verbose)
232
+ std::cout << bar[0] << " " << bar[1] << "checkinf: " << MultiFiltration::T_inf << " ==? "
233
+ << (bar[0] == MultiFiltration::T_inf) << std::endl;
234
+ auto birth = static_cast<index_type>(bar[0]);
235
+ auto death = static_cast<index_type>(
236
+ std::min(bar[1],
237
+ static_cast<typename MultiFiltration::value_type>(Y + I))); // I,J atteints, pas X ni Y
238
+ if constexpr (false) std::cout << "Birth " << birth << " Death " << death << std::endl;
239
+ for (auto intermediate_birth = birth; intermediate_birth < death; intermediate_birth++) {
240
+ for (auto intermediate_death = intermediate_birth; intermediate_death < death; intermediate_death++) {
241
+ auto [i, j] = get_coordinates(intermediate_birth, I, J);
242
+ auto [k, l] = get_coordinates(intermediate_death, I, J);
243
+ if (((i < k || j == J) && (j < l || k == I))) {
244
+ if (flip_death)
245
+ out[{degree_index, i, j, I - 1 - k, J - 1 - l}]++;
246
+ else
247
+ out[{degree_index, i, j, k, l}]++;
248
+ }
249
+ if constexpr (false) std::cout << degree_index << " " << i << " " << j << " " << k << " " << l << std::endl;
250
+ }
251
+ }
252
+ }
253
+ degree_index++;
254
+ }
255
+ };
256
+
257
+ template <class PersBackend,
258
+ class MultiFiltration,
259
+ typename dtype,
260
+ typename index_type>
261
+ inline void compute_2d_rank_invariant(
262
+ Gudhi::multi_persistence::Slicer<MultiFiltration, PersBackend> &slicer,
263
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
264
+ const std::vector<index_type> &grid_shape,
265
+ const std::vector<index_type> &degrees,
266
+ const bool flip_death,
267
+ const bool ignore_inf) {
268
+ if (degrees.size() == 0) return;
269
+ index_type X = grid_shape[1];
270
+ index_type Y = grid_shape[2]; // First axis is degree
271
+ constexpr const bool verbose = false;
272
+ if constexpr (verbose)
273
+ std::cout << "Shape " << grid_shape[0] << " " << grid_shape[1] << " " << grid_shape[2] << " " << grid_shape[3]
274
+ << " " << grid_shape[4] << std::endl;
275
+
276
+ using ThreadSafe = typename Gudhi::multi_persistence::Slicer<MultiFiltration, PersBackend>::Thread_safe;
277
+ ThreadSafe slicer_thread(slicer);
278
+ tbb::enumerable_thread_specific<ThreadSafe> thread_locals(slicer_thread);
279
+ tbb::parallel_for(0, X, [&](index_type I) {
280
+ tbb::parallel_for(0, Y, [&](index_type J) {
281
+ if constexpr (verbose) std::cout << "Computing elbow " << I << " " << J << "...";
282
+ ThreadSafe &slicer = thread_locals.local();
283
+ compute_2d_rank_invariant_of_elbow<PersBackend, MultiFiltration, dtype, index_type>(
284
+ slicer, out, I, J, grid_shape, degrees, flip_death, ignore_inf);
285
+ if constexpr (verbose) std::cout << "Done!" << std::endl;
286
+ });
287
+ });
288
+ }
289
+
290
+ template <class PersBackend,
291
+ class MultiFiltration,
292
+ typename dtype,
293
+ typename indices_type>
294
+ void compute_rank_invariant_python(Gudhi::multi_persistence::Slicer<MultiFiltration, PersBackend>& slicer,
295
+ dtype *data_ptr,
296
+ const std::vector<indices_type> grid_shape,
297
+ const std::vector<indices_type> degrees,
298
+ indices_type n_jobs,
299
+ const bool ignore_inf) {
300
+ if (degrees.size() == 0) return;
301
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr, grid_shape); // assumes its a zero tensor
302
+ if constexpr (false){
303
+ std::cout << "ignore_inf " << ignore_inf << std::endl;
304
+ }
305
+
306
+ oneapi::tbb::task_arena arena(PersBackend::is_vine ? 1 : n_jobs); // limits the number of threads
307
+ arena.execute([&] { compute_2d_rank_invariant(slicer, container, grid_shape, degrees, false, ignore_inf); });
308
+
309
+ return;
310
+ }
311
+
312
+ template <typename PersBackend,
313
+ typename MultiFiltration,
314
+ typename dtype = int,
315
+ typename indices_type = int>
316
+ std::pair<std::vector<std::vector<indices_type>>, std::vector<dtype>> compute_rank_signed_measure(
317
+ Gudhi::multi_persistence::Slicer<MultiFiltration, PersBackend>& slicer,
318
+ dtype *data_ptr,
319
+ const std::vector<indices_type> grid_shape,
320
+ const std::vector<indices_type> degrees,
321
+ indices_type n_jobs,
322
+ bool verbose,
323
+ const bool ignore_inf) {
324
+ if (degrees.size() == 0) return {{}, {}};
325
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr, grid_shape); // assumes its a zero tensor
326
+ oneapi::tbb::task_arena arena(n_jobs); // limits the number of threads
327
+ constexpr bool flip_death = true;
328
+ arena.execute([&] { compute_2d_rank_invariant(slicer, container, grid_shape, degrees, flip_death, ignore_inf); });
329
+
330
+ if (verbose) {
331
+ std::cout << "Done.\n";
332
+ std::cout << "Computing mobius inversion ..." << std::flush;
333
+ }
334
+
335
+ // for (indices_type axis :
336
+ // std::views::iota(2,st_multi.num_parameters()+1)) // +1 for the
337
+ // degree in axis 0
338
+ for (std::size_t axis = 0u; axis < slicer.get_number_of_parameters() + 1; axis++) container.differentiate(axis);
339
+ if (verbose) {
340
+ std::cout << "Done.\n";
341
+ std::cout << "Sparsifying the measure ..." << std::flush;
342
+ }
343
+ auto raw_signed_measure = container.sparsify({false, false, true, true});
344
+ if (verbose) {
345
+ std::cout << "Done.\n";
346
+ }
347
+ return raw_signed_measure;
348
+ }
349
+
350
+ }}} // namespace Gudhi::multiparameter::rank_invariant
@@ -0,0 +1,41 @@
1
+ from tqdm import tqdm
2
+
3
+
4
+ def _collapse_edge_list(
5
+ edges,
6
+ num: int = 0,
7
+ full: bool = False,
8
+ strong: bool = False,
9
+ progress: bool = False,
10
+ ):
11
+ """
12
+ Given an edge list defining a 1 critical 2 parameter 1 dimensional simplicial complex, simplificates this filtered simplicial complex, using filtration-domination's edge collapser.
13
+ """
14
+ from filtration_domination import (
15
+ remove_filtration_dominated,
16
+ remove_strongly_filtration_dominated,
17
+ )
18
+
19
+ n = len(edges)
20
+ if full:
21
+ num = 100
22
+ with tqdm(
23
+ range(num), total=num, desc="Removing edges", disable=not (progress)
24
+ ) as I:
25
+ for i in I:
26
+ if strong:
27
+ edges = remove_strongly_filtration_dominated(edges) # nogil ?
28
+ else:
29
+ edges = remove_filtration_dominated(edges)
30
+ # Prevents doing useless collapses
31
+ if len(edges) >= n:
32
+ if full and strong:
33
+ strong = False
34
+ n = len(edges)
35
+ # n = edges.size() # len(edges)
36
+ else:
37
+ break
38
+ else:
39
+ n = len(edges)
40
+ # n = edges.size()
41
+ return edges