multipers 2.3.3b6__cp312-cp312-manylinux_2_39_x86_64.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 (182) hide show
  1. multipers/__init__.py +33 -0
  2. multipers/_signed_measure_meta.py +453 -0
  3. multipers/_slicer_meta.py +211 -0
  4. multipers/array_api/__init__.py +45 -0
  5. multipers/array_api/numpy.py +41 -0
  6. multipers/array_api/torch.py +58 -0
  7. multipers/data/MOL2.py +458 -0
  8. multipers/data/UCR.py +18 -0
  9. multipers/data/__init__.py +1 -0
  10. multipers/data/graphs.py +466 -0
  11. multipers/data/immuno_regions.py +27 -0
  12. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  13. multipers/data/pytorch2simplextree.py +91 -0
  14. multipers/data/shape3d.py +101 -0
  15. multipers/data/synthetic.py +113 -0
  16. multipers/distances.py +202 -0
  17. multipers/filtration_conversions.pxd +229 -0
  18. multipers/filtration_conversions.pxd.tp +84 -0
  19. multipers/filtrations/__init__.py +18 -0
  20. multipers/filtrations/density.py +574 -0
  21. multipers/filtrations/filtrations.py +361 -0
  22. multipers/filtrations.pxd +224 -0
  23. multipers/function_rips.cpython-312-x86_64-linux-gnu.so +0 -0
  24. multipers/function_rips.pyx +105 -0
  25. multipers/grids.cpython-312-x86_64-linux-gnu.so +0 -0
  26. multipers/grids.pyx +433 -0
  27. multipers/gudhi/Persistence_slices_interface.h +132 -0
  28. multipers/gudhi/Simplex_tree_interface.h +239 -0
  29. multipers/gudhi/Simplex_tree_multi_interface.h +551 -0
  30. multipers/gudhi/cubical_to_boundary.h +59 -0
  31. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
  32. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
  33. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
  34. multipers/gudhi/gudhi/Debug_utils.h +45 -0
  35. multipers/gudhi/gudhi/Fields/Multi_field.h +484 -0
  36. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -0
  37. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -0
  38. multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -0
  39. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -0
  40. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -0
  41. multipers/gudhi/gudhi/Fields/Z2_field.h +355 -0
  42. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -0
  43. multipers/gudhi/gudhi/Fields/Zp_field.h +420 -0
  44. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -0
  45. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -0
  46. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
  47. multipers/gudhi/gudhi/Matrix.h +2107 -0
  48. multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -0
  49. multipers/gudhi/gudhi/Multi_persistence/Box.h +174 -0
  50. multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -0
  51. multipers/gudhi/gudhi/Off_reader.h +173 -0
  52. multipers/gudhi/gudhi/One_critical_filtration.h +1441 -0
  53. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -0
  54. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -0
  55. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -0
  56. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -0
  57. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -0
  58. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -0
  59. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -0
  60. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -0
  61. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -0
  62. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -0
  63. multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -0
  64. multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -0
  65. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -0
  66. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -0
  67. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -0
  68. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -0
  69. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -0
  70. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -0
  71. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -0
  72. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -0
  73. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -0
  74. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -0
  75. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -0
  76. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -0
  77. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -0
  78. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -0
  79. multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -0
  80. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -0
  81. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -0
  82. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -0
  83. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -0
  84. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -0
  85. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -0
  86. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -0
  87. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
  88. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
  89. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
  90. multipers/gudhi/gudhi/Persistent_cohomology.h +745 -0
  91. multipers/gudhi/gudhi/Points_off_io.h +171 -0
  92. multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
  93. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -0
  94. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
  95. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -0
  96. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
  97. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
  98. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
  99. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -0
  100. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -0
  101. multipers/gudhi/gudhi/Simplex_tree.h +2794 -0
  102. multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -0
  103. multipers/gudhi/gudhi/distance_functions.h +62 -0
  104. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
  105. multipers/gudhi/gudhi/persistence_interval.h +253 -0
  106. multipers/gudhi/gudhi/persistence_matrix_options.h +170 -0
  107. multipers/gudhi/gudhi/reader_utils.h +367 -0
  108. multipers/gudhi/mma_interface_coh.h +256 -0
  109. multipers/gudhi/mma_interface_h0.h +223 -0
  110. multipers/gudhi/mma_interface_matrix.h +293 -0
  111. multipers/gudhi/naive_merge_tree.h +536 -0
  112. multipers/gudhi/scc_io.h +310 -0
  113. multipers/gudhi/truc.h +1403 -0
  114. multipers/io.cpython-312-x86_64-linux-gnu.so +0 -0
  115. multipers/io.pyx +644 -0
  116. multipers/ml/__init__.py +0 -0
  117. multipers/ml/accuracies.py +90 -0
  118. multipers/ml/invariants_with_persistable.py +79 -0
  119. multipers/ml/kernels.py +176 -0
  120. multipers/ml/mma.py +713 -0
  121. multipers/ml/one.py +472 -0
  122. multipers/ml/point_clouds.py +352 -0
  123. multipers/ml/signed_measures.py +1589 -0
  124. multipers/ml/sliced_wasserstein.py +461 -0
  125. multipers/ml/tools.py +113 -0
  126. multipers/mma_structures.cpython-312-x86_64-linux-gnu.so +0 -0
  127. multipers/mma_structures.pxd +128 -0
  128. multipers/mma_structures.pyx +2786 -0
  129. multipers/mma_structures.pyx.tp +1094 -0
  130. multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -0
  131. multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -0
  132. multipers/multi_parameter_rank_invariant/function_rips.h +322 -0
  133. multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -0
  134. multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -0
  135. multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -0
  136. multipers/multiparameter_edge_collapse.py +41 -0
  137. multipers/multiparameter_module_approximation/approximation.h +2330 -0
  138. multipers/multiparameter_module_approximation/combinatory.h +129 -0
  139. multipers/multiparameter_module_approximation/debug.h +107 -0
  140. multipers/multiparameter_module_approximation/euler_curves.h +0 -0
  141. multipers/multiparameter_module_approximation/format_python-cpp.h +286 -0
  142. multipers/multiparameter_module_approximation/heap_column.h +238 -0
  143. multipers/multiparameter_module_approximation/images.h +79 -0
  144. multipers/multiparameter_module_approximation/list_column.h +174 -0
  145. multipers/multiparameter_module_approximation/list_column_2.h +232 -0
  146. multipers/multiparameter_module_approximation/ru_matrix.h +347 -0
  147. multipers/multiparameter_module_approximation/set_column.h +135 -0
  148. multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -0
  149. multipers/multiparameter_module_approximation/unordered_set_column.h +166 -0
  150. multipers/multiparameter_module_approximation/utilities.h +403 -0
  151. multipers/multiparameter_module_approximation/vector_column.h +223 -0
  152. multipers/multiparameter_module_approximation/vector_matrix.h +331 -0
  153. multipers/multiparameter_module_approximation/vineyards.h +464 -0
  154. multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -0
  155. multipers/multiparameter_module_approximation.cpython-312-x86_64-linux-gnu.so +0 -0
  156. multipers/multiparameter_module_approximation.pyx +235 -0
  157. multipers/pickle.py +90 -0
  158. multipers/plots.py +456 -0
  159. multipers/point_measure.cpython-312-x86_64-linux-gnu.so +0 -0
  160. multipers/point_measure.pyx +395 -0
  161. multipers/simplex_tree_multi.cpython-312-x86_64-linux-gnu.so +0 -0
  162. multipers/simplex_tree_multi.pxd +134 -0
  163. multipers/simplex_tree_multi.pyx +10840 -0
  164. multipers/simplex_tree_multi.pyx.tp +2009 -0
  165. multipers/slicer.cpython-312-x86_64-linux-gnu.so +0 -0
  166. multipers/slicer.pxd +3034 -0
  167. multipers/slicer.pxd.tp +234 -0
  168. multipers/slicer.pyx +20481 -0
  169. multipers/slicer.pyx.tp +1088 -0
  170. multipers/tensor/tensor.h +672 -0
  171. multipers/tensor.pxd +13 -0
  172. multipers/test.pyx +44 -0
  173. multipers/tests/__init__.py +62 -0
  174. multipers/torch/__init__.py +1 -0
  175. multipers/torch/diff_grids.py +240 -0
  176. multipers/torch/rips_density.py +310 -0
  177. multipers-2.3.3b6.dist-info/METADATA +128 -0
  178. multipers-2.3.3b6.dist-info/RECORD +182 -0
  179. multipers-2.3.3b6.dist-info/WHEEL +5 -0
  180. multipers-2.3.3b6.dist-info/licenses/LICENSE +21 -0
  181. multipers-2.3.3b6.dist-info/top_level.txt +1 -0
  182. multipers.libs/libtbb-ca48af5c.so.12.16 +0 -0
@@ -0,0 +1,531 @@
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.h
13
+ * @author Hannah Schreiber, Clément Maria
14
+ * @brief Contains the @ref Gudhi::persistence_fields::Multi_field_element_with_small_characteristics class.
15
+ */
16
+
17
+ #ifndef MATRIX_FIELD_MULTI_SMALL_H_
18
+ #define MATRIX_FIELD_MULTI_SMALL_H_
19
+
20
+ #include <utility>
21
+ #include <vector>
22
+ #include <limits.h>
23
+ #include <numeric>
24
+
25
+ namespace Gudhi {
26
+ namespace persistence_fields {
27
+
28
+ /**
29
+ * @class Multi_field_element_with_small_characteristics Multi_field_small.h gudhi/Fields/Multi_field_small.h
30
+ * @ingroup persistence_fields
31
+ *
32
+ * @brief Class representing an element of a multi-field, such that the product of all characteristics fits into
33
+ * the given @p Unsigned_integer_type template argument. The characteristics will corresponds to all prime numbers
34
+ * in the interval given as other template arguments.
35
+ *
36
+ * @tparam minimum Interval closed lower bound.
37
+ * @tparam maximum Interval closed upper bound.
38
+ * @tparam Unsigned_integer_type A native unsigned integer type: unsigned int, long unsigned int, etc.
39
+ * Will be used as the field element type.
40
+ */
41
+ template <unsigned int minimum, unsigned int maximum, typename Unsigned_integer_type = unsigned int,
42
+ class = std::enable_if_t<std::is_unsigned_v<Unsigned_integer_type> > >
43
+ class Multi_field_element_with_small_characteristics {
44
+ public:
45
+ using Element = Unsigned_integer_type; /**< Type for the elements in the field. */
46
+ using Characteristic = Element; /**< Type for the field characteristic. */
47
+ template <class T>
48
+ using isInteger = std::enable_if_t<std::is_integral_v<T> >;
49
+
50
+ /**
51
+ * @brief Default constructor. Sets the element to 0.
52
+ */
53
+ Multi_field_element_with_small_characteristics() : element_(0) {
54
+ static_assert(maximum >= 2, "Characteristics have to be positive.");
55
+ static_assert(minimum <= maximum, "The given interval is not valid.");
56
+ static_assert(minimum != maximum || _is_prime(minimum), "The given interval does not contain a prime number.");
57
+ static_assert(productOfAllCharacteristics_ != 1, "The given interval does not contain a prime number.");
58
+ }
59
+ /**
60
+ * @brief Constructor setting the element to the given value.
61
+ *
62
+ * @param element Value of the element.
63
+ */
64
+ template <typename Integer_type, class = isInteger<Integer_type> >
65
+ Multi_field_element_with_small_characteristics(Integer_type element)
66
+ : element_(_get_value(element)) {
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
+ static_assert(productOfAllCharacteristics_ != 1, "The given interval does not contain a prime number.");
71
+ }
72
+ /**
73
+ * @brief Copy constructor.
74
+ *
75
+ * @param toCopy Element to copy.
76
+ */
77
+ Multi_field_element_with_small_characteristics(const Multi_field_element_with_small_characteristics& toCopy)
78
+ : element_(toCopy.element_) {}
79
+ /**
80
+ * @brief Move constructor.
81
+ *
82
+ * @param toMove Element to move.
83
+ */
84
+ Multi_field_element_with_small_characteristics(Multi_field_element_with_small_characteristics&& toMove) noexcept
85
+ : element_(std::exchange(toMove.element_, 0)) {}
86
+
87
+ /**
88
+ * @brief operator+=
89
+ */
90
+ friend void operator+=(Multi_field_element_with_small_characteristics& f1,
91
+ Multi_field_element_with_small_characteristics const& f2) {
92
+ f1.element_ = _add(f1.element_, f2.element_);
93
+ }
94
+ /**
95
+ * @brief operator+
96
+ */
97
+ friend Multi_field_element_with_small_characteristics operator+(
98
+ Multi_field_element_with_small_characteristics f1, Multi_field_element_with_small_characteristics const& f2) {
99
+ f1 += f2;
100
+ return f1;
101
+ }
102
+ /**
103
+ * @brief operator+=
104
+ *
105
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
106
+ */
107
+ template <typename Integer_type, class = isInteger<Integer_type> >
108
+ friend void operator+=(Multi_field_element_with_small_characteristics& f, const Integer_type& v) {
109
+ f.element_ = _add(f.element_, _get_value(v));
110
+ }
111
+ /**
112
+ * @brief operator+
113
+ *
114
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
115
+ */
116
+ template <typename Integer_type, class = isInteger<Integer_type> >
117
+ friend Multi_field_element_with_small_characteristics operator+(Multi_field_element_with_small_characteristics f,
118
+ const Integer_type& v) {
119
+ f += v;
120
+ return f;
121
+ }
122
+ /**
123
+ * @brief operator+
124
+ *
125
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
126
+ */
127
+ template <typename Integer_type, class = isInteger<Integer_type> >
128
+ friend Integer_type operator+(const Integer_type& v, Multi_field_element_with_small_characteristics f) {
129
+ f += v;
130
+ return f.element_;
131
+ }
132
+
133
+ /**
134
+ * @brief operator-=
135
+ */
136
+ friend void operator-=(Multi_field_element_with_small_characteristics& f1,
137
+ Multi_field_element_with_small_characteristics const& f2) {
138
+ f1.element_ = _subtract(f1.element_, f2.element_);
139
+ }
140
+ /**
141
+ * @brief operator-
142
+ */
143
+ friend Multi_field_element_with_small_characteristics operator-(
144
+ Multi_field_element_with_small_characteristics f1, Multi_field_element_with_small_characteristics const& f2) {
145
+ f1 -= f2;
146
+ return f1;
147
+ }
148
+ /**
149
+ * @brief operator-=
150
+ *
151
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
152
+ */
153
+ template <typename Integer_type, class = isInteger<Integer_type> >
154
+ friend void operator-=(Multi_field_element_with_small_characteristics& f, const Integer_type& v) {
155
+ f.element_ = _subtract(f.element_, _get_value(v));
156
+ }
157
+ /**
158
+ * @brief operator-
159
+ *
160
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
161
+ */
162
+ template <typename Integer_type, class = isInteger<Integer_type> >
163
+ friend Multi_field_element_with_small_characteristics operator-(Multi_field_element_with_small_characteristics f,
164
+ const Integer_type& v) {
165
+ f -= v;
166
+ return f;
167
+ }
168
+ /**
169
+ * @brief operator-
170
+ *
171
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
172
+ */
173
+ template <typename Integer_type, class = isInteger<Integer_type> >
174
+ friend Integer_type operator-(const Integer_type& v, const Multi_field_element_with_small_characteristics& f) {
175
+ return _subtract(_get_value(v), f.element_);
176
+ }
177
+
178
+ /**
179
+ * @brief operator*=
180
+ */
181
+ friend void operator*=(Multi_field_element_with_small_characteristics& f1,
182
+ Multi_field_element_with_small_characteristics const& f2) {
183
+ f1.element_ = _multiply(f1.element_, f2.element_);
184
+ }
185
+ /**
186
+ * @brief operator*
187
+ */
188
+ friend Multi_field_element_with_small_characteristics operator*(
189
+ Multi_field_element_with_small_characteristics f1, Multi_field_element_with_small_characteristics const& f2) {
190
+ f1 *= f2;
191
+ return f1;
192
+ }
193
+ /**
194
+ * @brief operator*=
195
+ *
196
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
197
+ */
198
+ template <typename Integer_type, class = isInteger<Integer_type> >
199
+ friend void operator*=(Multi_field_element_with_small_characteristics& f, const Integer_type& v) {
200
+ f.element_ = _multiply(f.element_, _get_value(v));
201
+ }
202
+ /**
203
+ * @brief operator*
204
+ *
205
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
206
+ */
207
+ template <typename Integer_type, class = isInteger<Integer_type> >
208
+ friend Multi_field_element_with_small_characteristics operator*(Multi_field_element_with_small_characteristics f,
209
+ const Integer_type& v) {
210
+ f *= v;
211
+ return f;
212
+ }
213
+ /**
214
+ * @brief operator*
215
+ *
216
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
217
+ */
218
+ template <typename Integer_type, class = isInteger<Integer_type> >
219
+ friend Integer_type operator*(const Integer_type& v, Multi_field_element_with_small_characteristics f) {
220
+ f *= v;
221
+ return f.element_;
222
+ }
223
+
224
+ /**
225
+ * @brief operator==
226
+ */
227
+ friend bool operator==(const Multi_field_element_with_small_characteristics& f1,
228
+ const Multi_field_element_with_small_characteristics& f2) {
229
+ return f1.element_ == f2.element_;
230
+ }
231
+ /**
232
+ * @brief operator==
233
+ *
234
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
235
+ */
236
+ template <typename Integer_type, class = isInteger<Integer_type> >
237
+ friend bool operator==(const Integer_type v, const Multi_field_element_with_small_characteristics& f) {
238
+ return _get_value(v) == f.element_;
239
+ }
240
+ /**
241
+ * @brief operator==
242
+ *
243
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
244
+ */
245
+ template <typename Integer_type, class = isInteger<Integer_type> >
246
+ friend bool operator==(const Multi_field_element_with_small_characteristics& f, const Integer_type v) {
247
+ return _get_value(v) == f.element_;
248
+ }
249
+ /**
250
+ * @brief operator!=
251
+ */
252
+ friend bool operator!=(const Multi_field_element_with_small_characteristics& f1,
253
+ const Multi_field_element_with_small_characteristics& f2) {
254
+ return !(f1 == f2);
255
+ }
256
+ /**
257
+ * @brief operator!=
258
+ *
259
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
260
+ */
261
+ template <typename Integer_type, class = isInteger<Integer_type> >
262
+ friend bool operator!=(const Integer_type v, const Multi_field_element_with_small_characteristics& f) {
263
+ return !(v == f);
264
+ }
265
+ /**
266
+ * @brief operator!=
267
+ *
268
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
269
+ */
270
+ template <typename Integer_type, class = isInteger<Integer_type> >
271
+ friend bool operator!=(const Multi_field_element_with_small_characteristics& f, const Integer_type v) {
272
+ return !(v == f);
273
+ }
274
+
275
+ /**
276
+ * @brief Assign operator.
277
+ */
278
+ Multi_field_element_with_small_characteristics& operator=(Multi_field_element_with_small_characteristics other) {
279
+ std::swap(element_, other.element_);
280
+ return *this;
281
+ }
282
+ /**
283
+ * @brief Assign operator.
284
+ *
285
+ * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
286
+ */
287
+ template <typename Integer_type, class = isInteger<Integer_type> >
288
+ Multi_field_element_with_small_characteristics& operator=(const Integer_type& value) {
289
+ element_ = _get_value(value);
290
+ return *this;
291
+ }
292
+ /**
293
+ * @brief Swap operator.
294
+ */
295
+ friend void swap(Multi_field_element_with_small_characteristics& f1,
296
+ Multi_field_element_with_small_characteristics& f2) {
297
+ std::swap(f1.element_, f2.element_);
298
+ }
299
+
300
+ /**
301
+ * @brief Casts the element into an unsigned int.
302
+ */
303
+ operator unsigned int() const { return element_; }
304
+
305
+ /**
306
+ * @brief Returns the inverse of the element in the multi-field, see @cite boissonnat:hal-00922572.
307
+ *
308
+ * @return The inverse.
309
+ */
310
+ Multi_field_element_with_small_characteristics get_inverse() const {
311
+ return get_partial_inverse(productOfAllCharacteristics_).first;
312
+ }
313
+ /**
314
+ * @brief Returns the inverse of the element with respect to a sub-product of the characteristics in the multi-field,
315
+ * see @cite boissonnat:hal-00922572.
316
+ *
317
+ * @param productOfCharacteristics Sub-product of the characteristics.
318
+ * @return Pair of the inverse and the characteristic the inverse corresponds to.
319
+ */
320
+ std::pair<Multi_field_element_with_small_characteristics,Characteristic> get_partial_inverse(
321
+ Characteristic productOfCharacteristics) const {
322
+ Characteristic gcd = std::gcd(element_, productOfAllCharacteristics_);
323
+
324
+ if (gcd == productOfCharacteristics)
325
+ return {Multi_field_element_with_small_characteristics(), multiplicativeID_}; // partial inverse is 0
326
+
327
+ Characteristic QT = productOfCharacteristics / gcd;
328
+
329
+ const Element inv_qt = _get_inverse(element_, QT);
330
+
331
+ auto res = get_partial_multiplicative_identity(QT);
332
+ res *= inv_qt;
333
+
334
+ return {res, QT};
335
+ }
336
+
337
+ /**
338
+ * @brief Returns the additive identity of a field.
339
+ *
340
+ * @return The additive identity of a field.
341
+ */
342
+ static Multi_field_element_with_small_characteristics get_additive_identity() {
343
+ return Multi_field_element_with_small_characteristics<minimum, maximum>();
344
+ }
345
+ /**
346
+ * @brief Returns the multiplicative identity of a field.
347
+ *
348
+ * @return The multiplicative identity of a field.
349
+ */
350
+ static Multi_field_element_with_small_characteristics get_multiplicative_identity() {
351
+ return Multi_field_element_with_small_characteristics<minimum, maximum>(multiplicativeID_);
352
+ }
353
+ /**
354
+ * @brief Returns the partial multiplicative identity of the multi-field from the given product.
355
+ * See @cite boissonnat:hal-00922572 for more details.
356
+ *
357
+ * @param productOfCharacteristics Product of the different characteristics to take into account in the multi-field.
358
+ * @return The partial multiplicative identity of the multi-field.
359
+ */
360
+ static Multi_field_element_with_small_characteristics get_partial_multiplicative_identity(
361
+ const Characteristic& productOfCharacteristics) {
362
+ if (productOfCharacteristics == 0) {
363
+ return Multi_field_element_with_small_characteristics<minimum, maximum>(multiplicativeID_);
364
+ }
365
+ Multi_field_element_with_small_characteristics<minimum, maximum> mult;
366
+ for (Characteristic idx = 0; idx < primes_.size(); ++idx) {
367
+ if ((productOfCharacteristics % primes_[idx]) == 0) {
368
+ mult += partials_[idx];
369
+ }
370
+ }
371
+ return mult;
372
+ }
373
+ /**
374
+ * @brief Returns the product of all characteristics.
375
+ *
376
+ * @return The product of all characteristics.
377
+ */
378
+ static constexpr Characteristic get_characteristic() { return productOfAllCharacteristics_; }
379
+
380
+ /**
381
+ * @brief Returns the value of the element.
382
+ *
383
+ * @return Value of the element.
384
+ */
385
+ Element get_value() const { return element_; }
386
+
387
+ // static constexpr bool handles_only_z2() { return false; }
388
+
389
+ private:
390
+ static constexpr bool _is_prime(const unsigned int p) {
391
+ if (p <= 1) return false;
392
+ if (p <= 3) return true;
393
+ if (p % 2 == 0 || p % 3 == 0) return false;
394
+
395
+ for (unsigned long i = 5; i * i <= p; i = i + 6)
396
+ if (p % i == 0 || p % (i + 2) == 0) return false;
397
+
398
+ return true;
399
+ }
400
+ static constexpr Element _multiply(Element a, Element b) {
401
+ Element res = 0;
402
+ Element temp_b = 0;
403
+
404
+ if (b < a) std::swap(a, b);
405
+
406
+ while (a != 0) {
407
+ if (a & 1) {
408
+ /* Add b to res, modulo m, without overflow */
409
+ if (b >= productOfAllCharacteristics_ - res) res -= productOfAllCharacteristics_;
410
+ res += b;
411
+ }
412
+ a >>= 1;
413
+
414
+ /* Double b, modulo m */
415
+ temp_b = b;
416
+ if (b >= productOfAllCharacteristics_ - b) temp_b -= productOfAllCharacteristics_;
417
+ b += temp_b;
418
+ }
419
+ return res;
420
+ }
421
+ static constexpr Element _add(Element element, Element v) {
422
+ if (UINT_MAX - element < v) {
423
+ // automatic unsigned integer overflow behaviour will make it work
424
+ element += v;
425
+ element -= productOfAllCharacteristics_;
426
+ return element;
427
+ }
428
+
429
+ element += v;
430
+ if (element >= productOfAllCharacteristics_) element -= productOfAllCharacteristics_;
431
+
432
+ return element;
433
+ }
434
+ static constexpr Element _subtract(Element element, Element v) {
435
+ if (element < v) {
436
+ element += productOfAllCharacteristics_;
437
+ }
438
+ element -= v;
439
+
440
+ return element;
441
+ }
442
+ static constexpr int _get_inverse(Element element, const Element mod) {
443
+ // to solve: Ax + My = 1
444
+ int M = mod;
445
+ int A = element;
446
+ int y = 0, x = 1;
447
+ // extended euclidean division
448
+ while (A > 1) {
449
+ int quotient = A / M;
450
+ int temp = M;
451
+
452
+ M = A % M, A = temp;
453
+ temp = y;
454
+
455
+ y = x - quotient * y;
456
+ x = temp;
457
+ }
458
+
459
+ if (x < 0) x += mod;
460
+
461
+ return x;
462
+ }
463
+
464
+ template <typename Integer_type, class = isInteger<Integer_type> >
465
+ static constexpr Element _get_value(Integer_type e) {
466
+ if constexpr (std::is_signed_v<Integer_type>){
467
+ if (e < -static_cast<Integer_type>(productOfAllCharacteristics_)) e = e % productOfAllCharacteristics_;
468
+ if (e < 0) return e += productOfAllCharacteristics_;
469
+ return e < static_cast<Integer_type>(productOfAllCharacteristics_) ? e : e % productOfAllCharacteristics_;
470
+ } else {
471
+ return e < productOfAllCharacteristics_ ? e : e % productOfAllCharacteristics_;
472
+ }
473
+ }
474
+
475
+ Element element_;
476
+ static inline const std::vector<Characteristic> primes_ = []() {
477
+ std::vector<Characteristic> res;
478
+ for (Characteristic i = minimum; i <= maximum; ++i) {
479
+ if (_is_prime(i)) {
480
+ res.push_back(i);
481
+ }
482
+ }
483
+ return res;
484
+ }();
485
+ static inline constexpr Characteristic productOfAllCharacteristics_ = []() {
486
+ Characteristic res = 1;
487
+ for (Characteristic i = minimum; i <= maximum; ++i) {
488
+ if (_is_prime(i)) {
489
+ res *= i;
490
+ }
491
+ }
492
+ return res;
493
+ }();
494
+ static inline const std::vector<Characteristic> partials_ = []() {
495
+ std::vector<Characteristic> res;
496
+
497
+ if (productOfAllCharacteristics_ == 1) return res;
498
+
499
+ for (Characteristic i = 0; i < primes_.size(); ++i) {
500
+ Characteristic p = primes_[i];
501
+ Characteristic base = productOfAllCharacteristics_ / p;
502
+ Characteristic exp = p - 1;
503
+ res.push_back(1);
504
+
505
+ while (exp > 0) {
506
+ // If exp is odd, multiply with result
507
+ if (exp & 1) res.back() = _multiply(res.back(), base);
508
+ // y must be even now
509
+ exp = exp >> 1;
510
+ base = _multiply(base, base);
511
+ }
512
+ }
513
+
514
+ return res;
515
+ }();
516
+ // If I understood the paper well, multiplicativeID_ always equals to 1. But in Clement's code,
517
+ // multiplicativeID_ is computed (see commented lambda function below). TODO: verify with Clement.
518
+ static inline constexpr Element multiplicativeID_ = 1; /*= [](){
519
+ unsigned int res = 0;
520
+ for (unsigned int i = 0; i < partials_.size(); ++i){
521
+ res = (res + partials_[i]) % productOfAllCharacteristics_;
522
+ }
523
+
524
+ return res;
525
+ }();*/
526
+ };
527
+
528
+ } // namespace persistence_fields
529
+ } // namespace Gudhi
530
+
531
+ #endif // MATRIX_FIELD_MULTI_SMALL_H_