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,453 @@
|
|
|
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, Clément Maria
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2022-24 Inria
|
|
6
|
+
*
|
|
7
|
+
* Modification(s):
|
|
8
|
+
* - YYYY/MM Author: Description of the modification
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file Multi_field.h
|
|
13
|
+
* @author Hannah Schreiber, Clément Maria
|
|
14
|
+
* @brief Contains the @ref Gudhi::persistence_fields::Multi_field_element class.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef MATRIX_FIELD_MULTI_H_
|
|
18
|
+
#define MATRIX_FIELD_MULTI_H_
|
|
19
|
+
|
|
20
|
+
#include <utility>
|
|
21
|
+
#include <vector>
|
|
22
|
+
#include <gmpxx.h>
|
|
23
|
+
#include <stdexcept>
|
|
24
|
+
|
|
25
|
+
#include <gudhi/Debug_utils.h>
|
|
26
|
+
|
|
27
|
+
namespace Gudhi {
|
|
28
|
+
namespace persistence_fields {
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @class Multi_field_element Multi_field.h gudhi/Fields/Multi_field.h
|
|
32
|
+
* @ingroup persistence_fields
|
|
33
|
+
*
|
|
34
|
+
* @brief Class representing an element of a multi-field.
|
|
35
|
+
* The characteristics will corresponds to all prime numbers in the interval given as template.
|
|
36
|
+
*
|
|
37
|
+
* @tparam minimum Interval closed lower bound.
|
|
38
|
+
* @tparam maximum Interval closed upper bound.
|
|
39
|
+
*/
|
|
40
|
+
template <unsigned int minimum, unsigned int maximum>
|
|
41
|
+
class Multi_field_element
|
|
42
|
+
{
|
|
43
|
+
public:
|
|
44
|
+
using Element = mpz_class; /**< Type for the elements in the field. */
|
|
45
|
+
using Characteristic = Element; /**< Type for the field characteristic. */
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @brief Default constructor. Sets the element to 0.
|
|
49
|
+
*/
|
|
50
|
+
Multi_field_element() : element_(0)
|
|
51
|
+
{
|
|
52
|
+
static_assert(maximum >= 2, "Characteristics have to be positive.");
|
|
53
|
+
static_assert(minimum <= maximum, "The given interval is not valid.");
|
|
54
|
+
static_assert(minimum != maximum || _is_prime(minimum), "The given interval does not contain a prime number.");
|
|
55
|
+
|
|
56
|
+
if (productOfAllCharacteristics_ == 1)
|
|
57
|
+
throw std::runtime_error("The given interval does not contain a prime number.");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @brief Constructor setting the element to the given value.
|
|
62
|
+
*
|
|
63
|
+
* @param element Value of the element.
|
|
64
|
+
*/
|
|
65
|
+
Multi_field_element(Element element) : element_(std::move(element))
|
|
66
|
+
{
|
|
67
|
+
static_assert(maximum >= 2, "Characteristics has to be positive.");
|
|
68
|
+
static_assert(minimum <= maximum, "The given interval is not valid.");
|
|
69
|
+
static_assert(minimum != maximum || _is_prime(minimum), "The given interval does not contain a prime number.");
|
|
70
|
+
|
|
71
|
+
if (productOfAllCharacteristics_ == 1)
|
|
72
|
+
throw std::runtime_error("The given interval does not contain a prime number.");
|
|
73
|
+
|
|
74
|
+
mpz_mod(element_.get_mpz_t(), element_.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @brief operator+=
|
|
79
|
+
*/
|
|
80
|
+
friend void operator+=(Multi_field_element& f1, Multi_field_element const& f2)
|
|
81
|
+
{
|
|
82
|
+
f1.element_ += f2.element_;
|
|
83
|
+
mpz_mod(f1.element_.get_mpz_t(), f1.element_.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @brief operator+
|
|
88
|
+
*/
|
|
89
|
+
friend Multi_field_element operator+(Multi_field_element f1, Multi_field_element const& f2)
|
|
90
|
+
{
|
|
91
|
+
f1 += f2;
|
|
92
|
+
return f1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @brief operator+=
|
|
97
|
+
*/
|
|
98
|
+
friend void operator+=(Multi_field_element& f, const Element& v)
|
|
99
|
+
{
|
|
100
|
+
f.element_ += v;
|
|
101
|
+
mpz_mod(f.element_.get_mpz_t(), f.element_.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @brief operator+
|
|
106
|
+
*/
|
|
107
|
+
friend Multi_field_element operator+(Multi_field_element f, const Element& v)
|
|
108
|
+
{
|
|
109
|
+
f += v;
|
|
110
|
+
return f;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @brief operator+
|
|
115
|
+
*/
|
|
116
|
+
friend Element operator+(Element v, Multi_field_element const& f)
|
|
117
|
+
{
|
|
118
|
+
v += f.element_;
|
|
119
|
+
mpz_mod(v.get_mpz_t(), v.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
120
|
+
return v;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @brief operator-=
|
|
125
|
+
*/
|
|
126
|
+
friend void operator-=(Multi_field_element& f1, Multi_field_element const& f2)
|
|
127
|
+
{
|
|
128
|
+
f1.element_ -= f2.element_;
|
|
129
|
+
mpz_mod(f1.element_.get_mpz_t(), f1.element_.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @brief operator-
|
|
134
|
+
*/
|
|
135
|
+
friend Multi_field_element operator-(Multi_field_element f1, Multi_field_element const& f2)
|
|
136
|
+
{
|
|
137
|
+
f1 -= f2;
|
|
138
|
+
return f1;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @brief operator-=
|
|
143
|
+
*/
|
|
144
|
+
friend void operator-=(Multi_field_element& f, const Element& v)
|
|
145
|
+
{
|
|
146
|
+
f.element_ -= v;
|
|
147
|
+
mpz_mod(f.element_.get_mpz_t(), f.element_.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @brief operator-
|
|
152
|
+
*/
|
|
153
|
+
friend Multi_field_element operator-(Multi_field_element f, const Element& v)
|
|
154
|
+
{
|
|
155
|
+
f -= v;
|
|
156
|
+
return f;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @brief operator-
|
|
161
|
+
*/
|
|
162
|
+
friend Element operator-(Element v, Multi_field_element const& f)
|
|
163
|
+
{
|
|
164
|
+
// Element e(v);
|
|
165
|
+
if (v >= productOfAllCharacteristics_)
|
|
166
|
+
mpz_mod(v.get_mpz_t(), v.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
167
|
+
if (f.element_ > v) v += productOfAllCharacteristics_;
|
|
168
|
+
v -= f.element_;
|
|
169
|
+
return v;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @brief operator*=
|
|
174
|
+
*/
|
|
175
|
+
friend void operator*=(Multi_field_element& f1, Multi_field_element const& f2)
|
|
176
|
+
{
|
|
177
|
+
f1.element_ *= f2.element_;
|
|
178
|
+
mpz_mod(f1.element_.get_mpz_t(), f1.element_.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @brief operator*
|
|
183
|
+
*/
|
|
184
|
+
friend Multi_field_element operator*(Multi_field_element f1, Multi_field_element const& f2)
|
|
185
|
+
{
|
|
186
|
+
f1 *= f2;
|
|
187
|
+
return f1;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @brief operator*=
|
|
192
|
+
*/
|
|
193
|
+
friend void operator*=(Multi_field_element& f, const Element& v)
|
|
194
|
+
{
|
|
195
|
+
f.element_ *= v;
|
|
196
|
+
mpz_mod(f.element_.get_mpz_t(), f.element_.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @brief operator*
|
|
201
|
+
*/
|
|
202
|
+
friend Multi_field_element operator*(Multi_field_element f, const Element& v)
|
|
203
|
+
{
|
|
204
|
+
f *= v;
|
|
205
|
+
return f;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @brief operator*
|
|
210
|
+
*/
|
|
211
|
+
friend Element operator*(Element v, Multi_field_element const& f)
|
|
212
|
+
{
|
|
213
|
+
v *= f.element_;
|
|
214
|
+
mpz_mod(v.get_mpz_t(), v.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
215
|
+
return v;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @brief operator==
|
|
220
|
+
*/
|
|
221
|
+
friend bool operator==(const Multi_field_element& f1, const Multi_field_element& f2)
|
|
222
|
+
{
|
|
223
|
+
return f1.element_ == f2.element_;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @brief operator==
|
|
228
|
+
*/
|
|
229
|
+
friend bool operator==(const Element& v, const Multi_field_element& f)
|
|
230
|
+
{
|
|
231
|
+
if (v < productOfAllCharacteristics_) return v == f.element_;
|
|
232
|
+
Element e(v);
|
|
233
|
+
mpz_mod(e.get_mpz_t(), e.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
234
|
+
return e == f.element_;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @brief operator==
|
|
239
|
+
*/
|
|
240
|
+
friend bool operator==(const Multi_field_element& f, const Element& v)
|
|
241
|
+
{
|
|
242
|
+
if (v < productOfAllCharacteristics_) return v == f.element_;
|
|
243
|
+
Element e(v);
|
|
244
|
+
mpz_mod(e.get_mpz_t(), e.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
245
|
+
return e == f.element_;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @brief operator!=
|
|
250
|
+
*/
|
|
251
|
+
friend bool operator!=(const Multi_field_element& f1, const Multi_field_element& f2) { return !(f1 == f2); }
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @brief operator!=
|
|
255
|
+
*/
|
|
256
|
+
friend bool operator!=(const Element& v, const Multi_field_element& f) { return !(v == f); }
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @brief operator!=
|
|
260
|
+
*/
|
|
261
|
+
friend bool operator!=(const Multi_field_element& f, const Element& v) { return !(v == f); }
|
|
262
|
+
|
|
263
|
+
// /**
|
|
264
|
+
// * @brief Assign operator.
|
|
265
|
+
// */
|
|
266
|
+
// Multi_field_element& operator=(const Element& value)
|
|
267
|
+
// {
|
|
268
|
+
// mpz_mod(element_.get_mpz_t(), value.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
|
|
269
|
+
// return *this;
|
|
270
|
+
// }
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @brief Swap operator.
|
|
274
|
+
*/
|
|
275
|
+
friend void swap(Multi_field_element& f1, Multi_field_element& f2) noexcept { std::swap(f1.element_, f2.element_); }
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @brief Casts the element into an unsigned int.
|
|
279
|
+
*/
|
|
280
|
+
operator unsigned int() const { return element_.get_ui(); }
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @brief Casts the element into an mpz_class.
|
|
284
|
+
*/
|
|
285
|
+
explicit operator mpz_class() const { return element_; }
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* @brief Returns the inverse of the element in the multi-field, see @cite boissonnat:hal-00922572.
|
|
289
|
+
*
|
|
290
|
+
* @return The inverse.
|
|
291
|
+
*/
|
|
292
|
+
[[nodiscard]] Multi_field_element get_inverse() const
|
|
293
|
+
{
|
|
294
|
+
return get_partial_inverse(productOfAllCharacteristics_).first;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @brief Returns the inverse of the element with respect to a sub-product of the characteristics in the multi-field,
|
|
299
|
+
* see @cite boissonnat:hal-00922572.
|
|
300
|
+
*
|
|
301
|
+
* @param productOfCharacteristics Sub-product of the characteristics.
|
|
302
|
+
* @return Pair of the inverse and the characteristic the inverse corresponds to.
|
|
303
|
+
*/
|
|
304
|
+
[[nodiscard]] std::pair<Multi_field_element, Characteristic> get_partial_inverse(
|
|
305
|
+
const Characteristic& productOfCharacteristics) const
|
|
306
|
+
{
|
|
307
|
+
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
|
|
308
|
+
"The given product is not the product of a subset of the current Multi-field characteristics.");
|
|
309
|
+
|
|
310
|
+
Characteristic QR;
|
|
311
|
+
mpz_gcd(QR.get_mpz_t(), element_.get_mpz_t(), productOfCharacteristics.get_mpz_t()); // QR <- gcd(x,QS)
|
|
312
|
+
|
|
313
|
+
if (QR == productOfCharacteristics) return {Multi_field_element(), multiplicativeID_}; // partial inverse is 0
|
|
314
|
+
|
|
315
|
+
Characteristic QT = productOfCharacteristics / QR;
|
|
316
|
+
|
|
317
|
+
Characteristic inv_qt;
|
|
318
|
+
mpz_invert(inv_qt.get_mpz_t(), element_.get_mpz_t(), QT.get_mpz_t());
|
|
319
|
+
|
|
320
|
+
auto res = get_partial_multiplicative_identity(QT);
|
|
321
|
+
res *= inv_qt;
|
|
322
|
+
|
|
323
|
+
return {res, QT};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* @brief Returns the additive identity of a field.
|
|
328
|
+
*
|
|
329
|
+
* @return The additive identity of a field.
|
|
330
|
+
*/
|
|
331
|
+
static Multi_field_element get_additive_identity() { return Multi_field_element<minimum, maximum>(); }
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @brief Returns the multiplicative identity of a field.
|
|
335
|
+
*
|
|
336
|
+
* @return The multiplicative identity of a field.
|
|
337
|
+
*/
|
|
338
|
+
static Multi_field_element get_multiplicative_identity()
|
|
339
|
+
{
|
|
340
|
+
return Multi_field_element<minimum, maximum>(multiplicativeID_);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* @brief Returns the partial multiplicative identity of the multi-field from the given product.
|
|
345
|
+
* See @cite boissonnat:hal-00922572 for more details.
|
|
346
|
+
*
|
|
347
|
+
* @param productOfCharacteristics Product of the different characteristics to take into account in the multi-field.
|
|
348
|
+
* @return The partial multiplicative identity of the multi-field.
|
|
349
|
+
*/
|
|
350
|
+
static Multi_field_element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics)
|
|
351
|
+
{
|
|
352
|
+
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
|
|
353
|
+
"The given product is not the product of a subset of the current Multi-field characteristics.");
|
|
354
|
+
|
|
355
|
+
if (productOfCharacteristics == 0 || productOfCharacteristics == productOfAllCharacteristics_) {
|
|
356
|
+
return get_multiplicative_identity();
|
|
357
|
+
}
|
|
358
|
+
Multi_field_element<minimum, maximum> mult;
|
|
359
|
+
for (unsigned int idx = 0; idx < primes_.size(); ++idx) {
|
|
360
|
+
if ((productOfCharacteristics % primes_[idx]) == 0) {
|
|
361
|
+
mult += partials_[idx];
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return mult;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @brief Returns the product of all characteristics.
|
|
369
|
+
*
|
|
370
|
+
* @return The product of all characteristics.
|
|
371
|
+
*/
|
|
372
|
+
static Characteristic get_characteristic() { return productOfAllCharacteristics_; }
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* @brief Returns the value of the element.
|
|
376
|
+
*
|
|
377
|
+
* @return Value of the element.
|
|
378
|
+
*/
|
|
379
|
+
[[nodiscard]] Element get_value() const { return element_; }
|
|
380
|
+
|
|
381
|
+
private:
|
|
382
|
+
Element element_;
|
|
383
|
+
static inline const std::vector<unsigned int> primes_ = []() {
|
|
384
|
+
std::vector<unsigned int> res;
|
|
385
|
+
|
|
386
|
+
unsigned int curr_prime = minimum;
|
|
387
|
+
mpz_t tmp_prime;
|
|
388
|
+
mpz_init_set_ui(tmp_prime, minimum);
|
|
389
|
+
// test if min_prime is prime
|
|
390
|
+
int is_prime = mpz_probab_prime_p(tmp_prime, 25); // probabilistic primality test
|
|
391
|
+
|
|
392
|
+
if (is_prime == 0) { // min_prime is composite
|
|
393
|
+
mpz_nextprime(tmp_prime, tmp_prime);
|
|
394
|
+
curr_prime = mpz_get_ui(tmp_prime);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
while (curr_prime <= maximum) {
|
|
398
|
+
res.push_back(curr_prime);
|
|
399
|
+
mpz_nextprime(tmp_prime, tmp_prime);
|
|
400
|
+
curr_prime = mpz_get_ui(tmp_prime);
|
|
401
|
+
}
|
|
402
|
+
mpz_clear(tmp_prime);
|
|
403
|
+
|
|
404
|
+
return res;
|
|
405
|
+
}();
|
|
406
|
+
static inline const Characteristic productOfAllCharacteristics_ = []() {
|
|
407
|
+
Characteristic res = 1;
|
|
408
|
+
for (const auto p : primes_) {
|
|
409
|
+
res *= p;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return res;
|
|
413
|
+
}();
|
|
414
|
+
static inline const std::vector<Characteristic> partials_ = []() {
|
|
415
|
+
std::vector<Characteristic> res;
|
|
416
|
+
|
|
417
|
+
if (productOfAllCharacteristics_ == 1) return res;
|
|
418
|
+
|
|
419
|
+
for (unsigned int p : primes_) {
|
|
420
|
+
res.emplace_back(productOfAllCharacteristics_ / p);
|
|
421
|
+
mpz_powm_ui(res.back().get_mpz_t(), res.back().get_mpz_t(), p - 1, productOfAllCharacteristics_.get_mpz_t());
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return res;
|
|
425
|
+
}();
|
|
426
|
+
// If I understood the paper well, multiplicativeID_ always equals to 1. But in Clement's code,
|
|
427
|
+
// multiplicativeID_ is computed (see commented lambda function below). TODO: verify with Clement.
|
|
428
|
+
static inline const Element multiplicativeID_ = 1; /*[](){
|
|
429
|
+
mpz_class res = 0;
|
|
430
|
+
for (unsigned int i = 0; i < partials_.size(); ++i){
|
|
431
|
+
res = (res + partials_[i]) % productOfAllCharacteristics_;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return res;
|
|
435
|
+
}();*/
|
|
436
|
+
|
|
437
|
+
static constexpr bool _is_prime(const int p)
|
|
438
|
+
{
|
|
439
|
+
if (p <= 1) return false;
|
|
440
|
+
if (p <= 3) return true;
|
|
441
|
+
if (p % 2 == 0 || p % 3 == 0) return false;
|
|
442
|
+
|
|
443
|
+
for (long i = 5; i * i <= p; i = i + 6)
|
|
444
|
+
if (p % i == 0 || p % (i + 2) == 0) return false;
|
|
445
|
+
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
} // namespace persistence_fields
|
|
451
|
+
} // namespace Gudhi
|
|
452
|
+
|
|
453
|
+
#endif // MATRIX_FIELD_MULTI_H_
|