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