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,492 @@
|
|
|
1
|
+
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
|
|
2
|
+
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
|
|
3
|
+
* Author(s): Hannah Schreiber
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2022 Inria
|
|
6
|
+
*
|
|
7
|
+
* Modification(s):
|
|
8
|
+
* - YYYY/MM Author: Description of the modification
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file Zp_field_shared.h
|
|
13
|
+
* @author Hannah Schreiber
|
|
14
|
+
* @brief Contains the @ref Gudhi::persistence_fields::Shared_Zp_field_element class.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef MATRIX_FIELD_ZP_VAR_H_
|
|
18
|
+
#define MATRIX_FIELD_ZP_VAR_H_
|
|
19
|
+
|
|
20
|
+
#include <utility>
|
|
21
|
+
#include <vector>
|
|
22
|
+
#include <climits>
|
|
23
|
+
#include <stdexcept>
|
|
24
|
+
|
|
25
|
+
namespace Gudhi {
|
|
26
|
+
namespace persistence_fields {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @class Shared_Zp_field_element Zp_field_shared.h gudhi/Fields/Zp_field_shared.h
|
|
30
|
+
* @ingroup persistence_fields
|
|
31
|
+
*
|
|
32
|
+
* @brief Class representing an element of the \f$ \mathbb{F}_p \f$ field for any prime number \f$ p \f$.
|
|
33
|
+
* If each instantiation of the class can represent another element, they all share the same characteristics.
|
|
34
|
+
* That is if the characteristics are set for one, they will be set for all the others. The characteristics can
|
|
35
|
+
* be set before instantiating the elements with the static @ref Shared_Zp_field_element::initialize method.
|
|
36
|
+
*
|
|
37
|
+
* @tparam Unsigned_integer_type A native unsigned integer type: unsigned int, long unsigned int, etc.
|
|
38
|
+
* Will be used as the field element type.
|
|
39
|
+
*/
|
|
40
|
+
template <typename Unsigned_integer_type = unsigned int,
|
|
41
|
+
class = std::enable_if_t<std::is_unsigned_v<Unsigned_integer_type> > >
|
|
42
|
+
class Shared_Zp_field_element
|
|
43
|
+
{
|
|
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
|
+
Shared_Zp_field_element() : element_(0) {}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @brief Constructor setting the element to the given value.
|
|
57
|
+
*
|
|
58
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
59
|
+
* @param element Value of the element.
|
|
60
|
+
*/
|
|
61
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
62
|
+
Shared_Zp_field_element(Integer_type element) : element_(_get_value(element))
|
|
63
|
+
{}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @brief Copy constructor.
|
|
67
|
+
*
|
|
68
|
+
* @param toCopy Element to copy.
|
|
69
|
+
*/
|
|
70
|
+
Shared_Zp_field_element(const Shared_Zp_field_element& toCopy) = default;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @brief Move constructor.
|
|
74
|
+
*
|
|
75
|
+
* @param toMove Element to move.
|
|
76
|
+
*/
|
|
77
|
+
Shared_Zp_field_element(Shared_Zp_field_element&& toMove) noexcept : element_(std::exchange(toMove.element_, 0)) {}
|
|
78
|
+
|
|
79
|
+
~Shared_Zp_field_element() = default;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @brief Initialize the field to the given characteristic.
|
|
83
|
+
* Should be called first before constructing the field elements.
|
|
84
|
+
*
|
|
85
|
+
* @param characteristic Characteristic of the field. A positive prime number.
|
|
86
|
+
*/
|
|
87
|
+
static void initialize(Characteristic characteristic)
|
|
88
|
+
{
|
|
89
|
+
if (characteristic <= 1)
|
|
90
|
+
throw std::invalid_argument("Characteristic must be strictly positive and a prime number.");
|
|
91
|
+
|
|
92
|
+
inverse_.resize(characteristic);
|
|
93
|
+
inverse_[0] = 0;
|
|
94
|
+
for (Element i = 1; i < characteristic; ++i) {
|
|
95
|
+
Element inv = 1;
|
|
96
|
+
Element mult = inv * i;
|
|
97
|
+
while ((mult % characteristic) != 1) {
|
|
98
|
+
++inv;
|
|
99
|
+
if (mult == characteristic) throw std::invalid_argument("Characteristic must be a prime number.");
|
|
100
|
+
mult = inv * i;
|
|
101
|
+
}
|
|
102
|
+
inverse_[i] = inv;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
characteristic_ = characteristic;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @brief Returns the value of the element.
|
|
110
|
+
*
|
|
111
|
+
* @return Value of the element.
|
|
112
|
+
*/
|
|
113
|
+
Element get_value() const { return element_; }
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @brief operator+=
|
|
117
|
+
*/
|
|
118
|
+
friend void operator+=(Shared_Zp_field_element& f1, const Shared_Zp_field_element& f2)
|
|
119
|
+
{
|
|
120
|
+
f1.element_ = Shared_Zp_field_element::_add(f1.element_, f2.element_);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @brief operator+
|
|
125
|
+
*/
|
|
126
|
+
friend Shared_Zp_field_element operator+(Shared_Zp_field_element f1, const Shared_Zp_field_element& f2)
|
|
127
|
+
{
|
|
128
|
+
f1 += f2;
|
|
129
|
+
return f1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @brief operator+=
|
|
134
|
+
*
|
|
135
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
136
|
+
*/
|
|
137
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
138
|
+
friend void operator+=(Shared_Zp_field_element& f, const Integer_type& v)
|
|
139
|
+
{
|
|
140
|
+
f.element_ = Shared_Zp_field_element::_add(f.element_, _get_value(v));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @brief operator+
|
|
145
|
+
*
|
|
146
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
147
|
+
*/
|
|
148
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
149
|
+
friend Shared_Zp_field_element operator+(Shared_Zp_field_element f, const Integer_type& v)
|
|
150
|
+
{
|
|
151
|
+
f += v;
|
|
152
|
+
return f;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @brief operator+
|
|
157
|
+
*
|
|
158
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
159
|
+
*/
|
|
160
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
161
|
+
friend Integer_type operator+(const Integer_type& v, Shared_Zp_field_element f)
|
|
162
|
+
{
|
|
163
|
+
f += v;
|
|
164
|
+
return f.element_;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @brief operator-=
|
|
169
|
+
*/
|
|
170
|
+
friend void operator-=(Shared_Zp_field_element& f1, const Shared_Zp_field_element& f2)
|
|
171
|
+
{
|
|
172
|
+
f1.element_ = Shared_Zp_field_element::_subtract(f1.element_, f2.element_);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @brief operator-
|
|
177
|
+
*/
|
|
178
|
+
friend Shared_Zp_field_element operator-(Shared_Zp_field_element f1, const Shared_Zp_field_element& f2)
|
|
179
|
+
{
|
|
180
|
+
f1 -= f2;
|
|
181
|
+
return f1;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @brief operator-=
|
|
186
|
+
*
|
|
187
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
188
|
+
*/
|
|
189
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
190
|
+
friend void operator-=(Shared_Zp_field_element& f, const Integer_type& v)
|
|
191
|
+
{
|
|
192
|
+
f.element_ = Shared_Zp_field_element::_subtract(f.element_, _get_value(v));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @brief operator-
|
|
197
|
+
*
|
|
198
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
199
|
+
*/
|
|
200
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
201
|
+
friend Shared_Zp_field_element operator-(Shared_Zp_field_element f, const Integer_type& v)
|
|
202
|
+
{
|
|
203
|
+
f -= v;
|
|
204
|
+
return f;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @brief operator-
|
|
209
|
+
*
|
|
210
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
211
|
+
*/
|
|
212
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
213
|
+
friend Integer_type operator-(const Integer_type& v, const Shared_Zp_field_element& f)
|
|
214
|
+
{
|
|
215
|
+
return Shared_Zp_field_element::_subtract(_get_value(v), f.element_);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @brief operator*=
|
|
220
|
+
*/
|
|
221
|
+
friend void operator*=(Shared_Zp_field_element& f1, const Shared_Zp_field_element& f2)
|
|
222
|
+
{
|
|
223
|
+
f1.element_ = Shared_Zp_field_element::_multiply(f1.element_, f2.element_);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @brief operator*
|
|
228
|
+
*/
|
|
229
|
+
friend Shared_Zp_field_element operator*(Shared_Zp_field_element f1, const Shared_Zp_field_element& f2)
|
|
230
|
+
{
|
|
231
|
+
f1 *= f2;
|
|
232
|
+
return f1;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @brief operator*=
|
|
237
|
+
*
|
|
238
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
239
|
+
*/
|
|
240
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
241
|
+
friend void operator*=(Shared_Zp_field_element& f, const Integer_type& v)
|
|
242
|
+
{
|
|
243
|
+
f.element_ = Shared_Zp_field_element::_multiply(f.element_, _get_value(v));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @brief operator*
|
|
248
|
+
*
|
|
249
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
250
|
+
*/
|
|
251
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
252
|
+
friend Shared_Zp_field_element operator*(Shared_Zp_field_element f, const Integer_type& v)
|
|
253
|
+
{
|
|
254
|
+
f *= v;
|
|
255
|
+
return f;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @brief operator*
|
|
260
|
+
*
|
|
261
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic. if signed.
|
|
262
|
+
*/
|
|
263
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
264
|
+
friend Integer_type operator*(const Integer_type& v, Shared_Zp_field_element f)
|
|
265
|
+
{
|
|
266
|
+
f *= v;
|
|
267
|
+
return f.element_;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @brief operator==
|
|
272
|
+
*/
|
|
273
|
+
friend bool operator==(const Shared_Zp_field_element& f1, const Shared_Zp_field_element& f2)
|
|
274
|
+
{
|
|
275
|
+
return f1.element_ == f2.element_;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @brief operator==
|
|
280
|
+
*
|
|
281
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
282
|
+
*/
|
|
283
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
284
|
+
friend bool operator==(const Integer_type& v, const Shared_Zp_field_element& f)
|
|
285
|
+
{
|
|
286
|
+
return Shared_Zp_field_element::_get_value(v) == f.element_;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @brief operator==
|
|
291
|
+
*
|
|
292
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
293
|
+
*/
|
|
294
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
295
|
+
friend bool operator==(const Shared_Zp_field_element& f, const Integer_type& v)
|
|
296
|
+
{
|
|
297
|
+
return Shared_Zp_field_element::_get_value(v) == f.element_;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* @brief operator!=
|
|
302
|
+
*/
|
|
303
|
+
friend bool operator!=(const Shared_Zp_field_element& f1, const Shared_Zp_field_element& f2) { return !(f1 == f2); }
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* @brief operator!=
|
|
307
|
+
*
|
|
308
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
309
|
+
*/
|
|
310
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
311
|
+
friend bool operator!=(const Integer_type& v, const Shared_Zp_field_element& f)
|
|
312
|
+
{
|
|
313
|
+
return !(v == f);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @brief operator!=
|
|
318
|
+
*
|
|
319
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
320
|
+
*/
|
|
321
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
322
|
+
friend bool operator!=(const Shared_Zp_field_element& f, const Integer_type& v)
|
|
323
|
+
{
|
|
324
|
+
return !(v == f);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @brief Assign operator.
|
|
329
|
+
*/
|
|
330
|
+
Shared_Zp_field_element& operator=(Shared_Zp_field_element other)
|
|
331
|
+
{
|
|
332
|
+
std::swap(element_, other.element_);
|
|
333
|
+
return *this;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @brief Move assign operator.
|
|
338
|
+
*/
|
|
339
|
+
Shared_Zp_field_element& operator=(Shared_Zp_field_element&& other) noexcept
|
|
340
|
+
{
|
|
341
|
+
if (this == &other) return *this;
|
|
342
|
+
|
|
343
|
+
element_ = std::exchange(other.element_, 0);
|
|
344
|
+
return *this;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* @brief Assign operator.
|
|
349
|
+
*
|
|
350
|
+
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
|
|
351
|
+
*/
|
|
352
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
353
|
+
Shared_Zp_field_element& operator=(const Integer_type& value)
|
|
354
|
+
{
|
|
355
|
+
element_ = Shared_Zp_field_element::_get_value(value);
|
|
356
|
+
return *this;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* @brief Swap operator.
|
|
361
|
+
*/
|
|
362
|
+
friend void swap(Shared_Zp_field_element& f1, Shared_Zp_field_element& f2) noexcept
|
|
363
|
+
{
|
|
364
|
+
std::swap(f1.element_, f2.element_);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @brief Casts the element into an unsigned int.
|
|
369
|
+
*/
|
|
370
|
+
operator unsigned int() const { return element_; }
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* @brief Returns the inverse of the element in the field.
|
|
374
|
+
*
|
|
375
|
+
* @return The inverse.
|
|
376
|
+
*/
|
|
377
|
+
Shared_Zp_field_element get_inverse() const { return Shared_Zp_field_element(inverse_[element_]); }
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* @brief For interface purposes with multi-fields. Returns the inverse together with the argument.
|
|
381
|
+
*
|
|
382
|
+
* @param productOfCharacteristics Some value.
|
|
383
|
+
* @return Pair whose first element is the inverse and the second element is @p productOfCharacteristics.
|
|
384
|
+
*/
|
|
385
|
+
std::pair<Shared_Zp_field_element, Characteristic> get_partial_inverse(Characteristic productOfCharacteristics) const
|
|
386
|
+
{
|
|
387
|
+
return {get_inverse(), productOfCharacteristics};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* @brief Returns the additive identity of the field.
|
|
392
|
+
*
|
|
393
|
+
* @return 0.
|
|
394
|
+
*/
|
|
395
|
+
static Shared_Zp_field_element get_additive_identity() { return Shared_Zp_field_element(); }
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* @brief Returns the multiplicative identity of the field.
|
|
399
|
+
*
|
|
400
|
+
* @return 1.
|
|
401
|
+
*/
|
|
402
|
+
static Shared_Zp_field_element get_multiplicative_identity() { return Shared_Zp_field_element(1); }
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* @brief For interface purposes with multi-fields. Returns the multiplicative identity of the field.
|
|
406
|
+
*
|
|
407
|
+
* @param productOfCharacteristics Some value.
|
|
408
|
+
* @return 1.
|
|
409
|
+
*/
|
|
410
|
+
static Shared_Zp_field_element get_partial_multiplicative_identity(
|
|
411
|
+
[[maybe_unused]] Characteristic productOfCharacteristics)
|
|
412
|
+
{
|
|
413
|
+
return Shared_Zp_field_element(1);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* @brief Returns the current characteristic.
|
|
418
|
+
*
|
|
419
|
+
* @return The value of the current characteristic.
|
|
420
|
+
*/
|
|
421
|
+
static Characteristic get_characteristic() { return characteristic_; }
|
|
422
|
+
|
|
423
|
+
// static constexpr bool handles_only_z2() { return false; }
|
|
424
|
+
|
|
425
|
+
private:
|
|
426
|
+
Element element_; /**< Field element. */
|
|
427
|
+
static inline Characteristic characteristic_; /**< Current characteristic of the field. */
|
|
428
|
+
static inline std::vector<Element> inverse_; /**< All inverse elements. */
|
|
429
|
+
|
|
430
|
+
static Element _add(Element element, Element v)
|
|
431
|
+
{
|
|
432
|
+
if (UINT_MAX - element < v) {
|
|
433
|
+
// automatic unsigned integer overflow behaviour will make it work
|
|
434
|
+
element += v;
|
|
435
|
+
element -= characteristic_;
|
|
436
|
+
return element;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
element += v;
|
|
440
|
+
if (element >= characteristic_) element -= characteristic_;
|
|
441
|
+
|
|
442
|
+
return element;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
static Element _subtract(Element element, Element v)
|
|
446
|
+
{
|
|
447
|
+
if (element < v) {
|
|
448
|
+
element += characteristic_;
|
|
449
|
+
}
|
|
450
|
+
element -= v;
|
|
451
|
+
|
|
452
|
+
return element;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
static Element _multiply(Element element, Element v)
|
|
456
|
+
{
|
|
457
|
+
Element a = element;
|
|
458
|
+
element = 0;
|
|
459
|
+
Element temp_b;
|
|
460
|
+
|
|
461
|
+
while (a != 0) {
|
|
462
|
+
if (a & 1) {
|
|
463
|
+
if (v >= characteristic_ - element) element -= characteristic_;
|
|
464
|
+
element += v;
|
|
465
|
+
}
|
|
466
|
+
a >>= 1;
|
|
467
|
+
|
|
468
|
+
temp_b = v;
|
|
469
|
+
if (v >= characteristic_ - v) temp_b -= characteristic_;
|
|
470
|
+
v += temp_b;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return element;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
template <typename Integer_type, class = isInteger<Integer_type> >
|
|
477
|
+
static constexpr Element _get_value(Integer_type e)
|
|
478
|
+
{
|
|
479
|
+
if constexpr (std::is_signed_v<Integer_type>) {
|
|
480
|
+
if (e < -static_cast<Integer_type>(characteristic_)) e = e % characteristic_;
|
|
481
|
+
if (e < 0) return e += characteristic_;
|
|
482
|
+
return e < static_cast<Integer_type>(characteristic_) ? e : e % characteristic_;
|
|
483
|
+
} else {
|
|
484
|
+
return e < characteristic_ ? e : e % characteristic_;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
} // namespace persistence_fields
|
|
490
|
+
} // namespace Gudhi
|
|
491
|
+
|
|
492
|
+
#endif // MATRIX_FIELD_ZP_VAR_H_
|