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,237 @@
|
|
|
1
|
+
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
|
|
2
|
+
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
|
|
3
|
+
* Author(s): Hannah Schreiber
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2025 Inria
|
|
6
|
+
*
|
|
7
|
+
* Modification(s):
|
|
8
|
+
* - YYYY/MM Author: Description of the modification
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file multi_filtration_conversions.h
|
|
13
|
+
* @author Hannah Schreiber
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#ifndef MF_CONVERSIONS_H_
|
|
17
|
+
#define MF_CONVERSIONS_H_
|
|
18
|
+
|
|
19
|
+
#include <algorithm>
|
|
20
|
+
#include <cstddef>
|
|
21
|
+
#include <numeric>
|
|
22
|
+
#include <stdexcept>
|
|
23
|
+
#include <type_traits>
|
|
24
|
+
#include <vector>
|
|
25
|
+
|
|
26
|
+
#include <gudhi/Multi_parameter_filtration.h>
|
|
27
|
+
#include <gudhi/Dynamic_multi_parameter_filtration.h>
|
|
28
|
+
#include <gudhi/Degree_rips_bifiltration.h>
|
|
29
|
+
|
|
30
|
+
namespace Gudhi {
|
|
31
|
+
|
|
32
|
+
namespace multi_filtration {
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @brief Converts the given multi filtration value into the type given as template argument. It is assumed that the
|
|
36
|
+
* given value is simplified (i.e. minimal and ordered lexicographically). If the new type is
|
|
37
|
+
* @ref Gudhi::multi_filtration::Degree_rips_bifiltration it is additionally assumed that the given value is compatible
|
|
38
|
+
* with the type, that is,the number of parameters is 2 and the second parameter is an index (positive and convertible
|
|
39
|
+
* to an integer without loss).
|
|
40
|
+
*
|
|
41
|
+
* @tparam Out_multi_filtration New filtration value type. Has to be either
|
|
42
|
+
* @ref Gudhi::multi_filtration::Multi_parameter_filtration,
|
|
43
|
+
* @ref Gudhi::multi_filtration::Dynamic_multi_parameter_filtration or
|
|
44
|
+
* @ref Gudhi::multi_filtration::Degree_rips_bifiltration with desired template arguments.
|
|
45
|
+
* @tparam T First template argument of the initial filtration value type.
|
|
46
|
+
* @tparam Co Second template argument of the initial filtration value type.
|
|
47
|
+
* @tparam Ensure1Criticality Third template argument of the initial filtration value type.
|
|
48
|
+
* @param f Filtration value to convert.
|
|
49
|
+
*/
|
|
50
|
+
template <class Out_multi_filtration, typename T, bool Co, bool Ensure1Criticality>
|
|
51
|
+
Out_multi_filtration as_type(const Multi_parameter_filtration<T, Co, Ensure1Criticality>& f)
|
|
52
|
+
{
|
|
53
|
+
using U = typename Out_multi_filtration::value_type;
|
|
54
|
+
constexpr bool co = Out_multi_filtration::has_negative_cones();
|
|
55
|
+
constexpr bool one_crit = Out_multi_filtration::ensures_1_criticality();
|
|
56
|
+
|
|
57
|
+
if constexpr (std::is_same_v<Out_multi_filtration, Multi_parameter_filtration<U, co, one_crit> >) {
|
|
58
|
+
return f.template as_type<U, co, one_crit>();
|
|
59
|
+
} else if constexpr (std::is_same_v<Out_multi_filtration, Dynamic_multi_parameter_filtration<U, co, one_crit> >) {
|
|
60
|
+
return Out_multi_filtration(f.begin(), f.end(), f.num_parameters());
|
|
61
|
+
} else if constexpr (std::is_same_v<Out_multi_filtration, Degree_rips_bifiltration<U, co, one_crit> >) {
|
|
62
|
+
if (f.num_parameters() != 2) throw std::invalid_argument("Cannot convert a non-bifiltration to a bifiltration.");
|
|
63
|
+
U inf = co ? Out_multi_filtration::T_m_inf : Out_multi_filtration::T_inf;
|
|
64
|
+
|
|
65
|
+
T maxIndex = 0;
|
|
66
|
+
for (std::size_t g = 0; g < f.num_generators(); ++g) {
|
|
67
|
+
maxIndex = maxIndex < f(g, 1) ? f(g, 1) : maxIndex;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
std::vector<U> values(maxIndex + 1, inf);
|
|
71
|
+
for (std::size_t g = 0; g < f.num_generators(); ++g) {
|
|
72
|
+
values[f(g, 1)] = f(g, 0);
|
|
73
|
+
}
|
|
74
|
+
return Out_multi_filtration(std::move(values), 2);
|
|
75
|
+
} else {
|
|
76
|
+
throw std::invalid_argument("Given out multi filtration value is not available.");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @brief Converts the given multi filtration value into the type given as template argument. It is assumed that the
|
|
82
|
+
* given value is simplified (i.e. minimal and ordered lexicographically). If the new type is
|
|
83
|
+
* @ref Gudhi::multi_filtration::Degree_rips_bifiltration it is additionally assumed that the given value is compatible
|
|
84
|
+
* with the type, that is,the number of parameters is 2 and the second parameter is an index (positive and convertible
|
|
85
|
+
* to an integer without loss).
|
|
86
|
+
*
|
|
87
|
+
* @tparam Out_multi_filtration New filtration value type. Has to be either
|
|
88
|
+
* @ref Gudhi::multi_filtration::Multi_parameter_filtration,
|
|
89
|
+
* @ref Gudhi::multi_filtration::Dynamic_multi_parameter_filtration or
|
|
90
|
+
* @ref Gudhi::multi_filtration::Degree_rips_bifiltration with desired template arguments.
|
|
91
|
+
* @tparam T First template argument of the initial filtration value type.
|
|
92
|
+
* @tparam Co Second template argument of the initial filtration value type.
|
|
93
|
+
* @tparam Ensure1Criticality Third template argument of the initial filtration value type.
|
|
94
|
+
* @param f Filtration value to convert.
|
|
95
|
+
*/
|
|
96
|
+
template <class Out_multi_filtration, typename T, bool Co, bool Ensure1Criticality>
|
|
97
|
+
Out_multi_filtration as_type(const Dynamic_multi_parameter_filtration<T, Co, Ensure1Criticality>& f)
|
|
98
|
+
{
|
|
99
|
+
using U = typename Out_multi_filtration::value_type;
|
|
100
|
+
constexpr bool co = Out_multi_filtration::has_negative_cones();
|
|
101
|
+
constexpr bool one_crit = Out_multi_filtration::ensures_1_criticality();
|
|
102
|
+
|
|
103
|
+
if constexpr (std::is_same_v<Out_multi_filtration, Multi_parameter_filtration<U, co, one_crit> >) {
|
|
104
|
+
std::vector<U> values(f.num_entries());
|
|
105
|
+
std::size_t i = 0;
|
|
106
|
+
for (std::size_t g = 0; g < f.num_generators(); ++g) {
|
|
107
|
+
for (std::size_t p = 0; p < f.num_parameters(); ++p) {
|
|
108
|
+
values[i] = f(g, p);
|
|
109
|
+
++i;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return Out_multi_filtration(std::move(values), f.num_parameters());
|
|
113
|
+
} else if constexpr (std::is_same_v<Out_multi_filtration, Dynamic_multi_parameter_filtration<U, co, one_crit> >) {
|
|
114
|
+
return f.template as_type<U, co, one_crit>();
|
|
115
|
+
} else if constexpr (std::is_same_v<Out_multi_filtration, Degree_rips_bifiltration<U, co, one_crit> >) {
|
|
116
|
+
if (f.num_parameters() != 2) throw std::invalid_argument("Cannot convert a non-bifiltration to a bifiltration.");
|
|
117
|
+
U inf = co ? Out_multi_filtration::T_m_inf : Out_multi_filtration::T_inf;
|
|
118
|
+
|
|
119
|
+
T maxIndex = 0;
|
|
120
|
+
for (std::size_t g = 0; g < f.num_generators(); ++g) {
|
|
121
|
+
maxIndex = maxIndex < f(g, 1) ? f(g, 1) : maxIndex;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
std::vector<U> values(maxIndex + 1, inf);
|
|
125
|
+
for (std::size_t g = 0; g < f.num_generators(); ++g) {
|
|
126
|
+
values[f(g, 1)] = f(g, 0);
|
|
127
|
+
}
|
|
128
|
+
return Out_multi_filtration(std::move(values), 2);
|
|
129
|
+
} else {
|
|
130
|
+
throw std::invalid_argument("Given out multi filtration value is not available.");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @brief Converts the given multi filtration value into the type given as template argument.
|
|
136
|
+
*
|
|
137
|
+
* @tparam Out_multi_filtration New filtration value type. Has to be either
|
|
138
|
+
* @ref Gudhi::multi_filtration::Multi_parameter_filtration,
|
|
139
|
+
* @ref Gudhi::multi_filtration::Dynamic_multi_parameter_filtration or
|
|
140
|
+
* @ref Gudhi::multi_filtration::Degree_rips_bifiltration with desired template arguments.
|
|
141
|
+
* @tparam T First template argument of the initial filtration value type.
|
|
142
|
+
* @tparam Co Second template argument of the initial filtration value type.
|
|
143
|
+
* @tparam Ensure1Criticality Third template argument of the initial filtration value type.
|
|
144
|
+
* @param f Filtration value to convert.
|
|
145
|
+
*/
|
|
146
|
+
template <class Out_multi_filtration, typename T, bool Co, bool Ensure1Criticality>
|
|
147
|
+
Out_multi_filtration as_type(const Degree_rips_bifiltration<T, Co, Ensure1Criticality>& f)
|
|
148
|
+
{
|
|
149
|
+
using U = typename Out_multi_filtration::value_type;
|
|
150
|
+
constexpr bool co = Out_multi_filtration::has_negative_cones();
|
|
151
|
+
constexpr bool one_crit = Out_multi_filtration::ensures_1_criticality();
|
|
152
|
+
|
|
153
|
+
if constexpr (std::is_same_v<Out_multi_filtration, Degree_rips_bifiltration<U, co, one_crit> >) {
|
|
154
|
+
return f.template as_type<U, co, one_crit>();
|
|
155
|
+
} else {
|
|
156
|
+
auto gen_index = [&f](std::size_t i) {
|
|
157
|
+
if constexpr (Out_multi_filtration::has_negative_cones()) {
|
|
158
|
+
return f.num_generators() - 1 - i;
|
|
159
|
+
} else {
|
|
160
|
+
return i;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
auto strictly_dominates = [](T a, T b) {
|
|
165
|
+
if constexpr (Out_multi_filtration::has_negative_cones()) {
|
|
166
|
+
return a < b;
|
|
167
|
+
} else {
|
|
168
|
+
return a > b;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
if (f.size() == 0) return Out_multi_filtration(0);
|
|
173
|
+
|
|
174
|
+
std::vector<std::size_t> order(f.num_generators());
|
|
175
|
+
std::iota(order.begin(), order.end(), 0);
|
|
176
|
+
// lexicographical order
|
|
177
|
+
std::sort(order.begin(), order.end(), [&](std::size_t i, std::size_t j){
|
|
178
|
+
if (f(i, 0) == f(j, 0)) return f(i, 1) < f(j, 1); // f(i, 1) and f(j, 1) cannot be equal for i != j
|
|
179
|
+
return f(i, 0) < f(j, 0);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if constexpr (std::is_same_v<Out_multi_filtration, Multi_parameter_filtration<U, co, one_crit> >) {
|
|
183
|
+
std::vector<U> values;
|
|
184
|
+
values.reserve(f.num_generators() * 2);
|
|
185
|
+
std::size_t g = order[gen_index(0)];
|
|
186
|
+
T threshold = g;
|
|
187
|
+
values.push_back(f(g, 0));
|
|
188
|
+
values.push_back(threshold);
|
|
189
|
+
for (std::size_t i = 1; i < f.num_generators(); ++i) {
|
|
190
|
+
g = order[gen_index(i)];
|
|
191
|
+
if (strictly_dominates(threshold, g)) {
|
|
192
|
+
threshold = g;
|
|
193
|
+
values.push_back(f(g, 0));
|
|
194
|
+
values.push_back(threshold);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if constexpr (co) {
|
|
198
|
+
// lexicographical order
|
|
199
|
+
const std::size_t max_idx = values.size() - 1;
|
|
200
|
+
for (std::size_t i = 0; i < values.size() / 2; i += 2) {
|
|
201
|
+
std::swap(values[i], values[max_idx - 1 - i]);
|
|
202
|
+
std::swap(values[i + 1], values[max_idx - i]);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return Out_multi_filtration(std::move(values), 2);
|
|
207
|
+
} else if constexpr (std::is_same_v<Out_multi_filtration, Dynamic_multi_parameter_filtration<U, co, one_crit> >) {
|
|
208
|
+
std::vector<Multi_parameter_generator<U> > values;
|
|
209
|
+
values.reserve(f.num_generators());
|
|
210
|
+
std::size_t g = order[gen_index(0)];
|
|
211
|
+
T threshold = g;
|
|
212
|
+
values.emplace_back(std::vector<T>{static_cast<T>(f(g, 0)), threshold});
|
|
213
|
+
for (std::size_t i = 1; i < f.num_generators(); ++i) {
|
|
214
|
+
g = order[gen_index(i)];
|
|
215
|
+
if (strictly_dominates(threshold, g)) {
|
|
216
|
+
threshold = g;
|
|
217
|
+
std::vector<T> v = {static_cast<T>(f(g, 0)), threshold};
|
|
218
|
+
values.emplace_back(std::move(v));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if constexpr (co) {
|
|
222
|
+
// lexicographical order
|
|
223
|
+
std::reverse(values.begin(), values.end());
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return Out_multi_filtration(std::move(values), 2);
|
|
227
|
+
} else {
|
|
228
|
+
throw std::invalid_argument("Given out multi filtration value is not available.");
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
} // namespace multi_filtration
|
|
234
|
+
|
|
235
|
+
} // namespace Gudhi
|
|
236
|
+
|
|
237
|
+
#endif // MF_CONVERSIONS_H_
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
|
|
2
|
+
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
|
|
3
|
+
* Author(s): Hannah Schreiber
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2025 Inria
|
|
6
|
+
*
|
|
7
|
+
* Modification(s):
|
|
8
|
+
* - YYYY/MM Author: Description of the modification
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
* @file multi_filtration_utils.h
|
|
14
|
+
* @author Hannah Schreiber
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef MF_UTILS_H_
|
|
18
|
+
#define MF_UTILS_H_
|
|
19
|
+
|
|
20
|
+
#include <cstddef>
|
|
21
|
+
#include <istream>
|
|
22
|
+
#include <stdexcept>
|
|
23
|
+
#include <type_traits>
|
|
24
|
+
#include <limits>
|
|
25
|
+
#include <cmath>
|
|
26
|
+
|
|
27
|
+
namespace Gudhi {
|
|
28
|
+
|
|
29
|
+
namespace multi_filtration {
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
template <typename T>
|
|
35
|
+
class RangeTraits
|
|
36
|
+
{
|
|
37
|
+
private:
|
|
38
|
+
static auto check_begin(...) -> std::false_type;
|
|
39
|
+
template <typename U>
|
|
40
|
+
static auto check_begin(U x) -> decltype(x.begin(), std::true_type{});
|
|
41
|
+
|
|
42
|
+
static auto check_dynamic_filtration(...) -> std::false_type;
|
|
43
|
+
template <typename U>
|
|
44
|
+
static auto check_dynamic_filtration(U x) -> decltype(x.operator[](std::size_t{}), std::true_type{});
|
|
45
|
+
|
|
46
|
+
static auto check_filtration(...) -> std::false_type;
|
|
47
|
+
template <typename U>
|
|
48
|
+
static auto check_filtration(U x) -> decltype(x.ensures_1_criticality(), std::true_type{});
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
static constexpr bool has_begin = decltype(check_begin(std::declval<T>()))::value;
|
|
52
|
+
static constexpr bool is_multi_filtration = decltype(check_filtration(std::declval<T>()))::value;
|
|
53
|
+
static constexpr bool is_dynamic_multi_filtration =
|
|
54
|
+
is_multi_filtration && decltype(check_dynamic_filtration(std::declval<T>()))::value;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
template <typename T>
|
|
61
|
+
constexpr bool _is_nan(T val)
|
|
62
|
+
{
|
|
63
|
+
if constexpr (std::is_integral_v<T>) {
|
|
64
|
+
// to avoid Windows issue which don't know how to cast integers for cmath methods
|
|
65
|
+
return false;
|
|
66
|
+
} else {
|
|
67
|
+
return std::isnan(val);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @private
|
|
73
|
+
* @brief Infinity value of an entry of the filtration value.
|
|
74
|
+
*/
|
|
75
|
+
template <typename T>
|
|
76
|
+
constexpr const T MF_T_inf =
|
|
77
|
+
std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max();
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @private
|
|
81
|
+
* @brief Minus infinity value of an entry of the filtration value.
|
|
82
|
+
*/
|
|
83
|
+
template <typename T>
|
|
84
|
+
constexpr const T MF_T_m_inf =
|
|
85
|
+
std::numeric_limits<T>::has_infinity ? -std::numeric_limits<T>::infinity() : std::numeric_limits<T>::lowest();
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @private
|
|
89
|
+
* @brief Adds v1 and v2, stores the result in v1 and returns true if and only if v1 was modified.
|
|
90
|
+
*/
|
|
91
|
+
template <typename T>
|
|
92
|
+
constexpr bool _add(T &v1, T v2)
|
|
93
|
+
{
|
|
94
|
+
if (_is_nan(v1) || _is_nan(v2) || (v1 == MF_T_inf<T> && v2 == MF_T_m_inf<T>) ||
|
|
95
|
+
(v1 == MF_T_m_inf<T> && v2 == MF_T_inf<T>)) {
|
|
96
|
+
v1 = std::numeric_limits<T>::quiet_NaN();
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (v1 == MF_T_inf<T> || v1 == MF_T_m_inf<T>) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
if (v2 == MF_T_inf<T> || v2 == MF_T_m_inf<T>) {
|
|
103
|
+
v1 = v2;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
v1 += v2;
|
|
108
|
+
return true;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @private
|
|
113
|
+
* @brief Subtracts v1 and v2, stores the result in v1 and returns true if and only if v1 was modified.
|
|
114
|
+
*/
|
|
115
|
+
template <typename T>
|
|
116
|
+
constexpr bool _subtract(T &v1, T v2)
|
|
117
|
+
{
|
|
118
|
+
return _add(v1, v2 == MF_T_inf<T> ? MF_T_m_inf<T> : (v2 == MF_T_m_inf<T> ? MF_T_inf<T> : -v2));
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @private
|
|
123
|
+
* @brief Multiplies v1 and v2, stores the result in v1 and returns true if and only if v1 was modified.
|
|
124
|
+
*/
|
|
125
|
+
template <typename T>
|
|
126
|
+
constexpr bool _multiply(T &v1, T v2)
|
|
127
|
+
{
|
|
128
|
+
bool v1_is_infinite = v1 == MF_T_inf<T> || v1 == MF_T_m_inf<T>;
|
|
129
|
+
bool v2_is_infinite = v2 == MF_T_inf<T> || v2 == MF_T_m_inf<T>;
|
|
130
|
+
|
|
131
|
+
if (_is_nan(v1) || _is_nan(v2) || (v1_is_infinite && v2 == 0) || (v1 == 0 && v2_is_infinite)) {
|
|
132
|
+
v1 = std::numeric_limits<T>::quiet_NaN();
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if ((v1 == MF_T_inf<T> && v2 > 0) || (v1 == MF_T_m_inf<T> && v2 < 0) || (v1 < 0 && v2 == MF_T_m_inf<T>) ||
|
|
137
|
+
(v1 > 0 && v2 == MF_T_inf<T>)) {
|
|
138
|
+
v1 = MF_T_inf<T>;
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if ((v1 == MF_T_inf<T> && v2 < 0) || (v1 == MF_T_m_inf<T> && v2 > 0) || (v1 > 0 && v2 == MF_T_m_inf<T>) ||
|
|
143
|
+
(v1 < 0 && v2 == MF_T_inf<T>)) {
|
|
144
|
+
v1 = MF_T_m_inf<T>;
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
v1 *= v2;
|
|
149
|
+
return true;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @private
|
|
154
|
+
* @brief Divides v1 and v2, stores the result in v1 and returns true if and only if v1 was modified.
|
|
155
|
+
*/
|
|
156
|
+
template <typename T>
|
|
157
|
+
constexpr bool _divide(T &v1, T v2)
|
|
158
|
+
{
|
|
159
|
+
bool v1_is_infinite = v1 == MF_T_inf<T> || v1 == MF_T_m_inf<T>;
|
|
160
|
+
bool v2_is_infinite = v2 == MF_T_inf<T> || v2 == MF_T_m_inf<T>;
|
|
161
|
+
|
|
162
|
+
if (_is_nan(v1) || _is_nan(v2) || v2 == 0 || (v1_is_infinite && v2_is_infinite)) {
|
|
163
|
+
v1 = std::numeric_limits<T>::quiet_NaN();
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (v1 == 0 || (v1_is_infinite && v2 > 0)) return true;
|
|
168
|
+
|
|
169
|
+
if (v1_is_infinite && v2 < 0) {
|
|
170
|
+
v1 = v1 == MF_T_inf<T> ? MF_T_m_inf<T> : (v1 == MF_T_m_inf<T> ? MF_T_inf<T> : -v1);
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (v2_is_infinite) {
|
|
175
|
+
v1 = 0;
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
v1 /= v2;
|
|
180
|
+
return true;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
template <class T>
|
|
184
|
+
T _get_value(std::istream &stream)
|
|
185
|
+
{
|
|
186
|
+
if constexpr (std::numeric_limits<T>::has_infinity) {
|
|
187
|
+
auto pos = stream.tellg();
|
|
188
|
+
char first;
|
|
189
|
+
stream >> first;
|
|
190
|
+
if (first == 'i') {
|
|
191
|
+
stream >> first; // n
|
|
192
|
+
stream >> first; // f
|
|
193
|
+
return std::numeric_limits<T>::infinity();
|
|
194
|
+
}
|
|
195
|
+
if (first == '-') {
|
|
196
|
+
stream >> first; // i
|
|
197
|
+
if (first == 'i') {
|
|
198
|
+
stream >> first; // n
|
|
199
|
+
stream >> first; // f
|
|
200
|
+
return -std::numeric_limits<T>::infinity();
|
|
201
|
+
} // else could be a negative number
|
|
202
|
+
}
|
|
203
|
+
if (first == 'n') {
|
|
204
|
+
if constexpr (std::numeric_limits<T>::has_quiet_NaN) {
|
|
205
|
+
stream >> first; // a
|
|
206
|
+
stream >> first; // n
|
|
207
|
+
return std::numeric_limits<T>::quiet_NaN();
|
|
208
|
+
} else {
|
|
209
|
+
throw std::invalid_argument("Wrong input stream format for value, no nan values allowed.");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
stream.seekg(pos, std::ios_base::beg);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
T val;
|
|
216
|
+
stream >> val;
|
|
217
|
+
if (stream.fail()) throw std::invalid_argument("Wrong input stream format for value.");
|
|
218
|
+
return val;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
} // namespace multi_filtration
|
|
222
|
+
|
|
223
|
+
} // namespace Gudhi
|
|
224
|
+
|
|
225
|
+
#endif // MF_UTILS_H_
|