multipers 2.3.3b6__cp312-cp312-manylinux_2_39_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (182) hide show
  1. multipers/__init__.py +33 -0
  2. multipers/_signed_measure_meta.py +453 -0
  3. multipers/_slicer_meta.py +211 -0
  4. multipers/array_api/__init__.py +45 -0
  5. multipers/array_api/numpy.py +41 -0
  6. multipers/array_api/torch.py +58 -0
  7. multipers/data/MOL2.py +458 -0
  8. multipers/data/UCR.py +18 -0
  9. multipers/data/__init__.py +1 -0
  10. multipers/data/graphs.py +466 -0
  11. multipers/data/immuno_regions.py +27 -0
  12. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  13. multipers/data/pytorch2simplextree.py +91 -0
  14. multipers/data/shape3d.py +101 -0
  15. multipers/data/synthetic.py +113 -0
  16. multipers/distances.py +202 -0
  17. multipers/filtration_conversions.pxd +229 -0
  18. multipers/filtration_conversions.pxd.tp +84 -0
  19. multipers/filtrations/__init__.py +18 -0
  20. multipers/filtrations/density.py +574 -0
  21. multipers/filtrations/filtrations.py +361 -0
  22. multipers/filtrations.pxd +224 -0
  23. multipers/function_rips.cpython-312-x86_64-linux-gnu.so +0 -0
  24. multipers/function_rips.pyx +105 -0
  25. multipers/grids.cpython-312-x86_64-linux-gnu.so +0 -0
  26. multipers/grids.pyx +433 -0
  27. multipers/gudhi/Persistence_slices_interface.h +132 -0
  28. multipers/gudhi/Simplex_tree_interface.h +239 -0
  29. multipers/gudhi/Simplex_tree_multi_interface.h +551 -0
  30. multipers/gudhi/cubical_to_boundary.h +59 -0
  31. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
  32. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
  33. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
  34. multipers/gudhi/gudhi/Debug_utils.h +45 -0
  35. multipers/gudhi/gudhi/Fields/Multi_field.h +484 -0
  36. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -0
  37. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -0
  38. multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -0
  39. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -0
  40. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -0
  41. multipers/gudhi/gudhi/Fields/Z2_field.h +355 -0
  42. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -0
  43. multipers/gudhi/gudhi/Fields/Zp_field.h +420 -0
  44. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -0
  45. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -0
  46. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
  47. multipers/gudhi/gudhi/Matrix.h +2107 -0
  48. multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -0
  49. multipers/gudhi/gudhi/Multi_persistence/Box.h +174 -0
  50. multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -0
  51. multipers/gudhi/gudhi/Off_reader.h +173 -0
  52. multipers/gudhi/gudhi/One_critical_filtration.h +1441 -0
  53. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -0
  54. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -0
  55. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -0
  56. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -0
  57. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -0
  58. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -0
  59. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -0
  60. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -0
  61. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -0
  62. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -0
  63. multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -0
  64. multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -0
  65. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -0
  66. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -0
  67. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -0
  68. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -0
  69. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -0
  70. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -0
  71. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -0
  72. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -0
  73. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -0
  74. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -0
  75. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -0
  76. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -0
  77. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -0
  78. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -0
  79. multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -0
  80. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -0
  81. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -0
  82. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -0
  83. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -0
  84. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -0
  85. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -0
  86. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -0
  87. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
  88. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
  89. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
  90. multipers/gudhi/gudhi/Persistent_cohomology.h +745 -0
  91. multipers/gudhi/gudhi/Points_off_io.h +171 -0
  92. multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
  93. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -0
  94. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
  95. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -0
  96. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
  97. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
  98. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
  99. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -0
  100. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -0
  101. multipers/gudhi/gudhi/Simplex_tree.h +2794 -0
  102. multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -0
  103. multipers/gudhi/gudhi/distance_functions.h +62 -0
  104. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
  105. multipers/gudhi/gudhi/persistence_interval.h +253 -0
  106. multipers/gudhi/gudhi/persistence_matrix_options.h +170 -0
  107. multipers/gudhi/gudhi/reader_utils.h +367 -0
  108. multipers/gudhi/mma_interface_coh.h +256 -0
  109. multipers/gudhi/mma_interface_h0.h +223 -0
  110. multipers/gudhi/mma_interface_matrix.h +293 -0
  111. multipers/gudhi/naive_merge_tree.h +536 -0
  112. multipers/gudhi/scc_io.h +310 -0
  113. multipers/gudhi/truc.h +1403 -0
  114. multipers/io.cpython-312-x86_64-linux-gnu.so +0 -0
  115. multipers/io.pyx +644 -0
  116. multipers/ml/__init__.py +0 -0
  117. multipers/ml/accuracies.py +90 -0
  118. multipers/ml/invariants_with_persistable.py +79 -0
  119. multipers/ml/kernels.py +176 -0
  120. multipers/ml/mma.py +713 -0
  121. multipers/ml/one.py +472 -0
  122. multipers/ml/point_clouds.py +352 -0
  123. multipers/ml/signed_measures.py +1589 -0
  124. multipers/ml/sliced_wasserstein.py +461 -0
  125. multipers/ml/tools.py +113 -0
  126. multipers/mma_structures.cpython-312-x86_64-linux-gnu.so +0 -0
  127. multipers/mma_structures.pxd +128 -0
  128. multipers/mma_structures.pyx +2786 -0
  129. multipers/mma_structures.pyx.tp +1094 -0
  130. multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -0
  131. multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -0
  132. multipers/multi_parameter_rank_invariant/function_rips.h +322 -0
  133. multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -0
  134. multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -0
  135. multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -0
  136. multipers/multiparameter_edge_collapse.py +41 -0
  137. multipers/multiparameter_module_approximation/approximation.h +2330 -0
  138. multipers/multiparameter_module_approximation/combinatory.h +129 -0
  139. multipers/multiparameter_module_approximation/debug.h +107 -0
  140. multipers/multiparameter_module_approximation/euler_curves.h +0 -0
  141. multipers/multiparameter_module_approximation/format_python-cpp.h +286 -0
  142. multipers/multiparameter_module_approximation/heap_column.h +238 -0
  143. multipers/multiparameter_module_approximation/images.h +79 -0
  144. multipers/multiparameter_module_approximation/list_column.h +174 -0
  145. multipers/multiparameter_module_approximation/list_column_2.h +232 -0
  146. multipers/multiparameter_module_approximation/ru_matrix.h +347 -0
  147. multipers/multiparameter_module_approximation/set_column.h +135 -0
  148. multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -0
  149. multipers/multiparameter_module_approximation/unordered_set_column.h +166 -0
  150. multipers/multiparameter_module_approximation/utilities.h +403 -0
  151. multipers/multiparameter_module_approximation/vector_column.h +223 -0
  152. multipers/multiparameter_module_approximation/vector_matrix.h +331 -0
  153. multipers/multiparameter_module_approximation/vineyards.h +464 -0
  154. multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -0
  155. multipers/multiparameter_module_approximation.cpython-312-x86_64-linux-gnu.so +0 -0
  156. multipers/multiparameter_module_approximation.pyx +235 -0
  157. multipers/pickle.py +90 -0
  158. multipers/plots.py +456 -0
  159. multipers/point_measure.cpython-312-x86_64-linux-gnu.so +0 -0
  160. multipers/point_measure.pyx +395 -0
  161. multipers/simplex_tree_multi.cpython-312-x86_64-linux-gnu.so +0 -0
  162. multipers/simplex_tree_multi.pxd +134 -0
  163. multipers/simplex_tree_multi.pyx +10840 -0
  164. multipers/simplex_tree_multi.pyx.tp +2009 -0
  165. multipers/slicer.cpython-312-x86_64-linux-gnu.so +0 -0
  166. multipers/slicer.pxd +3034 -0
  167. multipers/slicer.pxd.tp +234 -0
  168. multipers/slicer.pyx +20481 -0
  169. multipers/slicer.pyx.tp +1088 -0
  170. multipers/tensor/tensor.h +672 -0
  171. multipers/tensor.pxd +13 -0
  172. multipers/test.pyx +44 -0
  173. multipers/tests/__init__.py +62 -0
  174. multipers/torch/__init__.py +1 -0
  175. multipers/torch/diff_grids.py +240 -0
  176. multipers/torch/rips_density.py +310 -0
  177. multipers-2.3.3b6.dist-info/METADATA +128 -0
  178. multipers-2.3.3b6.dist-info/RECORD +182 -0
  179. multipers-2.3.3b6.dist-info/WHEEL +5 -0
  180. multipers-2.3.3b6.dist-info/licenses/LICENSE +21 -0
  181. multipers-2.3.3b6.dist-info/top_level.txt +1 -0
  182. multipers.libs/libtbb-ca48af5c.so.12.16 +0 -0
@@ -0,0 +1,769 @@
1
+ #pragma once
2
+
3
+ #include "Simplex_tree_multi_interface.h"
4
+ #include "multi_parameter_rank_invariant/persistence_slices.h"
5
+ #include "tensor/tensor.h"
6
+ #include <algorithm>
7
+ #include <gudhi/One_critical_filtration.h>
8
+ #include <gudhi/truc.h>
9
+ #include <iostream>
10
+ #include <limits>
11
+ #include <oneapi/tbb/enumerable_thread_specific.h>
12
+ #include <oneapi/tbb/parallel_for.h>
13
+ #include <ostream>
14
+ #include <utility> // std::pair
15
+ #include <vector>
16
+
17
+ namespace Gudhi {
18
+ namespace multiparameter {
19
+ namespace hilbert_function {
20
+
21
+ // TODO : this function is ugly
22
+ template <typename Filtration, typename indices_type>
23
+ inline typename Filtration::value_type horizontal_line_filtration2(const Filtration &x,
24
+ indices_type height,
25
+ indices_type i,
26
+ indices_type j,
27
+ const std::vector<indices_type> &fixed_values) {
28
+ const auto &inf = Filtration::Generator::T_inf;
29
+ for (indices_type k = 0u; k < static_cast<indices_type>(x.size()); k++) {
30
+ if (k == i || k == j) continue; // coordinate in the plane
31
+ if (x[k] > fixed_values[k]) // simplex appears after the plane
32
+ return inf;
33
+ }
34
+ if (x[j] <= height) // simplex apppears in the plane, but is it in the line
35
+ // with height "height"
36
+ return x[i];
37
+ else
38
+ return inf;
39
+ }
40
+
41
+ template <typename index_type>
42
+ using hilbert_thread_data = tbb::enumerable_thread_specific<std::pair<Simplex_tree_std, std::vector<index_type>>>;
43
+
44
+ template <typename Filtration, typename dtype, typename index_type>
45
+ inline void compute_2d_hilbert_surface(
46
+ python_interface::Simplex_tree_multi_interface<Filtration> &st_multi,
47
+ // Simplex_tree_std &_st,
48
+ hilbert_thread_data<index_type> &thread_simplex_tree,
49
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
50
+ const std::vector<index_type> grid_shape,
51
+ const std::vector<index_type> degrees,
52
+ index_type i,
53
+ index_type j,
54
+ const std::vector<index_type> fixed_values,
55
+ bool mobius_inverion,
56
+ bool zero_pad,
57
+ int expand_collapse_dim = 0) {
58
+ using value_type = typename Filtration::value_type;
59
+ // if (grid_shape.size() < 2 || st_multi.get_number_of_parameters() < 2)
60
+ // throw std::invalid_argument("Grid shape has to have at least 2
61
+ // element."); if (st_multi.get_number_of_parameters() - fixed_values.size()
62
+ // != 2) throw std::invalid_argument("Fix more values for the
63
+ // simplextree, which has a too big number of parameters");
64
+ // assert(fixed_values.size() == st_multi.get_number_of_parameters());
65
+
66
+ constexpr const bool verbose = false;
67
+ index_type I = grid_shape[i + 1], J = grid_shape[j + 1];
68
+ if constexpr (verbose) std::cout << "Grid shape : " << I << " " << J << std::endl;
69
+
70
+ // grid2d out(I, std::vector<int>(J,0)); // zero of good size
71
+ // std::vector<std::vector<index_type>> free_coordinates(grid_shape.size());
72
+ // for (auto [r,k] = std::views::zip(free_coordinates,
73
+ // std::ranges::iota(0,free_coordinates.size()))){ if (k==i) r =
74
+ // std::ranges::iota(0,I); else if (k==j) r= std::ranges::iota(0,J);
75
+ // else fixed_values[k];
76
+ // }
77
+ // tensor::static_tensor_view_view<value_type, index_type> dim2_view(out,
78
+ // free_coordinates); auto coordinates_container =
79
+
80
+ // Simplex_tree_std _st;
81
+ // flatten<Simplex_tree_float,
82
+ // Gudhi::multi_persistence::Simplex_tree_options_multidimensional_filtration>(_st, st_multi,-1); //
83
+ // copies the st_multi to a standard 1-pers simplextree
84
+ // tbb::enumerable_thread_specific<std::pair<Simplex_tree_std,
85
+ // std::vector<index_type>>> thread_simplex_tree;
86
+ tbb::parallel_for(0, J, [&](index_type height) {
87
+ // SIMPLEXTREE INIT
88
+ auto &[st_std, coordinates_container] = thread_simplex_tree.local();
89
+ // if (st_std.num_simplices() == 0){ st_std = _st;}
90
+ // COORDINATES INIT
91
+ // if (coordinates_container.size() == 0) {
92
+ // //This init is fine as only the j+1th coord is touched
93
+ // coordinates_container.reserve(fixed_values.size()+1);
94
+ // coordinates_container.push_back(0); // degree
95
+ // for (auto c : fixed_values) coordinates_container.push_back(c);
96
+ // }
97
+ // coordinates_container.resize(fixed_values.size()+1); // Not necessary
98
+
99
+ // if (coordinates_container.size() != fixed_values.size()+1 ||
100
+ // st_std.num_simplices() == 0){ throw std::runtime_error("Bad tbb thread
101
+ // local storage initialization.");
102
+ // }
103
+ // Coordinate initialization to fixed values
104
+ // coordinates_container[0] = 0; // not necessary
105
+ // for (auto [c, i] : std::views::zip(fixed_values, std::views::iota(0u,
106
+ // fixed_values.size()))) // NIK APPLE CLANG coordinates_container[i+1] = c;
107
+ for (auto i = 0u; i < fixed_values.size(); i++) coordinates_container[i + 1] = fixed_values[i];
108
+
109
+ coordinates_container[j + 1] = height;
110
+
111
+ Filtration multi_filtration(st_multi.get_number_of_parameters());
112
+ auto sh_standard = st_std.complex_simplex_range().begin();
113
+ auto _end = st_std.complex_simplex_range().end();
114
+ auto sh_multi = st_multi.complex_simplex_range().begin();
115
+ for (; sh_standard != _end; ++sh_multi, ++sh_standard) {
116
+ // for (auto [sh_standard, sh_multi] :
117
+ // std::ranges::views::zip(st_std.complex_simplex_range(),
118
+ // st_multi.complex_simplex_range())){ // too bad apple clang exists
119
+ multi_filtration = st_multi.filtration(*sh_multi);
120
+ typename Simplex_tree_std::Filtration_value horizontal_filtration;
121
+ if constexpr (Filtration::is_multi_critical) {
122
+ horizontal_filtration = std::numeric_limits<typename Simplex_tree_std::Filtration_value>::infinity();
123
+ for (const auto &stuff : multi_filtration)
124
+ horizontal_filtration = std::min(horizontal_filtration,
125
+ static_cast<Simplex_tree_std::Filtration_value>(
126
+ horizontal_line_filtration2(stuff, height, i, j, fixed_values)));
127
+ } else {
128
+ horizontal_filtration = horizontal_line_filtration2(multi_filtration, height, i, j, fixed_values);
129
+ }
130
+ st_std.assign_filtration(*sh_standard, horizontal_filtration);
131
+
132
+ if constexpr (verbose) {
133
+ Gudhi::multi_filtration::One_critical_filtration<int> splx;
134
+ for (auto vertex : st_multi.simplex_vertex_range(*sh_multi)) splx.push_back(vertex);
135
+ std::cout << "Simplex " << splx << "/" << st_std.num_simplices() << " Filtration multi "
136
+ << st_multi.filtration(*sh_multi) << " Filtration 1d " << st_std.filtration(*sh_standard) << "\n";
137
+ }
138
+ }
139
+
140
+ if constexpr (verbose) {
141
+ std::cout << "Coords : " << height << " [";
142
+ for (auto stuff : fixed_values) std::cout << stuff << " ";
143
+ std::cout << "]" << std::endl;
144
+ }
145
+ const std::vector<Barcode> barcodes = compute_dgms(st_std, degrees, expand_collapse_dim);
146
+ index_type degree_index = 0;
147
+ for (const auto &barcode : barcodes) { // TODO range view cartesian product
148
+ coordinates_container[0] = degree_index;
149
+ for (const auto &bar : barcode) {
150
+ auto birth = bar.first; // float
151
+ auto death = bar.second;
152
+ // if constexpr (verbose) std::cout << "BEFORE " << birth << " " <<
153
+ // death << " " << I << " \n"; death = death > I ? I : death; // TODO
154
+ // FIXME if constexpr (verbose) std::cout <<"AFTER" << birth << " " <<
155
+ // death << " " << I << " \n";
156
+ if (birth > I) // some birth can be infinite
157
+ continue;
158
+
159
+ if (!mobius_inverion) {
160
+ // throw std::logic_error("Not implemented");
161
+ // death = death > I ? I : death;
162
+ // for (int index = static_cast<int>(birth); index <
163
+ // static_cast<int>(death); index ++){
164
+ // out[degree_index][index][height]++;
165
+ // }
166
+
167
+ // Seems to bug on linux ????
168
+
169
+ coordinates_container[i + 1] = static_cast<index_type>(birth);
170
+ index_type shift_value = out.get_cum_resolution()[i + 1];
171
+ index_type border = I;
172
+ // index_type border = out.get_resolution()[i+1];
173
+ dtype *ptr = &out[coordinates_container];
174
+ auto stop_value = death > static_cast<value_type>(border) ? border : static_cast<index_type>(death);
175
+ // Warning : for some reason linux static casts float inf to -min_int
176
+ // so min doesnt work.
177
+ if constexpr (verbose) {
178
+ std::cout << "Adding : (";
179
+ for (auto stuff : coordinates_container) std::cout << stuff << ", ";
180
+ std::cout << ") With death " << death << " casted at " << static_cast<index_type>(death)
181
+ << "with threshold at" << stop_value << " with " << border << std::endl;
182
+ }
183
+ for (index_type b = birth; b < stop_value; b++) {
184
+ (*ptr)++; // adds one to the vector
185
+ ptr += shift_value; // shift the pointer to the next element in the
186
+ // segment [birth, death]
187
+ }
188
+ } else {
189
+ // out[degree_index][static_cast<int>(birth)][height]++; // No need to
190
+ // do mobius inversion on this axis, it can be done here if (death <
191
+ // I) out[degree_index][static_cast<int>(death)][height]--;
192
+ // else if (zero_pad)
193
+ // {
194
+ // out[degree_index].back()[height]--;
195
+ // }
196
+ // coordinates_container[0] = degree_index;
197
+ coordinates_container[i + 1] = static_cast<index_type>(birth);
198
+ out[coordinates_container]++;
199
+
200
+ if constexpr (verbose) {
201
+ std::cout << "Coordinate : ";
202
+ for (auto c : coordinates_container) std::cout << c << ", ";
203
+ std::cout << std::endl;
204
+ std::cout << "axis, death, resolution : " << i + 1 << ", " << std::to_string(death) << ", "
205
+ << out.get_resolution()[i + 1];
206
+ std::cout << std::endl;
207
+ }
208
+
209
+ if (death < I) {
210
+ coordinates_container[i + 1] = static_cast<index_type>(death);
211
+ out[coordinates_container]--;
212
+ } else if (zero_pad) {
213
+ coordinates_container[i + 1] = I - 1;
214
+ out[coordinates_container]--;
215
+ }
216
+ }
217
+ // else
218
+ // out[I-1][height]--;
219
+ }
220
+ degree_index++;
221
+ }
222
+ });
223
+ return;
224
+ }
225
+
226
+ template <typename Filtration, typename dtype, typename index_type>
227
+ void _rec_get_hilbert_surface(python_interface::Simplex_tree_multi_interface<Filtration> &st_multi,
228
+ // Simplex_tree_std &_st,
229
+ hilbert_thread_data<index_type> &thread_simplex_tree,
230
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
231
+ const std::vector<index_type> grid_shape,
232
+ const std::vector<index_type> degrees,
233
+ std::vector<index_type> coordinates_to_compute,
234
+ const std::vector<index_type> fixed_values,
235
+ bool mobius_inverion = true,
236
+ bool zero_pad = false,
237
+ int expand_collapse_dim = 0) {
238
+ constexpr const bool verbose = false;
239
+
240
+ if constexpr (verbose) {
241
+ std::cout << "Computing coordinates (";
242
+ for (auto c : coordinates_to_compute) std::cout << c << ", ";
243
+ std::cout << "). with fixed values (";
244
+ for (auto c : fixed_values) {
245
+ std::cout << c << ", ";
246
+ }
247
+ std::cout << ")." << std::endl;
248
+ }
249
+ if (coordinates_to_compute.size() == 2) {
250
+ compute_2d_hilbert_surface(st_multi,
251
+ // _st,
252
+ thread_simplex_tree,
253
+ out, // assumes its a zero tensor
254
+ grid_shape,
255
+ degrees,
256
+ coordinates_to_compute[0],
257
+ coordinates_to_compute[1],
258
+ fixed_values,
259
+ mobius_inverion,
260
+ zero_pad,
261
+ expand_collapse_dim);
262
+ return;
263
+ }
264
+
265
+ // coordinate to iterate.size --
266
+ auto coordinate_to_iterate = coordinates_to_compute.back();
267
+ coordinates_to_compute.pop_back();
268
+ tbb::parallel_for(0, grid_shape[coordinate_to_iterate + 1], [&](index_type z) {
269
+ // Updates fixes values that defines the slice
270
+ std::vector<index_type> _fixed_values = fixed_values; // TODO : do not copy this //thread local
271
+ _fixed_values[coordinate_to_iterate] = z;
272
+ _rec_get_hilbert_surface(st_multi,
273
+ thread_simplex_tree,
274
+ out,
275
+ grid_shape,
276
+ degrees,
277
+ coordinates_to_compute,
278
+ _fixed_values,
279
+ mobius_inverion,
280
+ zero_pad,
281
+ expand_collapse_dim);
282
+ });
283
+ // rmq : with mobius_inversion + rec, the coordinates to compute size is 2 =>
284
+ // first coord is always the initial 1st coord.
285
+ // => inversion is only needed for coords > 2
286
+ }
287
+
288
+ template <typename Filtration, typename dtype, typename index_type>
289
+ void get_hilbert_surface(python_interface::Simplex_tree_multi_interface<Filtration> &st_multi,
290
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
291
+ const std::vector<index_type> &grid_shape,
292
+ const std::vector<index_type> &degrees,
293
+ std::vector<index_type> coordinates_to_compute,
294
+ const std::vector<index_type> &fixed_values,
295
+ bool mobius_inverion = true,
296
+ bool zero_pad = false,
297
+ bool expand_collapse = false) {
298
+ if (degrees.size() == 0) return;
299
+ // wrapper arount the rec version, that initialize the thread variables.
300
+ if (coordinates_to_compute.size() < 2)
301
+ throw std::logic_error("Not implemented for " + std::to_string(coordinates_to_compute.size()) + "<2 parameters.");
302
+
303
+ Simplex_tree_std _st;
304
+ Gudhi::multi_persistence::flatten(_st, st_multi,
305
+ -1); // copies the st_multi to a standard 1-pers simplextree
306
+ std::vector<index_type> coordinates_container(st_multi.get_number_of_parameters() + 1); // +1 for degree
307
+ // coordinates_container.reserve(fixed_values.size()+1);
308
+ // coordinates_container.push_back(0); // degree
309
+ // for (auto c : fixed_values) coordinates_container.push_back(c);
310
+ std::pair<Simplex_tree_std, std::vector<index_type>> thread_data_initialization = {_st, coordinates_container};
311
+ const int max_dim = expand_collapse ? *std::max_element(degrees.begin(), degrees.end()) + 1 : 0;
312
+ tbb::enumerable_thread_specific<std::pair<Simplex_tree_std, std::vector<index_type>>> thread_simplex_tree(
313
+ thread_data_initialization); // this has a fixed size, so init should
314
+ // be benefic
315
+ _rec_get_hilbert_surface(st_multi,
316
+ thread_simplex_tree,
317
+ out,
318
+ grid_shape,
319
+ degrees,
320
+ coordinates_to_compute,
321
+ fixed_values,
322
+ mobius_inverion,
323
+ zero_pad,
324
+ max_dim);
325
+ }
326
+
327
+ template <typename Filtration, typename dtype = int, typename indices_type>
328
+ std::pair<std::vector<std::vector<indices_type>>, std::vector<dtype>> get_hilbert_signed_measure(
329
+ python_interface::Simplex_tree_multi_interface<Filtration> &st_multi,
330
+ dtype *data_ptr,
331
+ std::vector<indices_type> grid_shape,
332
+ const std::vector<indices_type> degrees,
333
+ bool zero_pad = false,
334
+ indices_type n_jobs = 0,
335
+ const bool verbose = false,
336
+ const bool expand_collapse = false) {
337
+ if (degrees.size() == 0) return {{}, {}};
338
+ // const bool verbose = false;
339
+ // auto &st_multi =
340
+ // get_simplextree_from_pointer<python_interface::interface_multi<Filtration>>(simplextree_ptr);
341
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr, grid_shape); // assumes its a zero tensor
342
+ std::vector<indices_type> coordinates_to_compute(st_multi.get_number_of_parameters());
343
+ for (auto i = 0u; i < coordinates_to_compute.size(); i++) coordinates_to_compute[i] = i;
344
+ // for (auto [c,i] : std::views::zip(coordinates_to_compute,
345
+ // std::views::iota(0,st_multi.get_number_of_parameters()))) c=i; // NIK apple
346
+ // clang
347
+ std::vector<indices_type> fixed_values(st_multi.get_number_of_parameters());
348
+
349
+ if (verbose) {
350
+ std::cout << "Container shape : ";
351
+ for (auto r : container.get_resolution()) std::cout << r << ", ";
352
+ std::cout << "\nContainer size : " << container.size();
353
+ std::cout << "\nComputing hilbert invariant ..." << std::flush;
354
+ }
355
+ if (zero_pad) {
356
+ // +1 is bc degree is on first axis.
357
+ for (auto i = 1; i < st_multi.get_number_of_parameters() + 1; i++)
358
+ grid_shape[i]--; // get hilbert surface computes according to grid_shape.
359
+ // for (auto i : std::views::iota(1,st_multi.get_number_of_parameters()+1))
360
+ // grid_shape[i]--; // get hilbert surface computes according to grid_shape.
361
+ }
362
+
363
+ oneapi::tbb::task_arena arena(n_jobs); // limits the number of threads
364
+ arena.execute([&] {
365
+ get_hilbert_surface(st_multi,
366
+ container,
367
+ grid_shape,
368
+ degrees,
369
+ coordinates_to_compute,
370
+ fixed_values,
371
+ true,
372
+ zero_pad,
373
+ expand_collapse);
374
+ });
375
+
376
+ if (verbose) {
377
+ std::cout << "Done.\n";
378
+ std::cout << "Computing mobius inversion ..." << std::flush;
379
+ }
380
+
381
+ // for (indices_type axis :
382
+ // std::views::iota(2,st_multi.get_number_of_parameters()+1)) // +1 for the
383
+ // degree in axis 0
384
+ for (indices_type axis = 2u; axis < st_multi.get_number_of_parameters() + 1; axis++) container.differentiate(axis);
385
+ if (verbose) {
386
+ std::cout << "Done.\n";
387
+ std::cout << "Sparsifying the measure ..." << std::flush;
388
+ }
389
+ auto raw_signed_measure = container.sparsify();
390
+ if (verbose) {
391
+ std::cout << "Done.\n";
392
+ }
393
+ return raw_signed_measure;
394
+ }
395
+
396
+ template <typename Filtration, typename dtype, typename indices_type, typename... Args>
397
+ void get_hilbert_surface_python(python_interface::Simplex_tree_multi_interface<Filtration> &st_multi,
398
+ dtype *data_ptr,
399
+ std::vector<indices_type> grid_shape,
400
+ const std::vector<indices_type> degrees,
401
+ const bool mobius_inversion,
402
+ const bool zero_pad,
403
+ indices_type n_jobs,
404
+ bool expand_collapse) {
405
+ constexpr const bool verbose = false;
406
+ if (degrees.size() == 0) return;
407
+ // const bool verbose = false;
408
+ // auto &st_multi =
409
+ // get_simplextree_from_pointer<python_interface::interface_multi<Filtration>>(simplextree_ptr);
410
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr, grid_shape); // assumes its a zero tensor
411
+ std::vector<indices_type> coordinates_to_compute(st_multi.get_number_of_parameters());
412
+ for (auto i = 0u; i < coordinates_to_compute.size(); i++) coordinates_to_compute[i] = i;
413
+ // for (auto [c,i] : std::views::zip(coordinates_to_compute,
414
+ // std::views::iota(0,st_multi.get_number_of_parameters()))) c=i; // NIK apple
415
+ // clang
416
+ std::vector<indices_type> fixed_values(st_multi.get_number_of_parameters());
417
+
418
+ if (verbose) {
419
+ std::cout << "Container shape : ";
420
+ for (auto r : container.get_resolution()) std::cout << r << ", ";
421
+ std::cout << "\nContainer size : " << container.size();
422
+ std::cout << "\nComputing hilbert invariant ...";
423
+ }
424
+ if (zero_pad) {
425
+ // +1 is bc degree is on first axis.
426
+ for (auto i = 1; i < st_multi.get_number_of_parameters() + 1; i++)
427
+ grid_shape[i]--; // get hilbert surface computes according to grid_shape.
428
+ // for (auto i : std::views::iota(1,st_multi.get_number_of_parameters()+1))
429
+ // grid_shape[i]--; // get hilbert surface computes according to grid_shape.
430
+ }
431
+
432
+ oneapi::tbb::task_arena arena(n_jobs); // limits the number of threads
433
+ arena.execute([&] {
434
+ get_hilbert_surface(st_multi,
435
+ container,
436
+ grid_shape,
437
+ degrees,
438
+ coordinates_to_compute,
439
+ fixed_values,
440
+ mobius_inversion,
441
+ zero_pad,
442
+ expand_collapse);
443
+ });
444
+
445
+ if (mobius_inversion)
446
+ for (indices_type axis = 2u; axis < st_multi.get_number_of_parameters() + 1; axis++) container.differentiate(axis);
447
+ return;
448
+ }
449
+
450
+ /// FROM SLICER
451
+ ///
452
+ ///
453
+
454
+ template <typename PersBackend, typename Structure, typename Filtration, typename dtype, typename index_type>
455
+ inline void compute_2d_hilbert_surface(
456
+ tbb::enumerable_thread_specific<std::pair<typename truc_interface::Truc<PersBackend, Structure, Filtration>::ThreadSafe,
457
+ std::vector<index_type>>> &thread_stuff,
458
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
459
+ const std::vector<index_type> grid_shape,
460
+ const std::vector<index_type> degrees,
461
+ index_type i,
462
+ index_type j,
463
+ const std::vector<index_type> fixed_values,
464
+ const bool mobius_inverion,
465
+ const bool zero_pad,
466
+ const bool ignore_inf = true ) {
467
+ using value_type = typename Filtration::value_type;
468
+
469
+ constexpr const bool verbose = false;
470
+ index_type I = grid_shape[i + 1], J = grid_shape[j + 1];
471
+ if constexpr (verbose) std::cout << "Grid shape : " << I << " " << J << std::endl;
472
+ tbb::parallel_for(0, J, [&](index_type height) {
473
+ // SIMPLEXTREE INIT
474
+ auto &[slicer, coordinates_container] = thread_stuff.local();
475
+ for (auto i = 0u; i < fixed_values.size(); i++) coordinates_container[i + 1] = fixed_values[i];
476
+
477
+ coordinates_container[j + 1] = height;
478
+
479
+ auto &slice_filtration = slicer.get_one_filtration();
480
+ const auto &multi_filtration = slicer.get_filtrations();
481
+
482
+ for (std::size_t k = 0; k < multi_filtration.size(); k++) {
483
+ value_type horizontal_filtration;
484
+ if constexpr (Filtration::is_multi_critical) {
485
+ horizontal_filtration = Filtration::Generator::T_inf;
486
+ for (const auto &stuff : multi_filtration[k])
487
+ horizontal_filtration =
488
+ std::min(horizontal_filtration,
489
+ static_cast<value_type>(horizontal_line_filtration2(stuff, height, i, j, fixed_values)));
490
+ } else {
491
+ horizontal_filtration = horizontal_line_filtration2(multi_filtration[k], height, i, j, fixed_values);
492
+ }
493
+ slice_filtration[k] = horizontal_filtration;
494
+ }
495
+
496
+ if constexpr (verbose) {
497
+ std::cout << "Coords : " << height << " [";
498
+ for (auto stuff : fixed_values) std::cout << stuff << " ";
499
+ std::cout << "]" << std::endl;
500
+ }
501
+ using bc_type = typename truc_interface::Truc<PersBackend, Structure, Filtration>::split_barcode;
502
+ if constexpr (PersBackend::is_vine) {
503
+ if (!slicer.has_persistence()) [[unlikely]] {
504
+ slicer.compute_persistence();
505
+ } else {
506
+ slicer.vineyard_update();
507
+ }
508
+ } else {
509
+ slicer.compute_persistence(ignore_inf);
510
+ }
511
+ bc_type barcodes = slicer.get_barcode();
512
+ index_type degree_index = 0;
513
+ for (auto degree : degrees) { // TODO range view cartesian product
514
+ const auto &barcode = barcodes[degree];
515
+ coordinates_container[0] = degree_index;
516
+ for (const auto &bar : barcode) {
517
+ auto birth = bar.first; // float
518
+ auto death = bar.second;
519
+ if (birth > I) // some birth can be infinite
520
+ continue;
521
+
522
+ if (!mobius_inverion) {
523
+ coordinates_container[i + 1] = static_cast<index_type>(birth);
524
+ index_type shift_value = out.get_cum_resolution()[i + 1];
525
+ index_type border = I;
526
+ // index_type border = out.get_resolution()[i+1];
527
+ dtype *ptr = &out[coordinates_container];
528
+ auto stop_value = death > static_cast<value_type>(border) ? border : static_cast<index_type>(death);
529
+ // Warning : for some reason linux static casts float inf to -min_int
530
+ // so min doesnt work.
531
+ if constexpr (verbose) {
532
+ std::cout << "Adding : (";
533
+ for (auto stuff : coordinates_container) std::cout << stuff << ", ";
534
+ std::cout << ") With death " << death << " casted at " << static_cast<index_type>(death)
535
+ << "with threshold at" << stop_value << " with " << border << std::endl;
536
+ }
537
+ for (index_type b = birth; b < stop_value; b++) {
538
+ (*ptr)++; // adds one to the vector
539
+ ptr += shift_value; // shift the pointer to the next element in the
540
+ // segment [birth, death]
541
+ }
542
+ } else {
543
+ coordinates_container[i + 1] = static_cast<index_type>(birth);
544
+ out[coordinates_container]++;
545
+
546
+ if constexpr (verbose) {
547
+ std::cout << "Coordinate : ";
548
+ for (auto c : coordinates_container) std::cout << c << ", ";
549
+ std::cout << std::endl;
550
+ std::cout << "axis, death, resolution : " << i + 1 << ", " << std::to_string(death) << ", "
551
+ << out.get_resolution()[i + 1];
552
+ std::cout << std::endl;
553
+ }
554
+
555
+ if (death < I) {
556
+ coordinates_container[i + 1] = static_cast<index_type>(death);
557
+ out[coordinates_container]--;
558
+ } else if (zero_pad) {
559
+ coordinates_container[i + 1] = I - 1;
560
+ out[coordinates_container]--;
561
+ }
562
+ }
563
+ }
564
+ degree_index++;
565
+ }
566
+ });
567
+ return;
568
+ }
569
+
570
+ template <typename PersBackend, typename Structure, typename Filtration, typename dtype, typename index_type>
571
+ void _rec_get_hilbert_surface(
572
+ tbb::enumerable_thread_specific<std::pair<typename truc_interface::Truc<PersBackend, Structure, Filtration>::ThreadSafe,
573
+ std::vector<index_type>>> &thread_stuff,
574
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
575
+ const std::vector<index_type> grid_shape,
576
+ const std::vector<index_type> degrees,
577
+ std::vector<index_type> coordinates_to_compute,
578
+ const std::vector<index_type> fixed_values,
579
+ const bool mobius_inverion = true,
580
+ const bool zero_pad = false,
581
+ const bool ignore_inf = true) {
582
+ constexpr const bool verbose = false;
583
+
584
+ if constexpr (verbose) {
585
+ std::cout << "Computing coordinates (";
586
+ for (auto c : coordinates_to_compute) std::cout << c << ", ";
587
+ std::cout << "). with fixed values (";
588
+ for (auto c : fixed_values) {
589
+ std::cout << c << ", ";
590
+ }
591
+ std::cout << ")." << std::endl;
592
+ }
593
+ if (coordinates_to_compute.size() == 2) {
594
+ compute_2d_hilbert_surface<PersBackend, Structure, Filtration, dtype, index_type>(thread_stuff,
595
+ out, // assumes its a zero tensor
596
+ grid_shape,
597
+ degrees,
598
+ coordinates_to_compute[0],
599
+ coordinates_to_compute[1],
600
+ fixed_values,
601
+ mobius_inverion,
602
+ zero_pad, ignore_inf);
603
+ return;
604
+ }
605
+
606
+ // coordinate to iterate.size --
607
+ auto coordinate_to_iterate = coordinates_to_compute.back();
608
+ coordinates_to_compute.pop_back();
609
+ tbb::parallel_for(0, grid_shape[coordinate_to_iterate + 1], [&](index_type z) {
610
+ // Updates fixes values that defines the slice
611
+ std::vector<index_type> _fixed_values = fixed_values; // TODO : do not copy this //thread local
612
+ _fixed_values[coordinate_to_iterate] = z;
613
+ _rec_get_hilbert_surface<PersBackend, Structure, Filtration, dtype, index_type>(
614
+ thread_stuff, out, grid_shape, degrees, coordinates_to_compute, _fixed_values, mobius_inverion, zero_pad, ignore_inf);
615
+ });
616
+ // rmq : with mobius_inversion + rec, the coordinates to compute size is 2 =>
617
+ // first coord is always the initial 1st coord.
618
+ // => inversion is only needed for coords > 2
619
+ }
620
+
621
+ template <typename PersBackend, typename Structure, typename Filtration, typename dtype, typename index_type>
622
+ void get_hilbert_surface(truc_interface::Truc<PersBackend, Structure, Filtration> &slicer,
623
+ const tensor::static_tensor_view<dtype, index_type> &out, // assumes its a zero tensor
624
+ const std::vector<index_type> &grid_shape,
625
+ const std::vector<index_type> &degrees,
626
+ std::vector<index_type> coordinates_to_compute,
627
+ const std::vector<index_type> &fixed_values,
628
+ const bool mobius_inverion = true,
629
+ const bool zero_pad = false,
630
+ const bool ignore_inf = true) {
631
+
632
+ if (degrees.size() == 0) return;
633
+ // wrapper arount the rec version, that initialize the thread variables.
634
+ if (coordinates_to_compute.size() < 2)
635
+ throw std::logic_error("Not implemented for " + std::to_string(coordinates_to_compute.size()) + "<2 parameters.");
636
+ using ThreadSafe = typename truc_interface::Truc<PersBackend, Structure, Filtration>::ThreadSafe;
637
+ ThreadSafe slicer_thread(slicer);
638
+ std::vector<index_type> coordinates_container(slicer_thread.num_parameters() + 1); // +1 for degree
639
+ // coordinates_container.reserve(fixed_values.size()+1);
640
+ // coordinates_container.push_back(0); // degree
641
+ // for (auto c : fixed_values) coordinates_container.push_back(c);
642
+ std::pair<ThreadSafe, std::vector<index_type>> thread_data_initialization = {slicer_thread, coordinates_container};
643
+ tbb::enumerable_thread_specific<std::pair<ThreadSafe, std::vector<index_type>>> thread_stuff(
644
+ thread_data_initialization); // this has a fixed size, so
645
+ // init should be benefic
646
+ _rec_get_hilbert_surface<PersBackend, Structure, Filtration, dtype, index_type>(
647
+ thread_stuff, out, grid_shape, degrees, coordinates_to_compute, fixed_values, mobius_inverion, zero_pad, ignore_inf);
648
+ }
649
+
650
+ template <typename PersBackend,
651
+ typename Structure,
652
+ typename Filtration,
653
+ typename dtype,
654
+ typename indices_type,
655
+ typename... Args>
656
+ void get_hilbert_surface_python(truc_interface::Truc<PersBackend, Structure, Filtration> &slicer,
657
+ dtype *data_ptr,
658
+ std::vector<indices_type> grid_shape,
659
+ const std::vector<indices_type> degrees,
660
+ const bool mobius_inversion,
661
+ const bool zero_pad,
662
+ const bool ignore_inf,
663
+ indices_type n_jobs) {
664
+ const bool verbose = false;
665
+ if (degrees.size() == 0) return;
666
+ // const bool verbose = false;
667
+ // auto &st_multi =
668
+ // get_simplextree_from_pointer<python_interface::interface_multi<Filtration>>(simplextree_ptr);
669
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr, grid_shape); // assumes its a zero tensor
670
+ int num_parameters = slicer.num_parameters();
671
+ std::vector<indices_type> coordinates_to_compute(num_parameters);
672
+ for (auto i = 0u; i < coordinates_to_compute.size(); i++) coordinates_to_compute[i] = i;
673
+ // for (auto [c,i] : std::views::zip(coordinates_to_compute,
674
+ // std::views::iota(0,st_multi.get_number_of_parameters()))) c=i; // NIK apple
675
+ // clang
676
+ std::vector<indices_type> fixed_values(num_parameters);
677
+
678
+ if (verbose) {
679
+ std::cout << "Container shape : ";
680
+ for (auto r : container.get_resolution()) std::cout << r << ", ";
681
+ std::cout << "\nContainer size : " << container.size();
682
+ std::cout << "\nComputing hilbert invariant ...";
683
+ }
684
+ if (zero_pad) {
685
+ // +1 is bc degree is on first axis.
686
+ for (auto i = 1; i < num_parameters + 1; i++)
687
+ grid_shape[i]--; // get hilbert surface computes according to grid_shape.
688
+ // for (auto i : std::views::iota(1,st_multi.get_number_of_parameters()+1))
689
+ // grid_shape[i]--; // get hilbert surface computes according to grid_shape.
690
+ }
691
+
692
+ oneapi::tbb::task_arena arena(PersBackend::is_vine ? 1 : n_jobs); // limits the number of threads
693
+ arena.execute([&] {
694
+ get_hilbert_surface(
695
+ slicer, container, grid_shape, degrees, coordinates_to_compute, fixed_values, mobius_inversion, zero_pad, ignore_inf);
696
+ });
697
+
698
+ if (mobius_inversion)
699
+ for (indices_type axis = 2u; axis < num_parameters + 1; axis++) container.differentiate(axis);
700
+ return;
701
+ }
702
+
703
+ template <typename PersBackend,
704
+ typename Structure,
705
+ typename Filtration,
706
+ typename dtype,
707
+ typename indices_type,
708
+ typename... Args>
709
+ std::pair<std::vector<std::vector<indices_type>>, std::vector<dtype>> get_hilbert_signed_measure(
710
+ truc_interface::Truc<PersBackend, Structure, Filtration> &slicer,
711
+ dtype *data_ptr,
712
+ std::vector<indices_type> grid_shape,
713
+ const std::vector<indices_type> degrees,
714
+ bool zero_pad = false,
715
+ indices_type n_jobs = 0,
716
+ const bool verbose = false,
717
+ const bool ignore_inf = true){
718
+ if (degrees.size() == 0) return {{}, {}};
719
+ // const bool verbose = false;
720
+ // auto &st_multi =
721
+ // get_simplextree_from_pointer<python_interface::interface_multi<Filtration>>(simplextree_ptr);
722
+ tensor::static_tensor_view<dtype, indices_type> container(data_ptr, grid_shape); // assumes its a zero tensor
723
+ std::vector<indices_type> coordinates_to_compute(slicer.num_parameters());
724
+ for (auto i = 0u; i < coordinates_to_compute.size(); i++) coordinates_to_compute[i] = i;
725
+ // for (auto [c,i] : std::views::zip(coordinates_to_compute,
726
+ // std::views::iota(0,st_multi.get_number_of_parameters()))) c=i; // NIK apple
727
+ // clang
728
+ std::vector<indices_type> fixed_values(slicer.num_parameters());
729
+
730
+ if (verbose) {
731
+ std::cout << "Container shape : ";
732
+ for (auto r : container.get_resolution()) std::cout << r << ", ";
733
+ std::cout << "\nContainer size : " << container.size();
734
+ std::cout << "\nComputing hilbert invariant ..." << std::flush;
735
+ }
736
+ if (zero_pad) {
737
+ // +1 is bc degree is on first axis.
738
+ for (auto i = 1u; i < slicer.num_parameters() + 1; i++)
739
+ grid_shape[i]--; // get hilbert surface computes according to grid_shape.
740
+ // for (auto i : std::views::iota(1,st_multi.get_number_of_parameters()+1))
741
+ // grid_shape[i]--; // get hilbert surface computes according to grid_shape.
742
+ }
743
+
744
+ oneapi::tbb::task_arena arena(PersBackend::is_vine ? 1 : n_jobs); // limits the number of threads
745
+ arena.execute([&] {
746
+ get_hilbert_surface(slicer, container, grid_shape, degrees, coordinates_to_compute, fixed_values, true, zero_pad, ignore_inf);
747
+ });
748
+
749
+ if (verbose) {
750
+ std::cout << "Done.\n";
751
+ std::cout << "Computing mobius inversion ..." << std::flush;
752
+ }
753
+
754
+ // for (indices_type axis :
755
+ // std::views::iota(2,st_multi.get_number_of_parameters()+1)) // +1 for the
756
+ // degree in axis 0
757
+ for (indices_type axis = 2; axis < static_cast<indices_type>(slicer.num_parameters() + 1); axis++)
758
+ container.differentiate(axis);
759
+ if (verbose) {
760
+ std::cout << "Done.\n";
761
+ std::cout << "Sparsifying the measure ..." << std::flush;
762
+ }
763
+ auto raw_signed_measure = container.sparsify();
764
+ if (verbose) {
765
+ std::cout << "Done." << std::endl;
766
+ }
767
+ return raw_signed_measure;
768
+ }
769
+ }}} // namespace Gudhi::multiparameter::hilbert_function