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,490 @@
|
|
|
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_small_operators.h
|
|
13
|
+
* @author Hannah Schreiber, Clément Maria
|
|
14
|
+
* @brief Contains the @ref Gudhi::persistence_fields::Multi_field_operators_with_small_characteristics class.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef MATRIX_FIELD_MULTI_SMALL_OPERATORS_H_
|
|
18
|
+
#define MATRIX_FIELD_MULTI_SMALL_OPERATORS_H_
|
|
19
|
+
|
|
20
|
+
#include <utility>
|
|
21
|
+
#include <vector>
|
|
22
|
+
#include <climits>
|
|
23
|
+
#include <stdexcept>
|
|
24
|
+
#include <numeric>
|
|
25
|
+
|
|
26
|
+
#include <gudhi/Debug_utils.h>
|
|
27
|
+
|
|
28
|
+
namespace Gudhi {
|
|
29
|
+
namespace persistence_fields {
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @class Multi_field_operators_with_small_characteristics Multi_field_small_operators.h \
|
|
33
|
+
* gudhi/Fields/Multi_field_small_operators.h
|
|
34
|
+
* @ingroup persistence_fields
|
|
35
|
+
*
|
|
36
|
+
* @brief Class defining operators for a multi-field with "consecutive" characteristic range, such that
|
|
37
|
+
* `productOfAllCharacteristics ^ 2` fits into an unsigned int.
|
|
38
|
+
*/
|
|
39
|
+
class Multi_field_operators_with_small_characteristics
|
|
40
|
+
{
|
|
41
|
+
public:
|
|
42
|
+
using Element = unsigned int; /**< Type for the elements in the field. */
|
|
43
|
+
using Characteristic = Element; /**< Type for the field characteristic. */
|
|
44
|
+
|
|
45
|
+
inline static const Characteristic nullCharacteristic = 0; /**< Value of a non initialized characteristic. */
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @brief Default constructor, sets the product of all characteristics to 0.
|
|
49
|
+
*/
|
|
50
|
+
Multi_field_operators_with_small_characteristics()
|
|
51
|
+
: productOfAllCharacteristics_(nullCharacteristic) /* , multiplicativeID_(1) */
|
|
52
|
+
{}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @brief Constructor setting the characteristics to all prime numbers between the two given integers.
|
|
56
|
+
* The product of all primes to the square has to fit into an unsigned int.
|
|
57
|
+
*
|
|
58
|
+
* @param minCharacteristic Smallest value of a prime.
|
|
59
|
+
* @param maxCharacteristic Highest value of a prime.
|
|
60
|
+
*/
|
|
61
|
+
Multi_field_operators_with_small_characteristics(int minCharacteristic, int maxCharacteristic)
|
|
62
|
+
: productOfAllCharacteristics_(nullCharacteristic) //, multiplicativeID_(1)
|
|
63
|
+
{
|
|
64
|
+
set_characteristic(minCharacteristic, maxCharacteristic);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @brief Set the characteristics of the field, which are stored in a single value as a product of all of them.
|
|
69
|
+
* The characteristics will be all prime numbers in the given interval.
|
|
70
|
+
* The product of all primes to the square has to fit into an unsigned int.
|
|
71
|
+
*
|
|
72
|
+
* @param minimum Smallest value of a prime.
|
|
73
|
+
* @param maximum Highest value of a prime.
|
|
74
|
+
*/
|
|
75
|
+
void set_characteristic(int minimum, int maximum)
|
|
76
|
+
{
|
|
77
|
+
if (maximum < 2) throw std::invalid_argument("Characteristic must be strictly positive");
|
|
78
|
+
if (minimum > maximum) throw std::invalid_argument("The given interval is not valid.");
|
|
79
|
+
if (minimum == maximum && !_is_prime(minimum))
|
|
80
|
+
throw std::invalid_argument("The given interval does not contain a prime number.");
|
|
81
|
+
|
|
82
|
+
productOfAllCharacteristics_ = 1;
|
|
83
|
+
primes_.clear();
|
|
84
|
+
for (unsigned int i = minimum; i <= static_cast<unsigned int>(maximum); ++i) {
|
|
85
|
+
if (_is_prime(static_cast<int>(i))) {
|
|
86
|
+
primes_.push_back(i);
|
|
87
|
+
productOfAllCharacteristics_ *= i;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (primes_.empty()) throw std::invalid_argument("The given interval does not contain a prime number.");
|
|
92
|
+
|
|
93
|
+
partials_.resize(primes_.size());
|
|
94
|
+
for (unsigned int i = 0; i < primes_.size(); ++i) {
|
|
95
|
+
unsigned int p = primes_[i];
|
|
96
|
+
Characteristic base = productOfAllCharacteristics_ / p;
|
|
97
|
+
unsigned int exp = p - 1;
|
|
98
|
+
partials_[i] = 1;
|
|
99
|
+
|
|
100
|
+
while (exp > 0) {
|
|
101
|
+
// If exp is odd, multiply with result
|
|
102
|
+
if (exp & 1) partials_[i] = _multiply(partials_[i], base, productOfAllCharacteristics_);
|
|
103
|
+
// y must be even now
|
|
104
|
+
exp = exp >> 1; // y = y/2
|
|
105
|
+
base = _multiply(base, base, productOfAllCharacteristics_);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// If I understood the paper well, multiplicativeID_ always equals to 1. But in Clement's code,
|
|
110
|
+
// multiplicativeID_ is computed (see commented loop below). TODO: verify with Clement.
|
|
111
|
+
// for (unsigned int i = 0; i < partials_.size(); ++i){
|
|
112
|
+
// multiplicativeID_ = (multiplicativeID_ + partials_[i]) % productOfAllCharacteristics_;
|
|
113
|
+
// }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @brief Returns the current characteristics as the product of all of them.
|
|
118
|
+
*
|
|
119
|
+
* @return The value of the current characteristic.
|
|
120
|
+
*/
|
|
121
|
+
[[nodiscard]] const Characteristic& get_characteristic() const { return productOfAllCharacteristics_; }
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @brief Returns the value of an element in the field.
|
|
125
|
+
* That is the positive value of the integer modulo the current characteristic.
|
|
126
|
+
*
|
|
127
|
+
* @param e Integer to return the value from.
|
|
128
|
+
* @return @p e modulo the current characteristic, such that the result is positive.
|
|
129
|
+
*/
|
|
130
|
+
[[nodiscard]] Element get_value(Element e) const
|
|
131
|
+
{
|
|
132
|
+
return e < productOfAllCharacteristics_ ? e : e % productOfAllCharacteristics_;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @brief Returns the sum of two elements in the field.
|
|
137
|
+
*
|
|
138
|
+
* @param e1 First element.
|
|
139
|
+
* @param e2 Second element.
|
|
140
|
+
* @return `(e1 + e2) % productOfAllCharacteristics`, such that the result is positive.
|
|
141
|
+
*/
|
|
142
|
+
[[nodiscard]] Element add(Element e1, Element e2) const
|
|
143
|
+
{
|
|
144
|
+
return _add(get_value(e1), get_value(e2), productOfAllCharacteristics_);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @brief Stores in the first element the sum of two given elements in the field, that is
|
|
149
|
+
* `(e1 + e2) % productOfAllCharacteristics`, such that the result is positive.
|
|
150
|
+
*
|
|
151
|
+
* @param e1 First element.
|
|
152
|
+
* @param e2 Second element.
|
|
153
|
+
*/
|
|
154
|
+
void add_inplace(Element& e1, Element e2) const
|
|
155
|
+
{
|
|
156
|
+
e1 = _add(get_value(e1), get_value(e2), productOfAllCharacteristics_);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @brief Returns the subtraction in the field of the first element by the second element.
|
|
161
|
+
*
|
|
162
|
+
* @param e1 First element.
|
|
163
|
+
* @param e2 Second element.
|
|
164
|
+
* @return `(e1 - e2) % productOfAllCharacteristics`, such that the result is positive.
|
|
165
|
+
*/
|
|
166
|
+
[[nodiscard]] Element subtract(Element e1, Element e2) const
|
|
167
|
+
{
|
|
168
|
+
return _subtract(get_value(e1), get_value(e2), productOfAllCharacteristics_);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @brief Stores in the first element the subtraction in the field of the first element by the second element,
|
|
173
|
+
* that is `(e1 - e2) % productOfAllCharacteristics`, such that the result is positive.
|
|
174
|
+
*
|
|
175
|
+
* @param e1 First element.
|
|
176
|
+
* @param e2 Second element.
|
|
177
|
+
*/
|
|
178
|
+
void subtract_inplace_front(Element& e1, Element e2) const
|
|
179
|
+
{
|
|
180
|
+
e1 = _subtract(get_value(e1), get_value(e2), productOfAllCharacteristics_);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @brief Stores in the second element the subtraction in the field of the first element by the second element,
|
|
185
|
+
* that is `(e1 - e2) % productOfAllCharacteristics`, such that the result is positive.
|
|
186
|
+
*
|
|
187
|
+
* @param e1 First element.
|
|
188
|
+
* @param e2 Second element.
|
|
189
|
+
*/
|
|
190
|
+
void subtract_inplace_back(Element e1, Element& e2) const
|
|
191
|
+
{
|
|
192
|
+
e2 = _subtract(get_value(e1), get_value(e2), productOfAllCharacteristics_);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @brief Returns the multiplication of two elements in the field.
|
|
197
|
+
*
|
|
198
|
+
* @param e1 First element.
|
|
199
|
+
* @param e2 Second element.
|
|
200
|
+
* @return `(e1 * e2) % productOfAllCharacteristics`, such that the result is positive.
|
|
201
|
+
*/
|
|
202
|
+
[[nodiscard]] Element multiply(Element e1, Element e2) const
|
|
203
|
+
{
|
|
204
|
+
return _multiply(get_value(e1), get_value(e2), productOfAllCharacteristics_);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @brief Stores in the first element the multiplication of two given elements in the field,
|
|
209
|
+
* that is `(e1 * e2) % productOfAllCharacteristics`, such that the result is positive.
|
|
210
|
+
*
|
|
211
|
+
* @param e1 First element.
|
|
212
|
+
* @param e2 Second element.
|
|
213
|
+
*/
|
|
214
|
+
void multiply_inplace(Element& e1, Element e2) const
|
|
215
|
+
{
|
|
216
|
+
e1 = _multiply(get_value(e1), get_value(e2), productOfAllCharacteristics_);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @brief Multiplies the first element with the second one and adds the third one. Returns the result in the field.
|
|
221
|
+
*
|
|
222
|
+
* @warning Not overflow safe.
|
|
223
|
+
*
|
|
224
|
+
* @param e First element.
|
|
225
|
+
* @param m Second element.
|
|
226
|
+
* @param a Third element.
|
|
227
|
+
* @return `(e * m + a) % productOfAllCharacteristics`, such that the result is positive.
|
|
228
|
+
*/
|
|
229
|
+
[[nodiscard]] Element multiply_and_add(Element e, Element m, Element a) const { return get_value((e * m) + a); }
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @brief Multiplies the first element with the second one and adds the third one, that is
|
|
233
|
+
* `(e * m + a) % productOfAllCharacteristics`, such that the result is positive.
|
|
234
|
+
* Stores the result in the first element.
|
|
235
|
+
*
|
|
236
|
+
* @warning Not overflow safe.
|
|
237
|
+
*
|
|
238
|
+
* @param e First element.
|
|
239
|
+
* @param m Second element.
|
|
240
|
+
* @param a Third element.
|
|
241
|
+
*/
|
|
242
|
+
void multiply_and_add_inplace_front(Element& e, Element m, Element a) const { e = get_value((e * m) + a); }
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @brief Multiplies the first element with the second one and adds the third one, that is
|
|
246
|
+
* `(e * m + a) % productOfAllCharacteristics`, such that the result is positive.
|
|
247
|
+
* Stores the result in the third element.
|
|
248
|
+
*
|
|
249
|
+
* @warning Not overflow safe.
|
|
250
|
+
*
|
|
251
|
+
* @param e First element.
|
|
252
|
+
* @param m Second element.
|
|
253
|
+
* @param a Third element.
|
|
254
|
+
*/
|
|
255
|
+
void multiply_and_add_inplace_back(Element e, Element m, Element& a) const { a = get_value((e * m) + a); }
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @brief Adds the first element to the second one and multiplies the third one with it.
|
|
259
|
+
* Returns the result in the field.
|
|
260
|
+
*
|
|
261
|
+
* @warning Not overflow safe.
|
|
262
|
+
*
|
|
263
|
+
* @param e First element.
|
|
264
|
+
* @param a Second element.
|
|
265
|
+
* @param m Third element.
|
|
266
|
+
* @return `((e + a) * m) % productOfAllCharacteristics`, such that the result is positive.
|
|
267
|
+
*/
|
|
268
|
+
[[nodiscard]] Element add_and_multiply(Element e, Element a, Element m) const { return get_value((e + a) * m); }
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @brief Adds the first element to the second one and multiplies the third one with it, that is
|
|
272
|
+
* `((e + a) * m) % productOfAllCharacteristics`, such that the result is positive.
|
|
273
|
+
* Stores the result in the first element.
|
|
274
|
+
*
|
|
275
|
+
* @warning Not overflow safe.
|
|
276
|
+
*
|
|
277
|
+
* @param e First element.
|
|
278
|
+
* @param a Second element.
|
|
279
|
+
* @param m Third element.
|
|
280
|
+
*/
|
|
281
|
+
void add_and_multiply_inplace_front(Element& e, Element a, Element m) const { e = get_value((e + a) * m); }
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @brief Adds the first element to the second one and multiplies the third one with it, that is
|
|
285
|
+
* `((e + a) * m) % productOfAllCharacteristics`, such that the result is positive.
|
|
286
|
+
* Stores the result in the third element.
|
|
287
|
+
*
|
|
288
|
+
* @warning Not overflow safe.
|
|
289
|
+
*
|
|
290
|
+
* @param e First element.
|
|
291
|
+
* @param a Second element.
|
|
292
|
+
* @param m Third element.
|
|
293
|
+
*/
|
|
294
|
+
void add_and_multiply_inplace_back(Element e, Element a, Element& m) const { m = get_value((e + a) * m); }
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* @brief Returns true if the two given elements are equal in the field, false otherwise.
|
|
298
|
+
*
|
|
299
|
+
* @param e1 First element to compare.
|
|
300
|
+
* @param e2 Second element to compare.
|
|
301
|
+
* @return true If `e1 % productOfAllCharacteristics == e2 % productOfAllCharacteristics`.
|
|
302
|
+
* @return false Otherwise.
|
|
303
|
+
*/
|
|
304
|
+
[[nodiscard]] bool are_equal(Element e1, Element e2) const { return get_value(e1) == get_value(e2); }
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* @brief Returns the inverse of the given element in the sense of @cite boissonnat:hal-00922572 with respect
|
|
308
|
+
* to the product of all characteristics.
|
|
309
|
+
*
|
|
310
|
+
* @param e Element to get the inverse from.
|
|
311
|
+
* @return Inverse in the current field.
|
|
312
|
+
*/
|
|
313
|
+
[[nodiscard]] Element get_inverse(const Element& e) const
|
|
314
|
+
{
|
|
315
|
+
return get_partial_inverse(e, productOfAllCharacteristics_).first;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* @brief Returns the inverse of the given element in the multi-field corresponding to the given sub-product
|
|
320
|
+
* of the product of all characteristics in the multi-field. See @cite boissonnat:hal-00922572 for more details.
|
|
321
|
+
*
|
|
322
|
+
* @param e Element to get the inverse from.
|
|
323
|
+
* @param productOfCharacteristics Product of the different characteristics to take into account in the multi-field.
|
|
324
|
+
* @return Pair of the inverse of @p e and the characteristic the inverse is coming from.
|
|
325
|
+
*/
|
|
326
|
+
std::pair<Element, Characteristic> get_partial_inverse(const Element& e,
|
|
327
|
+
const Characteristic& productOfCharacteristics) const
|
|
328
|
+
{
|
|
329
|
+
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
|
|
330
|
+
"The given product is not the product of a subset of the current Multi-field characteristics.");
|
|
331
|
+
|
|
332
|
+
Characteristic gcd = std::gcd(e, productOfAllCharacteristics_);
|
|
333
|
+
|
|
334
|
+
if (gcd == productOfCharacteristics) return {0, get_multiplicative_identity()}; // partial inverse is 0
|
|
335
|
+
|
|
336
|
+
Characteristic QT = productOfCharacteristics / gcd;
|
|
337
|
+
|
|
338
|
+
const Characteristic inv_qt = _get_inverse(e, QT);
|
|
339
|
+
|
|
340
|
+
auto res = get_partial_multiplicative_identity(QT);
|
|
341
|
+
res = _multiply(res, inv_qt, productOfAllCharacteristics_);
|
|
342
|
+
|
|
343
|
+
return {res, QT};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @brief Returns the additive identity of a field.
|
|
348
|
+
*
|
|
349
|
+
* @return The additive identity of a field.
|
|
350
|
+
*/
|
|
351
|
+
static constexpr Element get_additive_identity() { return 0; }
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* @brief Returns the multiplicative identity of a field.
|
|
355
|
+
*
|
|
356
|
+
* @return The multiplicative identity of a field.
|
|
357
|
+
*/
|
|
358
|
+
static constexpr Element get_multiplicative_identity() { return 1; }
|
|
359
|
+
|
|
360
|
+
// static Element get_multiplicative_identity(){ return multiplicativeID_; }
|
|
361
|
+
/**
|
|
362
|
+
* @brief Returns the partial multiplicative identity of the multi-field from the given product.
|
|
363
|
+
* See @cite boissonnat:hal-00922572 for more details.
|
|
364
|
+
*
|
|
365
|
+
* @param productOfCharacteristics Product of the different characteristics to take into account in the multi-field.
|
|
366
|
+
* @return The partial multiplicative identity of the multi-field.
|
|
367
|
+
*/
|
|
368
|
+
[[nodiscard]] Element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics) const
|
|
369
|
+
{
|
|
370
|
+
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
|
|
371
|
+
"The given product is not the product of a subset of the current Multi-field characteristics.");
|
|
372
|
+
|
|
373
|
+
if (productOfCharacteristics == nullCharacteristic || productOfCharacteristics == productOfAllCharacteristics_) {
|
|
374
|
+
return get_multiplicative_identity();
|
|
375
|
+
}
|
|
376
|
+
Element multIdentity = 0;
|
|
377
|
+
for (unsigned int idx = 0; idx < primes_.size(); ++idx) {
|
|
378
|
+
if ((productOfCharacteristics % primes_[idx]) == 0) {
|
|
379
|
+
multIdentity = _add(multIdentity, partials_[idx], productOfAllCharacteristics_);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return multIdentity;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @brief Swap operator.
|
|
387
|
+
*/
|
|
388
|
+
friend void swap(Multi_field_operators_with_small_characteristics& f1,
|
|
389
|
+
Multi_field_operators_with_small_characteristics& f2) noexcept
|
|
390
|
+
{
|
|
391
|
+
f1.primes_.swap(f2.primes_);
|
|
392
|
+
std::swap(f1.productOfAllCharacteristics_, f2.productOfAllCharacteristics_);
|
|
393
|
+
f1.partials_.swap(f2.partials_);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
private:
|
|
397
|
+
std::vector<unsigned int> primes_; /**< All characteristics. */
|
|
398
|
+
Characteristic productOfAllCharacteristics_; /**< Product of all characteristics. */
|
|
399
|
+
std::vector<Characteristic> partials_; /**< Partial products of the characteristics. */
|
|
400
|
+
|
|
401
|
+
// static inline constexpr unsigned int multiplicativeID_ = 1;
|
|
402
|
+
|
|
403
|
+
static Element _add(Element element, Element v, Characteristic characteristic)
|
|
404
|
+
{
|
|
405
|
+
if (UINT_MAX - element < v) {
|
|
406
|
+
// automatic unsigned integer overflow behaviour will make it work
|
|
407
|
+
element += v;
|
|
408
|
+
element -= characteristic;
|
|
409
|
+
return element;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
element += v;
|
|
413
|
+
if (element >= characteristic) element -= characteristic;
|
|
414
|
+
|
|
415
|
+
return element;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
static Element _subtract(Element element, Element v, Characteristic characteristic)
|
|
419
|
+
{
|
|
420
|
+
if (element < v) {
|
|
421
|
+
element += characteristic;
|
|
422
|
+
}
|
|
423
|
+
element -= v;
|
|
424
|
+
|
|
425
|
+
return element;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
static Element _multiply(Element a, Element b, Characteristic characteristic)
|
|
429
|
+
{
|
|
430
|
+
Element res = 0;
|
|
431
|
+
Element temp_b = 0;
|
|
432
|
+
|
|
433
|
+
if (b < a) std::swap(a, b);
|
|
434
|
+
|
|
435
|
+
while (a != 0) {
|
|
436
|
+
if (a & 1) {
|
|
437
|
+
/* Add b to res, modulo m, without overflow */
|
|
438
|
+
if (b >= characteristic - res) res -= characteristic;
|
|
439
|
+
res += b;
|
|
440
|
+
}
|
|
441
|
+
a >>= 1;
|
|
442
|
+
|
|
443
|
+
/* Double b, modulo m */
|
|
444
|
+
temp_b = b;
|
|
445
|
+
if (b >= characteristic - b) temp_b -= characteristic;
|
|
446
|
+
b += temp_b;
|
|
447
|
+
}
|
|
448
|
+
return res;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
static constexpr long int _get_inverse(Element element, Characteristic mod)
|
|
452
|
+
{
|
|
453
|
+
// to solve: Ax + My = 1
|
|
454
|
+
Element M = mod;
|
|
455
|
+
Element A = element;
|
|
456
|
+
long int y = 0, x = 1;
|
|
457
|
+
// extended euclidean division
|
|
458
|
+
while (A > 1) {
|
|
459
|
+
int quotient = A / M;
|
|
460
|
+
int temp = M;
|
|
461
|
+
|
|
462
|
+
M = A % M, A = temp;
|
|
463
|
+
temp = y;
|
|
464
|
+
|
|
465
|
+
y = x - quotient * y;
|
|
466
|
+
x = temp;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (x < 0) x += mod;
|
|
470
|
+
|
|
471
|
+
return x;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
static constexpr bool _is_prime(const int p)
|
|
475
|
+
{
|
|
476
|
+
if (p <= 1) return false;
|
|
477
|
+
if (p <= 3) return true;
|
|
478
|
+
if (p % 2 == 0 || p % 3 == 0) return false;
|
|
479
|
+
|
|
480
|
+
for (long i = 5; i * i <= p; i = i + 6)
|
|
481
|
+
if (p % i == 0 || p % (i + 2) == 0) return false;
|
|
482
|
+
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
} // namespace persistence_fields
|
|
488
|
+
} // namespace Gudhi
|
|
489
|
+
|
|
490
|
+
#endif // MATRIX_FIELD_MULTI_SMALL_OPERATORS_H_
|