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,85 @@
1
+ #pragma once
2
+
3
+ #include <cstdint>
4
+ #include <vector>
5
+
6
+ #include "../gudhi/Simplex_tree_multi_interface.h"
7
+
8
+ namespace Gudhi {
9
+ namespace multiparameter {
10
+ namespace differentiation {
11
+
12
+ using signed_measure_indices = std::vector<std::vector<int32_t>>;
13
+ template <typename Filtration>
14
+ using interface_multi = python_interface::interface_multi<Filtration>;
15
+ template <typename Filtration>
16
+ using signed_measure_pts = std::vector<std::vector<typename Filtration::value_type>>;
17
+ template <typename Filtration>
18
+ using idx_map_type = std::vector<std::map<typename Filtration::value_type, int32_t>>;
19
+
20
+ // O(num_simplices)
21
+ template <typename Filtration>
22
+ idx_map_type<Filtration> build_idx_map(interface_multi<Filtration> &st, const std::vector<int> &simplices_dimensions) {
23
+ auto num_parameters = st.num_parameters();
24
+ if (static_cast<int>(simplices_dimensions.size()) < num_parameters) throw;
25
+ int max_dim = *std::max_element(simplices_dimensions.begin(), simplices_dimensions.end());
26
+ int min_dim = *std::min_element(simplices_dimensions.begin(), simplices_dimensions.end());
27
+ max_dim = min_dim >= 0 ? max_dim : st.dimension();
28
+
29
+ idx_map_type<Filtration> idx_map(num_parameters);
30
+ auto splx_idx = 0u;
31
+ for (auto sh : st.complex_simplex_range()) { // order has to be retrieved later, so I'm
32
+ // not sure that skeleton iterator is well
33
+ // suited
34
+ const auto &splx_filtration = st.filtration(sh);
35
+ const auto splx_dim = st.dimension(sh);
36
+ if (splx_dim <= max_dim)
37
+ for (auto i = 0u; i < splx_filtration.size(); i++) {
38
+ if (simplices_dimensions[i] != splx_dim and simplices_dimensions[i] != -1) continue;
39
+ auto f = splx_filtration[i];
40
+ idx_map[i].try_emplace(f, splx_idx);
41
+ }
42
+ splx_idx++;
43
+ }
44
+ return idx_map;
45
+ }
46
+
47
+ template <typename Filtration, typename... Args>
48
+ idx_map_type<Filtration> build_idx_map(const intptr_t simplextree_ptr, Args... args) {
49
+ auto &st_multi = get_simplextree_from_pointer<interface_multi<Filtration>>(simplextree_ptr);
50
+ return build_idx_map(st_multi, args...);
51
+ }
52
+
53
+ // O(signed_measure_size*num_parameters)
54
+ template <typename Filtration>
55
+ std::pair<signed_measure_indices, signed_measure_indices> get_signed_measure_indices(
56
+ const idx_map_type<Filtration> &idx_map,
57
+ const signed_measure_pts<Filtration> &pts) {
58
+ using value_type = typename Filtration::value_type;
59
+ std::size_t num_pts = pts.size();
60
+ std::size_t num_parameters = idx_map.size();
61
+ signed_measure_indices out_indices(
62
+ num_pts,
63
+ std::vector<int32_t>(num_parameters,
64
+ -1)); // -1 to be able from indicies to get if the pt is found or not
65
+ signed_measure_indices out_unmapped_values;
66
+ for (auto pt_idx = 0u; pt_idx < num_pts; pt_idx++) {
67
+ auto &pt = pts[pt_idx];
68
+ auto &pt_indices = out_indices[pt_idx];
69
+
70
+ for (std::size_t parameter = 0u; parameter < num_parameters; parameter++) {
71
+ value_type f = pt[parameter];
72
+ const std::map<value_type, int32_t> &parameter_map = idx_map[parameter];
73
+ auto it = parameter_map.find(f);
74
+ if (it == parameter_map.end())
75
+ out_unmapped_values.push_back({static_cast<int32_t>(pt_idx), static_cast<int32_t>(parameter)});
76
+ else
77
+ pt_indices[parameter] = it->second;
78
+ }
79
+ }
80
+ return {out_indices, out_unmapped_values}; // TODO return a ptr for python
81
+ }
82
+
83
+ } // namespace differentiation
84
+ } // namespace multiparameter
85
+ } // namespace Gudhi
@@ -0,0 +1,95 @@
1
+ #pragma once
2
+
3
+ #include <iostream>
4
+ #include <vector>
5
+ #include <utility> // std::pair
6
+
7
+ #include "../gudhi/Simplex_tree_multi_interface.h"
8
+ #include "../tensor/tensor.h"
9
+ #include "persistence_slices.h"
10
+
11
+
12
+ namespace Gudhi::multiparameter::euler_characteristic{
13
+
14
+
15
+ template<typename Filtration, typename dtype=int, typename index_type=std::uint16_t>
16
+ void get_euler_surface(
17
+ python_interface::Simplex_tree_multi_interface<Filtration, typename Filtration::value_type> &st_multi,
18
+ const tensor::static_tensor_view<dtype, index_type>& out, // assumes its a zero tensor
19
+ bool mobius_inversion,
20
+ bool zero_pad
21
+ ){
22
+ std::vector<index_type> coordinate_container(st_multi.num_parameters());
23
+ for (auto sh : st_multi.complex_simplex_range()){
24
+ const auto& multi_filtration = st_multi.filtration(sh);
25
+ for (index_type i=0u; i<st_multi.num_parameters(); i++){
26
+ coordinate_container[i] = static_cast<index_type>(multi_filtration(0,i));
27
+ }
28
+ int sign = 1-2*(st_multi.dimension(sh) % 2);
29
+ if (mobius_inversion && zero_pad)
30
+ out.add_cone_boundary(coordinate_container,sign);
31
+ else if (mobius_inversion)
32
+ out[coordinate_container] += sign;
33
+ else
34
+ out.add_cone(coordinate_container,sign);
35
+ }
36
+ return;
37
+ }
38
+
39
+
40
+ template<typename Filtration, typename dtype=int, typename indices_type=uint16_t>
41
+ std::pair<std::vector<std::vector<indices_type>>, std::vector<dtype>> get_euler_signed_measure(
42
+ python_interface::Simplex_tree_multi_interface<Filtration, typename Filtration::value_type>& st_multi,
43
+ dtype* data_ptr,
44
+ std::vector<indices_type> grid_shape,
45
+ bool zero_pad,
46
+ const bool verbose = false){
47
+ // const bool verbose = false;
48
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr,grid_shape); // assumes its a zero tensor
49
+ if (verbose){
50
+ std::cout << "Container shape : ";
51
+ for (auto r : container.get_resolution()) std::cout << r << ", ";
52
+ std::cout << "\nContainer size : " << container.size();
53
+ std::cout << "\nComputing Euler Characteristic ...";
54
+ }
55
+ get_euler_surface(st_multi,container,true, zero_pad);
56
+ if (verbose){
57
+ std::cout << "Done." << std::endl;
58
+ std::cout << "Sparsifying the measure ...";
59
+ }
60
+ auto raw_signed_measure = container.sparsify();
61
+ if (verbose){
62
+ std::cout << "Done." << std::endl;
63
+ }
64
+ return raw_signed_measure;
65
+ }
66
+
67
+
68
+ template<typename Filtration, typename dtype, typename indices_type, typename ... Args>
69
+ void get_euler_surface_python(
70
+ const intptr_t simplextree_ptr,
71
+ dtype* data_ptr,
72
+ const std::vector<indices_type> grid_shape,
73
+ bool mobius_inversion=false,
74
+ bool zero_pad = false,
75
+ bool verbose=false){
76
+ auto &st_multi = get_simplextree_from_pointer<python_interface::interface_multi<Filtration>>(simplextree_ptr);
77
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr,grid_shape); // assumes its a zero tensor
78
+ if (verbose){
79
+ std::cout << "Container shape : ";
80
+ for (auto r : container.get_resolution()) std::cout << r << ", ";
81
+ std::cout << "\nContainer size : " << container.size();
82
+ std::cout << "\nComputing Euler Characteristic ...";
83
+ }
84
+ get_euler_surface(st_multi,container,mobius_inversion, zero_pad);
85
+ if (verbose){
86
+ std::cout << "Done." << std::endl;
87
+ }
88
+ return;
89
+ }
90
+
91
+
92
+
93
+
94
+
95
+ } // namespace rank_invariant
@@ -0,0 +1,317 @@
1
+ #pragma once
2
+
3
+ #include <oneapi/tbb/enumerable_thread_specific.h>
4
+ #include <oneapi/tbb/parallel_for.h>
5
+ #include <limits>
6
+ #include <stdexcept>
7
+
8
+ #include "../gudhi/Simplex_tree_multi_interface.h"
9
+ #include "../tensor/tensor.h"
10
+ #include "persistence_slices.h"
11
+
12
+ namespace Gudhi {
13
+ namespace multiparameter {
14
+ namespace function_rips {
15
+
16
+ using value_type = typename python_interface::interface_std::Filtration_value;
17
+ // using _multifiltration = multipers::tmp_interface::Filtration_value<value_type>;
18
+ using flat_multifiltration = Gudhi::multi_filtration::Degree_rips_bifiltration<value_type>;
19
+ using _multifiltration = Gudhi::multi_filtration::Degree_rips_bifiltration<value_type>;
20
+ using _multi_st = python_interface::Simplex_tree_multi_interface<flat_multifiltration>;
21
+ using flat_multi_st = python_interface::Simplex_tree_multi_interface<flat_multifiltration>;
22
+ using mult_opt = Gudhi::multi_persistence::Simplex_tree_options_multidimensional_filtration<flat_multifiltration>;
23
+ using interface_multi = _multi_st;
24
+
25
+ std::pair<std::map<value_type, unsigned int>, std::vector<value_type>> inline radius_to_coordinate(
26
+ Simplex_tree_std &st) {
27
+ unsigned int count = 0;
28
+ std::map<value_type, unsigned int> out;
29
+ std::vector<value_type> filtration_values;
30
+ filtration_values.reserve(st.num_simplices());
31
+ for (auto sh : st.filtration_simplex_range()) { // ordered by filtration, so
32
+ // should be sorted
33
+ auto filtration = st.filtration(sh);
34
+ if (!out.contains(filtration)) {
35
+ out[filtration] = count;
36
+ filtration_values.push_back(filtration);
37
+ count++;
38
+ }
39
+ }
40
+ return {out, filtration_values};
41
+ }
42
+
43
+ // Takes a standard simplextree and turn it into a simplextreemulti, whose first
44
+ // axis is the rips, and the others are the filtrations of the node at each
45
+ // degree in degrees Assumes that the degrees are sorted, and unique
46
+ // also return max_degree,filtration_values
47
+ inline flat_multi_st get_degree_filtrations(python_interface::interface_std &st, const std::vector<int> &degrees) {
48
+ constexpr const bool verbose = false;
49
+ using filtration_lists = std::vector<std::vector<value_type>>;
50
+
51
+ if (st.dimension() != 1)
52
+ throw std::invalid_argument("get_degree_filtrations only works for 1-dimensional simplex trees.");
53
+
54
+ unsigned int num_degrees = degrees.size();
55
+ // puts the st filtration in axis 0 + fitrations for each degrees afterward
56
+ flat_multifiltration default_f(static_cast<int>(num_degrees), 0);
57
+ flat_multi_st st_multi(Gudhi::multi_persistence::make_multi_dimensional<mult_opt>(st, default_f, 0));
58
+
59
+ // preprocess
60
+ filtration_lists edge_filtration_of_nodes(st.num_vertices());
61
+ for (auto sh : st.complex_simplex_range()) {
62
+ if (st.dimension(sh) == 0) continue;
63
+ value_type filtration = st.filtration(sh);
64
+ for (auto node : st.simplex_vertex_range(sh)) {
65
+ edge_filtration_of_nodes[node].push_back(filtration);
66
+ }
67
+ }
68
+
69
+ tbb::parallel_for(static_cast<size_t>(0u), st.num_vertices(), [&](size_t i) {
70
+ auto &filtrations = edge_filtration_of_nodes[i];
71
+ tbb::parallel_sort(filtrations.begin(), filtrations.end());
72
+ unsigned int node_degree = filtrations.size();
73
+ filtrations.resize(std::max(num_degrees, node_degree));
74
+ for (unsigned int degree_index = 0; degree_index < num_degrees; degree_index++) {
75
+ if (degrees[degree_index] < static_cast<int>(node_degree))
76
+ filtrations[degree_index] = filtrations[degrees[degree_index]];
77
+ else
78
+ filtrations[degree_index] = std::numeric_limits<value_type>::infinity();
79
+ if constexpr (verbose) std::cout << filtrations[degree_index] << " ";
80
+ }
81
+ filtrations.resize(num_degrees);
82
+ std::reverse(filtrations.begin(),
83
+ filtrations.end()); // degree is in opposite direction
84
+ });
85
+
86
+ // fills the degree_rips simplextree with lower star
87
+ auto sh_standard = st.complex_simplex_range().begin(); // waiting for c++23 & zip to remove this garbage
88
+ auto _end = st.complex_simplex_range().end();
89
+ auto sh_multi = st_multi.complex_simplex_range().begin();
90
+ for (; sh_standard != _end; ++sh_multi, ++sh_standard) {
91
+ // only fill using t
92
+ // will be filled afterward
93
+ if (st.dimension(*sh_standard) == 0) continue;
94
+ // dimension is 1 by assumption. fill using the node + rips value
95
+ value_type edge_filtration = st.filtration(*sh_standard);
96
+ // the filtration vector to fill
97
+
98
+ std::vector<value_type> edge_degree_rips_filtration(num_degrees, std::numeric_limits<value_type>::infinity());
99
+
100
+ if constexpr (verbose) {
101
+ std::cout << "\nSetting filtration of edge [";
102
+ for (int node : st.simplex_vertex_range(*sh_standard)) {
103
+ std::cout << std::to_string(node) << ",";
104
+ }
105
+ std::cout << "] to : ";
106
+ }
107
+ for (auto degree_index = 0u; degree_index < num_degrees; degree_index++) {
108
+ value_type edge_filtration_of_degree = edge_filtration; // copy as we do the max with edges of degree index
109
+ for (int node : st.simplex_vertex_range(*sh_standard)) {
110
+ edge_filtration_of_degree = std::max(edge_filtration_of_degree, edge_filtration_of_nodes[node][degree_index]);
111
+ }
112
+
113
+ edge_degree_rips_filtration[degree_index] = edge_filtration_of_degree;
114
+ if (edge_filtration_of_degree == std::numeric_limits<value_type>::infinity()) break;
115
+ }
116
+
117
+ if constexpr (verbose) {
118
+ for (auto k = 0u; k < num_degrees; k++) std::cout << " " << std::to_string(edge_degree_rips_filtration[k]);
119
+ }
120
+ // std::reverse(edge_degree_rips_filtration.begin(), edge_degree_rips_filtration.end());
121
+ auto &to_update = st_multi.get_filtration_value(*sh_multi);
122
+ if (edge_degree_rips_filtration.size() != num_degrees)
123
+ throw std::overflow_error("edge_degree_rips of invalid size");
124
+ to_update.set_num_generators(edge_degree_rips_filtration.size());
125
+ for (auto k = 0u; k < edge_degree_rips_filtration.size(); k++) {
126
+ if (edge_degree_rips_filtration[k] == std::numeric_limits<value_type>::infinity()) {
127
+ to_update.set_num_generators(k);
128
+ break;
129
+ }
130
+
131
+ to_update(k, 0) = edge_degree_rips_filtration[k];
132
+ }
133
+ if constexpr (verbose) std::cout << "\n" << st_multi.get_filtration_value(*sh_multi) << std::endl;
134
+ }
135
+
136
+ // fills the dimension 0 simplices
137
+ for (auto vertex : st_multi.complex_vertex_range()) { // should be in increasing order
138
+ auto &vertex_filtration = st_multi.get_filtration_value(st_multi.find({vertex}));
139
+ if constexpr (verbose) {
140
+ std::cout << "Setting filtration of node " << vertex << " to ";
141
+ for (auto degree_index = 0u; degree_index < num_degrees; degree_index++) {
142
+ std::cout << edge_filtration_of_nodes[vertex][degree_index] << " ";
143
+ }
144
+ std::cout << "\n";
145
+ }
146
+
147
+ if (edge_filtration_of_nodes[vertex].size() > num_degrees)
148
+ throw std::overflow_error("Edge filtration of node of bad size");
149
+
150
+ vertex_filtration.set_num_generators(num_degrees);
151
+ for (auto k = 0u; k < num_degrees; k++) {
152
+ vertex_filtration(k, 0) = edge_filtration_of_nodes[vertex][k];
153
+ }
154
+ if constexpr (verbose) {
155
+ std::cout << "Filtration of node " << std::to_string(vertex) << " :\n" << vertex_filtration << "\n";
156
+ }
157
+ }
158
+ if constexpr (verbose) std::cout << std::endl;
159
+
160
+ return st_multi;
161
+ }
162
+
163
+ // assumes that the degree is 1
164
+ inline void fill_st_slice(Simplex_tree_std &st_container, flat_multi_st &degree_rips_st, int degree) {
165
+ auto sh_std = st_container.complex_simplex_range().begin();
166
+ auto sh_multi = degree_rips_st.complex_simplex_range().begin();
167
+ auto sh_end = st_container.complex_simplex_range().end();
168
+ for (; sh_std != sh_end; ++sh_std, ++sh_multi) {
169
+ value_type splx_filtration = degree_rips_st.get_filtration_value(*sh_multi)(0, degree);
170
+ st_container.assign_filtration(*sh_std, splx_filtration);
171
+ }
172
+ }
173
+
174
+ template <typename dtype, typename index_type>
175
+ inline void compute_2d_function_rips(
176
+ flat_multi_st &st_multi, // Function rips
177
+ // Simplex_tree_std &_st,
178
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
179
+ const std::vector<index_type> degrees,
180
+ index_type I,
181
+ index_type J, // grid_shape
182
+ bool mobius_inverion,
183
+ bool zero_pad) {
184
+ constexpr bool verbose = false;
185
+ if constexpr (verbose) std::cout << "Grid shape : " << I << " " << J << std::endl;
186
+
187
+ // inits default simplextrees
188
+ // copies the st_multi to a standard 1-pers simplextree, and puts its filtration values to 0 for all.
189
+ Simplex_tree_std _st(
190
+ st_multi,
191
+ []([[maybe_unused]] const flat_multifiltration &f) -> Simplex_tree_std::Filtration_value { return 0.; });
192
+ tbb::enumerable_thread_specific<Simplex_tree_std> thread_simplex_tree(_st);
193
+ int max_simplex_dimension = *std::max_element(degrees.begin(), degrees.end()) + 1;
194
+ tbb::parallel_for(0, J, [&](index_type function_value) {
195
+ auto &st_std = thread_simplex_tree.local();
196
+ fill_st_slice(st_std, st_multi, function_value);
197
+ constexpr int num_collapses = 10;
198
+ const std::vector<Barcode> barcodes = compute_dgms(st_std, degrees, num_collapses, max_simplex_dimension);
199
+
200
+ index_type degree_index = 0;
201
+ for (const auto &barcode : barcodes) { // TODO range view cartesian product
202
+ // coordinates_container[0] = degree_index;
203
+ for (const auto &bar : barcode) {
204
+ auto birth = bar.first; // float
205
+ auto death = bar.second;
206
+ if (birth > I) // some birth can be infinite
207
+ continue;
208
+
209
+ if (!mobius_inverion) {
210
+ index_type shift_value = out.get_cum_resolution()[1]; // degree, x coord, y coord
211
+ index_type border = I;
212
+ // index_type border = out.get_resolution()[i+1];
213
+ // dtype* ptr = &out[coordinates_container];
214
+ dtype *ptr = &out[{degree_index, static_cast<index_type>(birth), function_value}];
215
+ auto stop_value = death > static_cast<value_type>(border) ? border : static_cast<index_type>(death);
216
+ // Warning : for some reason linux static casts float inf to -min_int
217
+ // so min doesnt work.
218
+ if constexpr (verbose) {
219
+ std::cout << "Adding : (";
220
+ // for (auto stuff : coordinates_container) std::cout << stuff << ",
221
+ // ";
222
+ std::cout << ") With death " << death << " casted at " << static_cast<index_type>(death)
223
+ << "with threshold at" << stop_value << " with " << border << std::endl;
224
+ }
225
+ for (index_type b = birth; b < stop_value; b++) {
226
+ (*ptr)++; // adds one to the vector
227
+ ptr += shift_value; // shift the pointer to the next element in the
228
+ // segment [birth, death]
229
+ }
230
+ } else {
231
+ // adds birth
232
+ out[{degree_index, static_cast<index_type>(birth), function_value}]++;
233
+ if constexpr (verbose) {
234
+ std::cout << "Coordinate : ";
235
+ // for (auto c : coordinates_container) std::cout << c << ", ";
236
+ std::cout << std::endl;
237
+ std::cout << "axis, death, resolution : " << 1 << ", " << std::to_string(death) << ", "
238
+ << out.get_resolution()[1];
239
+ std::cout << std::endl;
240
+ }
241
+ // removes death
242
+ if (death < I) {
243
+ out[{degree_index, static_cast<index_type>(death), function_value}]--;
244
+ } else if (zero_pad) {
245
+ out[{degree_index, I - 1, function_value}]--;
246
+ }
247
+ }
248
+ }
249
+ degree_index++;
250
+ }
251
+ });
252
+ }
253
+
254
+ // python interface
255
+
256
+ inline void get_degree_rips_st_python(const intptr_t simplextree_ptr,
257
+ const intptr_t st_multi_ptr,
258
+ const std::vector<int> &degrees) {
259
+ auto &st_std = python_interface::get_simplextree_from_pointer<python_interface::interface_std>(simplextree_ptr);
260
+ auto &st_multi_python_container = python_interface::get_simplextree_from_pointer<flat_multi_st>(st_multi_ptr);
261
+ auto st_multi = get_degree_filtrations(st_std, degrees);
262
+ st_multi_python_container = std::move(st_multi);
263
+ }
264
+
265
+ template <typename dtype, typename indices_type>
266
+ void compute_function_rips_surface_python(const intptr_t st_multi_ptr,
267
+ dtype *data_ptr,
268
+ const std::vector<indices_type> degrees,
269
+ indices_type I,
270
+ indices_type J,
271
+ const bool mobius_inversion = false,
272
+ const bool zero_pad = false,
273
+ indices_type n_jobs = 0) {
274
+ if (degrees.size() == 0) return;
275
+ // const bool verbose = false;
276
+ auto &st_multi = python_interface::get_simplextree_from_pointer<flat_multi_st>(st_multi_ptr);
277
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr,
278
+ {static_cast<indices_type>(degrees.size()), I, J});
279
+ if (zero_pad) {
280
+ I--;
281
+ J--;
282
+ }
283
+
284
+ oneapi::tbb::task_arena arena(n_jobs); // limits the number of threads
285
+ arena.execute([&] { compute_2d_function_rips(st_multi, container, degrees, I, J, mobius_inversion, zero_pad); });
286
+ if (mobius_inversion) container.differentiate(2); // degree,x axis (already inversed), y axis
287
+ }
288
+
289
+ template <typename dtype, typename indices_type>
290
+ std::pair<std::vector<std::vector<indices_type>>, std::vector<dtype>> compute_function_rips_signed_measure_python(
291
+ const intptr_t st_multi_ptr,
292
+ dtype *data_ptr,
293
+ const std::vector<indices_type> degrees,
294
+ indices_type I,
295
+ indices_type J,
296
+ const bool mobius_inversion = false,
297
+ const bool zero_pad = false,
298
+ indices_type n_jobs = 0) {
299
+ if (degrees.size() == 0) return {{}, {}};
300
+ // const bool verbose = false;
301
+ auto &st_multi = python_interface::get_simplextree_from_pointer<interface_multi>(st_multi_ptr);
302
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr,
303
+ {static_cast<indices_type>(degrees.size()), I, J});
304
+ if (zero_pad) {
305
+ I--;
306
+ J--;
307
+ }
308
+
309
+ oneapi::tbb::task_arena arena(n_jobs); // limits the number of threads
310
+ arena.execute([&] { compute_2d_function_rips(st_multi, container, degrees, I, J, mobius_inversion, zero_pad); });
311
+ if (mobius_inversion) container.differentiate(2); // degree,x axis (already inversed), y axis
312
+ return container.sparsify();
313
+ }
314
+
315
+ } // namespace function_rips
316
+ } // namespace multiparameter
317
+ } // namespace Gudhi