multipers 2.3.3b6__cp313-cp313-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.

Potentially problematic release.


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

Files changed (183) hide show
  1. multipers/.dylibs/libc++.1.0.dylib +0 -0
  2. multipers/.dylibs/libtbb.12.16.dylib +0 -0
  3. multipers/__init__.py +33 -0
  4. multipers/_signed_measure_meta.py +453 -0
  5. multipers/_slicer_meta.py +211 -0
  6. multipers/array_api/__init__.py +45 -0
  7. multipers/array_api/numpy.py +41 -0
  8. multipers/array_api/torch.py +58 -0
  9. multipers/data/MOL2.py +458 -0
  10. multipers/data/UCR.py +18 -0
  11. multipers/data/__init__.py +1 -0
  12. multipers/data/graphs.py +466 -0
  13. multipers/data/immuno_regions.py +27 -0
  14. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  15. multipers/data/pytorch2simplextree.py +91 -0
  16. multipers/data/shape3d.py +101 -0
  17. multipers/data/synthetic.py +113 -0
  18. multipers/distances.py +202 -0
  19. multipers/filtration_conversions.pxd +229 -0
  20. multipers/filtration_conversions.pxd.tp +84 -0
  21. multipers/filtrations/__init__.py +18 -0
  22. multipers/filtrations/density.py +574 -0
  23. multipers/filtrations/filtrations.py +361 -0
  24. multipers/filtrations.pxd +224 -0
  25. multipers/function_rips.cpython-313-darwin.so +0 -0
  26. multipers/function_rips.pyx +105 -0
  27. multipers/grids.cpython-313-darwin.so +0 -0
  28. multipers/grids.pyx +433 -0
  29. multipers/gudhi/Persistence_slices_interface.h +132 -0
  30. multipers/gudhi/Simplex_tree_interface.h +239 -0
  31. multipers/gudhi/Simplex_tree_multi_interface.h +551 -0
  32. multipers/gudhi/cubical_to_boundary.h +59 -0
  33. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
  34. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
  35. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
  36. multipers/gudhi/gudhi/Debug_utils.h +45 -0
  37. multipers/gudhi/gudhi/Fields/Multi_field.h +484 -0
  38. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -0
  39. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -0
  40. multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -0
  41. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -0
  42. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -0
  43. multipers/gudhi/gudhi/Fields/Z2_field.h +355 -0
  44. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -0
  45. multipers/gudhi/gudhi/Fields/Zp_field.h +420 -0
  46. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -0
  47. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -0
  48. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
  49. multipers/gudhi/gudhi/Matrix.h +2107 -0
  50. multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -0
  51. multipers/gudhi/gudhi/Multi_persistence/Box.h +174 -0
  52. multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -0
  53. multipers/gudhi/gudhi/Off_reader.h +173 -0
  54. multipers/gudhi/gudhi/One_critical_filtration.h +1441 -0
  55. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -0
  56. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -0
  57. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -0
  58. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -0
  59. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -0
  60. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -0
  61. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -0
  62. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -0
  63. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -0
  64. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -0
  65. multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -0
  66. multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -0
  67. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -0
  68. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -0
  69. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -0
  70. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -0
  71. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -0
  72. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -0
  73. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -0
  74. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -0
  75. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -0
  76. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -0
  77. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -0
  78. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -0
  79. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -0
  80. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -0
  81. multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -0
  82. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -0
  83. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -0
  84. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -0
  85. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -0
  86. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -0
  87. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -0
  88. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -0
  89. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
  90. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
  91. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
  92. multipers/gudhi/gudhi/Persistent_cohomology.h +745 -0
  93. multipers/gudhi/gudhi/Points_off_io.h +171 -0
  94. multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
  95. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -0
  96. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
  97. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -0
  98. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
  99. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
  100. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
  101. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -0
  102. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -0
  103. multipers/gudhi/gudhi/Simplex_tree.h +2794 -0
  104. multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -0
  105. multipers/gudhi/gudhi/distance_functions.h +62 -0
  106. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
  107. multipers/gudhi/gudhi/persistence_interval.h +253 -0
  108. multipers/gudhi/gudhi/persistence_matrix_options.h +170 -0
  109. multipers/gudhi/gudhi/reader_utils.h +367 -0
  110. multipers/gudhi/mma_interface_coh.h +256 -0
  111. multipers/gudhi/mma_interface_h0.h +223 -0
  112. multipers/gudhi/mma_interface_matrix.h +293 -0
  113. multipers/gudhi/naive_merge_tree.h +536 -0
  114. multipers/gudhi/scc_io.h +310 -0
  115. multipers/gudhi/truc.h +1403 -0
  116. multipers/io.cpython-313-darwin.so +0 -0
  117. multipers/io.pyx +644 -0
  118. multipers/ml/__init__.py +0 -0
  119. multipers/ml/accuracies.py +90 -0
  120. multipers/ml/invariants_with_persistable.py +79 -0
  121. multipers/ml/kernels.py +176 -0
  122. multipers/ml/mma.py +713 -0
  123. multipers/ml/one.py +472 -0
  124. multipers/ml/point_clouds.py +352 -0
  125. multipers/ml/signed_measures.py +1589 -0
  126. multipers/ml/sliced_wasserstein.py +461 -0
  127. multipers/ml/tools.py +113 -0
  128. multipers/mma_structures.cpython-313-darwin.so +0 -0
  129. multipers/mma_structures.pxd +128 -0
  130. multipers/mma_structures.pyx +2786 -0
  131. multipers/mma_structures.pyx.tp +1094 -0
  132. multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -0
  133. multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -0
  134. multipers/multi_parameter_rank_invariant/function_rips.h +322 -0
  135. multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -0
  136. multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -0
  137. multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -0
  138. multipers/multiparameter_edge_collapse.py +41 -0
  139. multipers/multiparameter_module_approximation/approximation.h +2330 -0
  140. multipers/multiparameter_module_approximation/combinatory.h +129 -0
  141. multipers/multiparameter_module_approximation/debug.h +107 -0
  142. multipers/multiparameter_module_approximation/euler_curves.h +0 -0
  143. multipers/multiparameter_module_approximation/format_python-cpp.h +286 -0
  144. multipers/multiparameter_module_approximation/heap_column.h +238 -0
  145. multipers/multiparameter_module_approximation/images.h +79 -0
  146. multipers/multiparameter_module_approximation/list_column.h +174 -0
  147. multipers/multiparameter_module_approximation/list_column_2.h +232 -0
  148. multipers/multiparameter_module_approximation/ru_matrix.h +347 -0
  149. multipers/multiparameter_module_approximation/set_column.h +135 -0
  150. multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -0
  151. multipers/multiparameter_module_approximation/unordered_set_column.h +166 -0
  152. multipers/multiparameter_module_approximation/utilities.h +403 -0
  153. multipers/multiparameter_module_approximation/vector_column.h +223 -0
  154. multipers/multiparameter_module_approximation/vector_matrix.h +331 -0
  155. multipers/multiparameter_module_approximation/vineyards.h +464 -0
  156. multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -0
  157. multipers/multiparameter_module_approximation.cpython-313-darwin.so +0 -0
  158. multipers/multiparameter_module_approximation.pyx +235 -0
  159. multipers/pickle.py +90 -0
  160. multipers/plots.py +456 -0
  161. multipers/point_measure.cpython-313-darwin.so +0 -0
  162. multipers/point_measure.pyx +395 -0
  163. multipers/simplex_tree_multi.cpython-313-darwin.so +0 -0
  164. multipers/simplex_tree_multi.pxd +134 -0
  165. multipers/simplex_tree_multi.pyx +10840 -0
  166. multipers/simplex_tree_multi.pyx.tp +2009 -0
  167. multipers/slicer.cpython-313-darwin.so +0 -0
  168. multipers/slicer.pxd +3034 -0
  169. multipers/slicer.pxd.tp +234 -0
  170. multipers/slicer.pyx +20481 -0
  171. multipers/slicer.pyx.tp +1088 -0
  172. multipers/tensor/tensor.h +672 -0
  173. multipers/tensor.pxd +13 -0
  174. multipers/test.pyx +44 -0
  175. multipers/tests/__init__.py +62 -0
  176. multipers/torch/__init__.py +1 -0
  177. multipers/torch/diff_grids.py +240 -0
  178. multipers/torch/rips_density.py +310 -0
  179. multipers-2.3.3b6.dist-info/METADATA +128 -0
  180. multipers-2.3.3b6.dist-info/RECORD +183 -0
  181. multipers-2.3.3b6.dist-info/WHEEL +6 -0
  182. multipers-2.3.3b6.dist-info/licenses/LICENSE +21 -0
  183. multipers-2.3.3b6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,455 @@
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_operators.h
13
+ * @author Hannah Schreiber, Clément Maria
14
+ * @brief Contains the @ref Gudhi::persistence_fields::Multi_field_operators class.
15
+ */
16
+
17
+ #ifndef MATRIX_FIELD_MULTI_OPERATORS_H_
18
+ #define MATRIX_FIELD_MULTI_OPERATORS_H_
19
+
20
+ #include <utility>
21
+ #include <vector>
22
+ #include <gmpxx.h>
23
+ #include <stdexcept>
24
+
25
+ namespace Gudhi {
26
+ namespace persistence_fields {
27
+
28
+ /**
29
+ * @class Multi_field_operators Multi_field_operators.h gudhi/Fields/Multi_field_operators.h
30
+ * @ingroup persistence_fields
31
+ *
32
+ * @brief Class defining operators for a multi-field with "consecutive" characteristic range.
33
+ */
34
+ class Multi_field_operators
35
+ {
36
+ public:
37
+ using Element = mpz_class; /**< Type for the elements in the field. */
38
+ using Characteristic = Element; /**< Type for the field characteristic. */
39
+
40
+ /**
41
+ * @brief Default constructor, sets the product of all characteristics to 0.
42
+ */
43
+ Multi_field_operators() : productOfAllCharacteristics_(0) /* , multiplicativeID_(1) */
44
+ {}
45
+ /**
46
+ * @brief Constructor setting the characteristics to all prime numbers between the two given integers.
47
+ *
48
+ * @param minCharacteristic Smallest value of a prime.
49
+ * @param maxCharacteristic Highest value of a prime.
50
+ */
51
+ Multi_field_operators(int minCharacteristic, int maxCharacteristic)
52
+ : productOfAllCharacteristics_(0) //, multiplicativeID_(1)
53
+ {
54
+ set_characteristic(minCharacteristic, maxCharacteristic);
55
+ }
56
+ /**
57
+ * @brief Copy constructor.
58
+ *
59
+ * @param toCopy Operators to copy.
60
+ */
61
+ Multi_field_operators(const Multi_field_operators& toCopy)
62
+ : primes_(toCopy.primes_),
63
+ productOfAllCharacteristics_(toCopy.productOfAllCharacteristics_),
64
+ partials_(toCopy.partials_) /* ,
65
+ multiplicativeID_(toCopy.multiplicativeID_) */
66
+ {}
67
+ /**
68
+ * @brief Move constructor.
69
+ *
70
+ * @param toMove Operators to move.
71
+ */
72
+ Multi_field_operators(Multi_field_operators&& toMove) noexcept
73
+ : primes_(std::move(toMove.primes_)),
74
+ productOfAllCharacteristics_(std::move(toMove.productOfAllCharacteristics_)),
75
+ partials_(std::move(toMove.partials_)) /* ,
76
+ multiplicativeID_(std::move(toMove.multiplicativeID_)) */
77
+ {}
78
+
79
+ /**
80
+ * @brief Set the characteristics of the field, which are stored in a single value as a product of all of them.
81
+ * The characteristics will be all prime numbers in the given interval.
82
+ *
83
+ * @param minimum Smallest value of a prime.
84
+ * @param maximum Highest value of a prime.
85
+ */
86
+ void set_characteristic(int minimum, int maximum) {
87
+ if (maximum < 2) throw std::invalid_argument("Characteristic must be strictly positive");
88
+ if (minimum > maximum) throw std::invalid_argument("The given interval is not valid.");
89
+ if (minimum == maximum && !_is_prime(minimum))
90
+ throw std::invalid_argument("The given interval does not contain a prime number.");
91
+
92
+ unsigned int curr_prime = minimum;
93
+ mpz_t tmp_prime;
94
+ mpz_init_set_ui(tmp_prime, minimum);
95
+ // test if min_prime is prime
96
+ int is_prime = mpz_probab_prime_p(tmp_prime, 25); // probabilistic primality test
97
+
98
+ if (is_prime == 0) { // min_prime is composite
99
+ mpz_nextprime(tmp_prime, tmp_prime);
100
+ curr_prime = mpz_get_ui(tmp_prime);
101
+ }
102
+
103
+ primes_.clear();
104
+ while (curr_prime <= static_cast<unsigned int>(maximum)) {
105
+ primes_.push_back(curr_prime);
106
+ mpz_nextprime(tmp_prime, tmp_prime);
107
+ curr_prime = mpz_get_ui(tmp_prime);
108
+ }
109
+ mpz_clear(tmp_prime);
110
+
111
+ if (primes_.empty()) throw std::invalid_argument("The given interval does not contain a prime number.");
112
+
113
+ productOfAllCharacteristics_ = 1;
114
+ for (const unsigned int p : primes_) {
115
+ productOfAllCharacteristics_ *= p;
116
+ }
117
+
118
+ partials_.resize(primes_.size());
119
+ for (unsigned int i = 0; i < primes_.size(); ++i) {
120
+ unsigned int p = primes_[i];
121
+ partials_[i] = productOfAllCharacteristics_ / p;
122
+ mpz_powm_ui(partials_[i].get_mpz_t(), partials_[i].get_mpz_t(), p - 1, productOfAllCharacteristics_.get_mpz_t());
123
+ }
124
+
125
+ // If I understood the paper well, multiplicativeID_ always equals to 1. But in Clement's code,
126
+ // multiplicativeID_ is computed (see commented loop below). TODO: verify with Clement.
127
+ // for (unsigned int i = 0; i < partials_.size(); ++i) {
128
+ // multiplicativeID_ = (multiplicativeID_ + partials_[i]) % productOfAllCharacteristics_;
129
+ // }
130
+ }
131
+ /**
132
+ * @brief Returns the current characteristics as the product of all of them.
133
+ *
134
+ * @return The value of the current characteristic.
135
+ */
136
+ const Characteristic& get_characteristic() const { return productOfAllCharacteristics_; }
137
+
138
+ /**
139
+ * @brief Returns the value of an element in the field.
140
+ * That is the positive value of the integer modulo the current characteristic.
141
+ *
142
+ * @param e Element to return the value from.
143
+ * @return @p e modulo the current characteristic, such that the result is positive.
144
+ */
145
+ Element get_value(Element e) const {
146
+ get_value_inplace(e);
147
+ return e;
148
+ }
149
+
150
+ /**
151
+ * @brief Stores in the given element the value of this element in the field.
152
+ * That is the positive value of the integer modulo the current characteristic.
153
+ *
154
+ * @param e Element to return the value from.
155
+ */
156
+ void get_value_inplace(Element& e) const {
157
+ if (e >= productOfAllCharacteristics_ || e < -productOfAllCharacteristics_)
158
+ mpz_mod(e.get_mpz_t(), e.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
159
+ if (e < 0) e += productOfAllCharacteristics_;
160
+ }
161
+
162
+ /**
163
+ * @brief Returns the sum of two elements in the field.
164
+ *
165
+ * @param e1 First element.
166
+ * @param e2 Second element.
167
+ * @return `(e1 + e2) % productOfAllCharacteristics`, such that the result is positive.
168
+ */
169
+ Element add(Element e1, const Element& e2) const {
170
+ add_inplace(e1, e2);
171
+ return e1;
172
+ }
173
+
174
+ /**
175
+ * @brief Stores in the first element the sum of two given elements in the field, that is
176
+ * `(e1 + e2) % productOfAllCharacteristics`, such that the result is positive.
177
+ *
178
+ * @param e1 First element.
179
+ * @param e2 Second element.
180
+ */
181
+ void add_inplace(Element& e1, const Element& e2) const {
182
+ e1 += e2;
183
+ get_value_inplace(e1);
184
+ }
185
+
186
+ /**
187
+ * @brief Returns the subtraction in the field of the first element by the second element.
188
+ *
189
+ * @param e1 First element.
190
+ * @param e2 Second element.
191
+ * @return `(e1 - e2) % productOfAllCharacteristics`, such that the result is positive.
192
+ */
193
+ Element subtract(Element e1, const Element& e2) const {
194
+ subtract_inplace_front(e1, e2);
195
+ return e1;
196
+ }
197
+
198
+ /**
199
+ * @brief Stores in the first element the subtraction in the field of the first element by the second element,
200
+ * that is `(e1 - e2) % productOfAllCharacteristics`, such that the result is positive.
201
+ *
202
+ * @param e1 First element.
203
+ * @param e2 Second element.
204
+ */
205
+ void subtract_inplace_front(Element& e1, const Element& e2) const {
206
+ e1 -= e2;
207
+ get_value_inplace(e1);
208
+ }
209
+ /**
210
+ * @brief Stores in the second element the subtraction in the field of the first element by the second element,
211
+ * that is `(e1 - e2) % productOfAllCharacteristics`, such that the result is positive.
212
+ *
213
+ * @param e1 First element.
214
+ * @param e2 Second element.
215
+ */
216
+ void subtract_inplace_back(const Element& e1, Element& e2) const {
217
+ mpz_sub(e2.get_mpz_t(), e1.get_mpz_t(), e2.get_mpz_t());
218
+ get_value_inplace(e2);
219
+ }
220
+
221
+ /**
222
+ * @brief Returns the multiplication of two elements in the field.
223
+ *
224
+ * @param e1 First element.
225
+ * @param e2 Second element.
226
+ * @return `(e1 * e2) % productOfAllCharacteristics`, such that the result is positive.
227
+ */
228
+ Element multiply(Element e1, const Element& e2) const {
229
+ multiply_inplace(e1, e2);
230
+ return e1;
231
+ }
232
+
233
+ /**
234
+ * @brief Stores in the first element the multiplication of two given elements in the field,
235
+ * that is `(e1 * e2) % productOfAllCharacteristics`, such that the result is positive.
236
+ *
237
+ * @param e1 First element.
238
+ * @param e2 Second element.
239
+ */
240
+ void multiply_inplace(Element& e1, const Element& e2) const {
241
+ e1 *= e2;
242
+ get_value_inplace(e1);
243
+ }
244
+
245
+ /**
246
+ * @brief Multiplies the first element with the second one and adds the third one. Returns the result in the field.
247
+ *
248
+ * @param e First element.
249
+ * @param m Second element.
250
+ * @param a Third element.
251
+ * @return `(e * m + a) % productOfAllCharacteristics`, such that the result is positive.
252
+ */
253
+ Element multiply_and_add(Element e, const Element& m, const Element& a) const {
254
+ multiply_and_add_inplace_front(e, m, a);
255
+ return e;
256
+ }
257
+
258
+ /**
259
+ * @brief Multiplies the first element with the second one and adds the third one, that is
260
+ * `(e * m + a) % productOfAllCharacteristics`, such that the result is positive.
261
+ * Stores the result in the first element.
262
+ *
263
+ * @param e First element.
264
+ * @param m Second element.
265
+ * @param a Third element.
266
+ */
267
+ void multiply_and_add_inplace_front(Element& e, const Element& m, const Element& a) const {
268
+ e *= m;
269
+ e += a;
270
+ get_value_inplace(e);
271
+ }
272
+ /**
273
+ * @brief Multiplies the first element with the second one and adds the third one, that is
274
+ * `(e * m + a) % productOfAllCharacteristics`, such that the result is positive.
275
+ * Stores the result in the third element.
276
+ *
277
+ * @param e First element.
278
+ * @param m Second element.
279
+ * @param a Third element.
280
+ */
281
+ void multiply_and_add_inplace_back(const Element& e, const Element& m, Element& a) const {
282
+ a += e * m;
283
+ get_value_inplace(a);
284
+ }
285
+
286
+ /**
287
+ * @brief Adds the first element to the second one and multiplies the third one with it.
288
+ * Returns the result in the field.
289
+ *
290
+ * @param e First element.
291
+ * @param a Second element.
292
+ * @param m Third element.
293
+ * @return `((e + a) * m) % productOfAllCharacteristics`, such that the result is positive.
294
+ */
295
+ Element add_and_multiply(Element e, const Element& a, const Element& m) const {
296
+ add_and_multiply_inplace_front(e, a, m);
297
+ return e;
298
+ }
299
+
300
+ /**
301
+ * @brief Adds the first element to the second one and multiplies the third one with it, that is
302
+ * `((e + a) * m) % productOfAllCharacteristics`, such that the result is positive.
303
+ * Stores the result in the first element.
304
+ *
305
+ * @param e First element.
306
+ * @param a Second element.
307
+ * @param m Third element.
308
+ */
309
+ void add_and_multiply_inplace_front(Element& e, const Element& a, const Element& m) const {
310
+ e += a;
311
+ e *= m;
312
+ get_value_inplace(e);
313
+ }
314
+ /**
315
+ * @brief Adds the first element to the second one and multiplies the third one with it, that is
316
+ * `((e + a) * m) % productOfAllCharacteristics`, such that the result is positive.
317
+ * Stores the result in the third element.
318
+ *
319
+ * @param e First element.
320
+ * @param a Second element.
321
+ * @param m Third element.
322
+ */
323
+ void add_and_multiply_inplace_back(const Element& e, const Element& a, Element& m) const {
324
+ m *= e + a;
325
+ get_value_inplace(m);
326
+ }
327
+
328
+ /**
329
+ * @brief Returns true if the two given elements are equal in the field, false otherwise.
330
+ *
331
+ * @param e1 First element to compare.
332
+ * @param e2 Second element to compare.
333
+ * @return true If `e1 % productOfAllCharacteristics == e2 % productOfAllCharacteristics`.
334
+ * @return false Otherwise.
335
+ */
336
+ bool are_equal(const Element& e1, const Element& e2) const {
337
+ if (e1 == e2) return true;
338
+ return get_value(e1) == get_value(e2);
339
+ }
340
+
341
+ /**
342
+ * @brief Returns the inverse of the given element in the sense of @cite boissonnat:hal-00922572 with respect
343
+ * to the product of all characteristics.
344
+ *
345
+ * @param e Element to get the inverse from.
346
+ * @return Inverse in the current field.
347
+ */
348
+ Element get_inverse(const Element& e) const {
349
+ return get_partial_inverse(e, productOfAllCharacteristics_).first;
350
+ }
351
+ /**
352
+ * @brief Returns the inverse of the given element in the multi-field corresponding to the given sub-product
353
+ * of the product of all characteristics in the multi-field. See @cite boissonnat:hal-00922572 for more details.
354
+ *
355
+ * @param e Element to get the inverse from.
356
+ * @param productOfCharacteristics Product of the different characteristics to take into account in the multi-field.
357
+ * @return Pair of the inverse of @p e and the characteristic the inverse is coming from.
358
+ */
359
+ std::pair<Element, Characteristic> get_partial_inverse(
360
+ const Element& e, const Characteristic& productOfCharacteristics) const {
361
+ Characteristic QR;
362
+ mpz_gcd(QR.get_mpz_t(), e.get_mpz_t(), productOfCharacteristics.get_mpz_t()); // QR <- gcd(x,QS)
363
+
364
+ if (QR == productOfCharacteristics) return {0, get_multiplicative_identity()}; // partial inverse is 0
365
+
366
+ Characteristic QT = productOfCharacteristics / QR;
367
+
368
+ Characteristic inv_qt;
369
+ mpz_invert(inv_qt.get_mpz_t(), e.get_mpz_t(), QT.get_mpz_t());
370
+
371
+ std::pair<Element, Characteristic> res(get_partial_multiplicative_identity(QT), QT);
372
+ res.first *= inv_qt;
373
+ get_value_inplace(res.first);
374
+
375
+ return res;
376
+ }
377
+
378
+ /**
379
+ * @brief Returns the additive identity of a field.
380
+ *
381
+ * @return The additive identity of a field.
382
+ */
383
+ static const Element& get_additive_identity() { return additiveID_; }
384
+ /**
385
+ * @brief Returns the multiplicative identity of a field.
386
+ *
387
+ * @return The multiplicative identity of a field.
388
+ */
389
+ static const Element& get_multiplicative_identity() { return multiplicativeID_; }
390
+
391
+ /**
392
+ * @brief Returns the partial multiplicative identity of the multi-field from the given product.
393
+ * See @cite boissonnat:hal-00922572 for more details.
394
+ *
395
+ * @param productOfCharacteristics Product of the different characteristics to take into account in the multi-field.
396
+ * @return The partial multiplicative identity of the multi-field.
397
+ */
398
+ Element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics) const {
399
+ if (productOfCharacteristics == 0) {
400
+ return get_multiplicative_identity();
401
+ }
402
+ Element multIdentity(0);
403
+ for (unsigned int idx = 0; idx < primes_.size(); ++idx) {
404
+ if ((productOfCharacteristics % primes_[idx]) == 0) {
405
+ multIdentity += partials_[idx];
406
+ }
407
+ }
408
+ get_value_inplace(multIdentity);
409
+ return multIdentity;
410
+ }
411
+
412
+ // static constexpr bool handles_only_z2() { return false; }
413
+
414
+ /**
415
+ * @brief Assign operator.
416
+ */
417
+ Multi_field_operators& operator=(Multi_field_operators other) {
418
+ primes_.swap(other.primes_);
419
+ productOfAllCharacteristics_ = other.productOfAllCharacteristics_;
420
+ partials_.swap(other.partials_);
421
+
422
+ return *this;
423
+ }
424
+ /**
425
+ * @brief Swap operator.
426
+ */
427
+ friend void swap(Multi_field_operators& f1, Multi_field_operators& f2) {
428
+ f1.primes_.swap(f2.primes_);
429
+ std::swap(f1.productOfAllCharacteristics_, f2.productOfAllCharacteristics_);
430
+ f1.partials_.swap(f2.partials_);
431
+ }
432
+
433
+ private:
434
+ std::vector<unsigned int> primes_; /**< All characteristics. */
435
+ Characteristic productOfAllCharacteristics_; /**< Product of all characteristics. */
436
+ std::vector<Characteristic> partials_; /**< Partial products of the characteristics. */
437
+ inline static const Element multiplicativeID_ = 1;
438
+ inline static const Element additiveID_ = 0;
439
+
440
+ static constexpr bool _is_prime(const int p) {
441
+ if (p <= 1) return false;
442
+ if (p <= 3) return true;
443
+ if (p % 2 == 0 || p % 3 == 0) return false;
444
+
445
+ for (long i = 5; i * i <= p; i = i + 6)
446
+ if (p % i == 0 || p % (i + 2) == 0) return false;
447
+
448
+ return true;
449
+ }
450
+ };
451
+
452
+ } // namespace persistence_fields
453
+ } // namespace Gudhi
454
+
455
+ #endif // MATRIX_FIELD_MULTI_OPERATORS_H_