multipers 2.3.3b6__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.

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-312-darwin.so +0 -0
  26. multipers/function_rips.pyx +105 -0
  27. multipers/grids.cpython-312-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-312-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-312-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-312-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-312-darwin.so +0 -0
  162. multipers/point_measure.pyx +395 -0
  163. multipers/simplex_tree_multi.cpython-312-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-312-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,1012 @@
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-24 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+ /**
12
+ * @file unordered_set_column.h
13
+ * @author Hannah Schreiber
14
+ * @brief Contains the @ref Gudhi::persistence_matrix::Unordered_set_column class.
15
+ * Also defines the std::hash method for @ref Gudhi::persistence_matrix::Unordered_set_column.
16
+ */
17
+
18
+ #ifndef PM_UNORDERED_SET_COLUMN_H
19
+ #define PM_UNORDERED_SET_COLUMN_H
20
+
21
+ #include <vector>
22
+ #include <stdexcept>
23
+ #include <type_traits>
24
+ #include <set>
25
+ #include <utility> //std::swap, std::move & std::exchange
26
+
27
+ #include <boost/iterator/indirect_iterator.hpp>
28
+ #if BOOST_VERSION >= 108100
29
+ #include <boost/unordered/unordered_flat_set.hpp>
30
+ #else
31
+ #include <unordered_set>
32
+ #endif
33
+
34
+ #include <gudhi/Persistence_matrix/allocators/entry_constructors.h>
35
+
36
+ namespace Gudhi {
37
+ namespace persistence_matrix {
38
+
39
+ // For unordered_set container. Outside of Unordered_set_column because of a msvc bug who can't compile properly
40
+ // unordered_flat_set if the hash method is nested.
41
+ template <class Entry>
42
+ struct EntryPointerHash
43
+ {
44
+ size_t operator()(const Entry* c) const { return std::hash<Entry>()(*c); }
45
+ };
46
+ template <class Entry>
47
+ struct EntryPointerEq
48
+ {
49
+ bool operator()(const Entry* c1, const Entry* c2) const { return *c1 == *c2; }
50
+ };
51
+
52
+ /**
53
+ * @class Unordered_set_column unordered_set_column.h gudhi/Persistence_matrix/columns/unordered_set_column.h
54
+ * @ingroup persistence_matrix
55
+ *
56
+ * @brief Column class following the @ref PersistenceMatrixColumn concept.
57
+ *
58
+ * Column based on an unordered set structure. The entries are not ordered, but only non-zero values
59
+ * are stored uniquely in the underlying container. When adding an entry range into it, the given entry range
60
+ * also does not need to be ordered (contrary to most other column types).
61
+ *
62
+ * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced.
63
+ * @tparam Entry_constructor Factory of @ref Entry classes.
64
+ */
65
+ template <class Master_matrix>
66
+ class Unordered_set_column : public Master_matrix::Row_access_option,
67
+ public Master_matrix::Column_dimension_option,
68
+ public Master_matrix::Chain_column_option
69
+ {
70
+ public:
71
+ using Master = Master_matrix;
72
+ using Index = typename Master_matrix::Index;
73
+ using ID_index = typename Master_matrix::ID_index;
74
+ using Dimension = typename Master_matrix::Dimension;
75
+ using Field_element = typename Master_matrix::Element;
76
+ using Entry = typename Master_matrix::Matrix_entry;
77
+ using Column_settings = typename Master_matrix::Column_settings;
78
+
79
+ private:
80
+ using Field_operators = typename Master_matrix::Field_operators;
81
+ using Entry_constructor = typename Master_matrix::Entry_constructor;
82
+
83
+ struct EntryPointerComp {
84
+ bool operator()(const Entry* c1, const Entry* c2) const { return *c1 < *c2; }
85
+ };
86
+
87
+ #if BOOST_VERSION >= 108100
88
+ using Column_support = boost::unordered_flat_set<Entry*, EntryPointerHash<Entry>, EntryPointerEq<Entry>>;
89
+ #else
90
+ using Column_support = std::unordered_set<Entry*, EntryPointerHash<Entry>, EntryPointerEq<Entry>>;
91
+ #endif
92
+
93
+ public:
94
+ using iterator = boost::indirect_iterator<typename Column_support::iterator>;
95
+ using const_iterator = boost::indirect_iterator<typename Column_support::const_iterator>;
96
+
97
+ Unordered_set_column(Column_settings* colSettings = nullptr);
98
+ template <class Container = typename Master_matrix::Boundary>
99
+ Unordered_set_column(const Container& nonZeroRowIndices, Column_settings* colSettings);
100
+ template <class Container = typename Master_matrix::Boundary, class Row_container>
101
+ Unordered_set_column(Index columnIndex,
102
+ const Container& nonZeroRowIndices,
103
+ Row_container* rowContainer,
104
+ Column_settings* colSettings);
105
+ template <class Container = typename Master_matrix::Boundary>
106
+ Unordered_set_column(const Container& nonZeroChainRowIndices, Dimension dimension, Column_settings* colSettings);
107
+ template <class Container = typename Master_matrix::Boundary, class Row_container>
108
+ Unordered_set_column(Index columnIndex,
109
+ const Container& nonZeroChainRowIndices,
110
+ Dimension dimension,
111
+ Row_container* rowContainer,
112
+ Column_settings* colSettings);
113
+ Unordered_set_column(const Unordered_set_column& column, Column_settings* colSettings = nullptr);
114
+ template <class Row_container>
115
+ Unordered_set_column(const Unordered_set_column& column,
116
+ Index columnIndex,
117
+ Row_container* rowContainer,
118
+ Column_settings* colSettings = nullptr);
119
+ Unordered_set_column(Unordered_set_column&& column) noexcept;
120
+ ~Unordered_set_column();
121
+
122
+ std::vector<Field_element> get_content(int columnLength = -1) const;
123
+ bool is_non_zero(ID_index rowIndex) const;
124
+ bool is_empty() const;
125
+ std::size_t size() const;
126
+
127
+ template <class Row_index_map>
128
+ void reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex = -1);
129
+ void clear();
130
+ void clear(ID_index rowIndex);
131
+
132
+ ID_index get_pivot() const;
133
+ Field_element get_pivot_value() const;
134
+
135
+ iterator begin() noexcept;
136
+ const_iterator begin() const noexcept;
137
+ iterator end() noexcept;
138
+ const_iterator end() const noexcept;
139
+
140
+ template <class Entry_range>
141
+ Unordered_set_column& operator+=(const Entry_range& column);
142
+ Unordered_set_column& operator+=(Unordered_set_column& column);
143
+
144
+ Unordered_set_column& operator*=(unsigned int v);
145
+
146
+ // this = v * this + column
147
+ template <class Entry_range>
148
+ Unordered_set_column& multiply_target_and_add(const Field_element& val, const Entry_range& column);
149
+ Unordered_set_column& multiply_target_and_add(const Field_element& val, Unordered_set_column& column);
150
+ // this = this + column * v
151
+ template <class Entry_range>
152
+ Unordered_set_column& multiply_source_and_add(const Entry_range& column, const Field_element& val);
153
+ Unordered_set_column& multiply_source_and_add(Unordered_set_column& column, const Field_element& val);
154
+
155
+ void push_back(const Entry& entry);
156
+
157
+ friend bool operator==(const Unordered_set_column& c1, const Unordered_set_column& c2) {
158
+ if (&c1 == &c2) return true;
159
+ if (c1.column_.size() != c2.column_.size()) return false;
160
+
161
+ for (Entry* entry : c1.column_) {
162
+ auto it = c2.column_.find(entry);
163
+ if (it == c2.column_.end()) return false;
164
+ if constexpr (!Master_matrix::Option_list::is_z2)
165
+ if ((*it)->get_element() != entry->get_element()) return false;
166
+ }
167
+ return true;
168
+ }
169
+ friend bool operator<(const Unordered_set_column& c1, const Unordered_set_column& c2) {
170
+ if (&c1 == &c2) return false;
171
+
172
+ using ID_index = Unordered_set_column<Master_matrix>::ID_index;
173
+ using Entry_rep =
174
+ typename std::conditional<Master_matrix::Option_list::is_z2,
175
+ ID_index,
176
+ std::pair<ID_index, unsigned int>
177
+ >::type;
178
+
179
+ auto it1 = c1.column_.begin();
180
+ auto it2 = c2.column_.begin();
181
+ std::set<Entry_rep> entries1, entries2;
182
+ while (it1 != c1.column_.end() && it2 != c2.column_.end()) {
183
+ if constexpr (Master_matrix::Option_list::is_z2) {
184
+ entries1.insert((*it1)->get_row_index());
185
+ entries2.insert((*it2)->get_row_index());
186
+ } else {
187
+ entries1.emplace((*it1)->get_row_index(), (*it1)->get_element());
188
+ entries2.emplace((*it2)->get_row_index(), (*it2)->get_element());
189
+ }
190
+ ++it1;
191
+ ++it2;
192
+ }
193
+ while (it1 != c1.column_.end()) {
194
+ if constexpr (Master_matrix::Option_list::is_z2) {
195
+ entries1.insert((*it1)->get_row_index());
196
+ } else {
197
+ entries1.emplace((*it1)->get_row_index(), (*it1)->get_element());
198
+ }
199
+ ++it1;
200
+ }
201
+ while (it2 != c2.column_.end()) {
202
+ if constexpr (Master_matrix::Option_list::is_z2) {
203
+ entries2.insert((*it2)->get_row_index());
204
+ } else {
205
+ entries2.emplace((*it2)->get_row_index(), (*it2)->get_element());
206
+ }
207
+ ++it2;
208
+ }
209
+ return entries1 < entries2;
210
+ }
211
+
212
+ // Disabled with row access.
213
+ Unordered_set_column& operator=(const Unordered_set_column& other);
214
+
215
+ friend void swap(Unordered_set_column& col1, Unordered_set_column& col2) {
216
+ swap(static_cast<typename Master_matrix::Row_access_option&>(col1),
217
+ static_cast<typename Master_matrix::Row_access_option&>(col2));
218
+ swap(static_cast<typename Master_matrix::Column_dimension_option&>(col1),
219
+ static_cast<typename Master_matrix::Column_dimension_option&>(col2));
220
+ swap(static_cast<typename Master_matrix::Chain_column_option&>(col1),
221
+ static_cast<typename Master_matrix::Chain_column_option&>(col2));
222
+ col1.column_.swap(col2.column_);
223
+ std::swap(col1.operators_, col2.operators_);
224
+ std::swap(col1.entryPool_, col2.entryPool_);
225
+ }
226
+
227
+ private:
228
+ using RA_opt = typename Master_matrix::Row_access_option;
229
+ using Dim_opt = typename Master_matrix::Column_dimension_option;
230
+ using Chain_opt = typename Master_matrix::Chain_column_option;
231
+
232
+ Column_support column_;
233
+ Field_operators* operators_;
234
+ Entry_constructor* entryPool_;
235
+
236
+ void _delete_entry(typename Column_support::iterator& it);
237
+ Entry* _insert_entry(const Field_element& value, ID_index rowIndex);
238
+ void _insert_entry(ID_index rowIndex);
239
+ template <class Entry_range>
240
+ bool _add(const Entry_range& column);
241
+ template <class Entry_range>
242
+ bool _multiply_target_and_add(const Field_element& val, const Entry_range& column);
243
+ template <class Entry_range>
244
+ bool _multiply_source_and_add(const Entry_range& column, const Field_element& val);
245
+ template <class Entry_range, typename F1, typename F2>
246
+ bool _generic_add(const Entry_range& source, F1&& process_source, F2&& update_target);
247
+ };
248
+
249
+ template <class Master_matrix>
250
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Column_settings* colSettings)
251
+ : RA_opt(),
252
+ Dim_opt(),
253
+ Chain_opt(),
254
+ operators_(nullptr),
255
+ entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor))
256
+ {
257
+ if (operators_ == nullptr && entryPool_ == nullptr) return; // to allow default constructor which gives a dummy column
258
+ if constexpr (!Master_matrix::Option_list::is_z2) {
259
+ operators_ = &(colSettings->operators);
260
+ }
261
+ }
262
+
263
+ template <class Master_matrix>
264
+ template <class Container>
265
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(const Container& nonZeroRowIndices,
266
+ Column_settings* colSettings)
267
+ : RA_opt(),
268
+ Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1),
269
+ Chain_opt(),
270
+ column_(nonZeroRowIndices.size()),
271
+ operators_(nullptr),
272
+ entryPool_(&(colSettings->entryConstructor))
273
+ {
274
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
275
+ "Constructor not available for chain columns, please specify the dimension of the chain.");
276
+
277
+ if constexpr (Master_matrix::Option_list::is_z2) {
278
+ for (ID_index id : nonZeroRowIndices) {
279
+ _insert_entry(id);
280
+ }
281
+ } else {
282
+ operators_ = &(colSettings->operators);
283
+ for (const auto& p : nonZeroRowIndices) {
284
+ _insert_entry(operators_->get_value(p.second), p.first);
285
+ }
286
+ }
287
+ }
288
+
289
+ template <class Master_matrix>
290
+ template <class Container, class Row_container>
291
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Index columnIndex,
292
+ const Container& nonZeroRowIndices,
293
+ Row_container* rowContainer,
294
+ Column_settings* colSettings)
295
+ : RA_opt(columnIndex, rowContainer),
296
+ Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1),
297
+ Chain_opt([&] {
298
+ if constexpr (Master_matrix::Option_list::is_z2) {
299
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
300
+ } else {
301
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
302
+ }
303
+ }()),
304
+ column_(nonZeroRowIndices.size()),
305
+ operators_(nullptr),
306
+ entryPool_(&(colSettings->entryConstructor))
307
+ {
308
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
309
+ "Constructor not available for chain columns, please specify the dimension of the chain.");
310
+
311
+ if constexpr (Master_matrix::Option_list::is_z2) {
312
+ for (ID_index id : nonZeroRowIndices) {
313
+ _insert_entry(id);
314
+ }
315
+ } else {
316
+ operators_ = &(colSettings->operators);
317
+ for (const auto& p : nonZeroRowIndices) {
318
+ _insert_entry(operators_->get_value(p.second), p.first);
319
+ }
320
+ }
321
+ }
322
+
323
+ template <class Master_matrix>
324
+ template <class Container>
325
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(const Container& nonZeroRowIndices,
326
+ Dimension dimension,
327
+ Column_settings* colSettings)
328
+ : RA_opt(),
329
+ Dim_opt(dimension),
330
+ Chain_opt([&] {
331
+ if constexpr (Master_matrix::Option_list::is_z2) {
332
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
333
+ } else {
334
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
335
+ }
336
+ }()),
337
+ column_(nonZeroRowIndices.size()),
338
+ operators_(nullptr),
339
+ entryPool_(&(colSettings->entryConstructor))
340
+ {
341
+ if constexpr (Master_matrix::Option_list::is_z2) {
342
+ for (ID_index id : nonZeroRowIndices) {
343
+ _insert_entry(id);
344
+ }
345
+ } else {
346
+ operators_ = &(colSettings->operators);
347
+ for (const auto& p : nonZeroRowIndices) {
348
+ _insert_entry(operators_->get_value(p.second), p.first);
349
+ }
350
+ }
351
+ }
352
+
353
+ template <class Master_matrix>
354
+ template <class Container, class Row_container>
355
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Index columnIndex,
356
+ const Container& nonZeroRowIndices,
357
+ Dimension dimension,
358
+ Row_container* rowContainer,
359
+ Column_settings* colSettings)
360
+ : RA_opt(columnIndex, rowContainer),
361
+ Dim_opt(dimension),
362
+ Chain_opt([&] {
363
+ if constexpr (Master_matrix::Option_list::is_z2) {
364
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
365
+ } else {
366
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
367
+ }
368
+ }()),
369
+ column_(nonZeroRowIndices.size()),
370
+ operators_(nullptr),
371
+ entryPool_(&(colSettings->entryConstructor))
372
+ {
373
+ if constexpr (Master_matrix::Option_list::is_z2) {
374
+ for (ID_index id : nonZeroRowIndices) {
375
+ _insert_entry(id);
376
+ }
377
+ } else {
378
+ operators_ = &(colSettings->operators);
379
+ for (const auto& p : nonZeroRowIndices) {
380
+ _insert_entry(operators_->get_value(p.second), p.first);
381
+ }
382
+ }
383
+ }
384
+
385
+ template <class Master_matrix>
386
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(const Unordered_set_column& column,
387
+ Column_settings* colSettings)
388
+ : RA_opt(),
389
+ Dim_opt(static_cast<const Dim_opt&>(column)),
390
+ Chain_opt(static_cast<const Chain_opt&>(column)),
391
+ column_(column.column_.bucket_count()),
392
+ operators_(colSettings == nullptr ? column.operators_ : nullptr),
393
+ entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
394
+ {
395
+ static_assert(!Master_matrix::Option_list::has_row_access,
396
+ "Simple copy constructor not available when row access option enabled. Please specify the new column "
397
+ "index and the row container.");
398
+
399
+ if constexpr (!Master_matrix::Option_list::is_z2) {
400
+ if (colSettings != nullptr) operators_ = &(colSettings->operators);
401
+ }
402
+
403
+ for (const Entry* entry : column.column_) {
404
+ if constexpr (Master_matrix::Option_list::is_z2) {
405
+ _insert_entry(entry->get_row_index());
406
+ } else {
407
+ _insert_entry(entry->get_element(), entry->get_row_index());
408
+ }
409
+ }
410
+ }
411
+
412
+ template <class Master_matrix>
413
+ template <class Row_container>
414
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(const Unordered_set_column& column,
415
+ Index columnIndex,
416
+ Row_container* rowContainer,
417
+ Column_settings* colSettings)
418
+ : RA_opt(columnIndex, rowContainer),
419
+ Dim_opt(static_cast<const Dim_opt&>(column)),
420
+ Chain_opt(static_cast<const Chain_opt&>(column)),
421
+ column_(column.column_.bucket_count()),
422
+ operators_(colSettings == nullptr ? column.operators_ : nullptr),
423
+ entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
424
+ {
425
+ if constexpr (!Master_matrix::Option_list::is_z2) {
426
+ if (colSettings != nullptr) operators_ = &(colSettings->operators);
427
+ }
428
+
429
+ for (const Entry* entry : column.column_) {
430
+ if constexpr (Master_matrix::Option_list::is_z2) {
431
+ _insert_entry(entry->get_row_index());
432
+ } else {
433
+ _insert_entry(entry->get_element(), entry->get_row_index());
434
+ }
435
+ }
436
+ }
437
+
438
+ template <class Master_matrix>
439
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Unordered_set_column&& column) noexcept
440
+ : RA_opt(std::move(static_cast<RA_opt&>(column))),
441
+ Dim_opt(std::move(static_cast<Dim_opt&>(column))),
442
+ Chain_opt(std::move(static_cast<Chain_opt&>(column))),
443
+ column_(std::move(column.column_)),
444
+ operators_(std::exchange(column.operators_, nullptr)),
445
+ entryPool_(std::exchange(column.entryPool_, nullptr))
446
+ {}
447
+
448
+ template <class Master_matrix>
449
+ inline Unordered_set_column<Master_matrix>::~Unordered_set_column()
450
+ {
451
+ for (auto* entry : column_) {
452
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
453
+ entryPool_->destroy(entry);
454
+ }
455
+ }
456
+
457
+ template <class Master_matrix>
458
+ inline std::vector<typename Unordered_set_column<Master_matrix>::Field_element>
459
+ Unordered_set_column<Master_matrix>::get_content(int columnLength) const
460
+ {
461
+ if (columnLength < 0 && column_.size() > 0)
462
+ columnLength = (*std::max_element(column_.begin(), column_.end(), EntryPointerComp()))->get_row_index() + 1;
463
+ else if (columnLength < 0)
464
+ return std::vector<Field_element>();
465
+
466
+ std::vector<Field_element> container(columnLength, 0);
467
+ for (auto it = column_.begin(); it != column_.end(); ++it) {
468
+ if ((*it)->get_row_index() < static_cast<ID_index>(columnLength)) {
469
+ if constexpr (Master_matrix::Option_list::is_z2) {
470
+ container[(*it)->get_row_index()] = 1;
471
+ } else {
472
+ container[(*it)->get_row_index()] = (*it)->get_element();
473
+ }
474
+ }
475
+ }
476
+ return container;
477
+ }
478
+
479
+ template <class Master_matrix>
480
+ inline bool Unordered_set_column<Master_matrix>::is_non_zero(ID_index rowIndex) const
481
+ {
482
+ Entry entry(rowIndex);
483
+ return column_.find(&entry) != column_.end();
484
+ }
485
+
486
+ template <class Master_matrix>
487
+ inline bool Unordered_set_column<Master_matrix>::is_empty() const
488
+ {
489
+ return column_.empty();
490
+ }
491
+
492
+ template <class Master_matrix>
493
+ inline std::size_t Unordered_set_column<Master_matrix>::size() const
494
+ {
495
+ return column_.size();
496
+ }
497
+
498
+ template <class Master_matrix>
499
+ template <class Row_index_map>
500
+ inline void Unordered_set_column<Master_matrix>::reorder(const Row_index_map& valueMap,
501
+ [[maybe_unused]] Index columnIndex)
502
+ {
503
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
504
+ "Method not available for chain columns.");
505
+
506
+ Column_support newSet;
507
+
508
+ for (Entry* entry : column_) {
509
+ if constexpr (Master_matrix::Option_list::has_row_access) {
510
+ RA_opt::unlink(entry);
511
+ if (columnIndex != static_cast<Index>(-1)) entry->set_column_index(columnIndex);
512
+ }
513
+ entry->set_row_index(valueMap.at(entry->get_row_index()));
514
+ newSet.insert(entry);
515
+ if constexpr (Master_matrix::Option_list::has_row_access &&
516
+ Master_matrix::Option_list::has_intrusive_rows) // intrusive list
517
+ RA_opt::insert_entry(entry->get_row_index(), entry);
518
+ }
519
+
520
+ // when row is a set, all entries have to be deleted first, to avoid colliding when inserting
521
+ if constexpr (Master_matrix::Option_list::has_row_access && !Master_matrix::Option_list::has_intrusive_rows) { // set
522
+ for (Entry* entry : newSet) {
523
+ RA_opt::insert_entry(entry->get_row_index(), entry);
524
+ }
525
+ }
526
+
527
+ column_.swap(newSet);
528
+ }
529
+
530
+ template <class Master_matrix>
531
+ inline void Unordered_set_column<Master_matrix>::clear()
532
+ {
533
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
534
+ "Method not available for chain columns as a base element should not be empty.");
535
+
536
+ for (auto* entry : column_) {
537
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
538
+ entryPool_->destroy(entry);
539
+ }
540
+
541
+ column_.clear();
542
+ }
543
+
544
+ template <class Master_matrix>
545
+ inline void Unordered_set_column<Master_matrix>::clear(ID_index rowIndex)
546
+ {
547
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
548
+ "Method not available for chain columns.");
549
+
550
+ auto entry = entryPool_->construct(rowIndex);
551
+ auto it = column_.find(entry);
552
+ if (it != column_.end()) {
553
+ _delete_entry(it);
554
+ }
555
+ entryPool_->destroy(entry);
556
+ }
557
+
558
+ template <class Master_matrix>
559
+ inline typename Unordered_set_column<Master_matrix>::ID_index Unordered_set_column<Master_matrix>::get_pivot() const
560
+ {
561
+ static_assert(Master_matrix::isNonBasic,
562
+ "Method not available for base columns."); // could technically be, but is the notion useful then?
563
+
564
+ if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
565
+ if (column_.empty()) return -1;
566
+ // linear search could be avoided with storing the pivot. But even then, some modifications of the column requires
567
+ // the max, so not clear how much it is worth it.
568
+ return (*std::max_element(column_.begin(), column_.end(), EntryPointerComp()))->get_row_index();
569
+ } else {
570
+ return Chain_opt::get_pivot();
571
+ }
572
+ }
573
+
574
+ template <class Master_matrix>
575
+ inline typename Unordered_set_column<Master_matrix>::Field_element
576
+ Unordered_set_column<Master_matrix>::get_pivot_value() const
577
+ {
578
+ static_assert(Master_matrix::isNonBasic,
579
+ "Method not available for base columns."); // could technically be, but is the notion useful then?
580
+
581
+ if constexpr (Master_matrix::Option_list::is_z2) {
582
+ return 1;
583
+ } else {
584
+ if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
585
+ if (column_.empty()) return 0;
586
+ return (*std::max_element(column_.begin(), column_.end(), EntryPointerComp()))->get_element();
587
+ } else {
588
+ if (Chain_opt::get_pivot() == static_cast<ID_index>(-1)) return Field_element();
589
+ for (const Entry* entry : column_) {
590
+ if (entry->get_row_index() == Chain_opt::get_pivot()) return entry->get_element();
591
+ }
592
+ return Field_element(); // should never happen if chain column is used properly
593
+ }
594
+ }
595
+ }
596
+
597
+ template <class Master_matrix>
598
+ inline typename Unordered_set_column<Master_matrix>::iterator Unordered_set_column<Master_matrix>::begin() noexcept
599
+ {
600
+ return column_.begin();
601
+ }
602
+
603
+ template <class Master_matrix>
604
+ inline typename Unordered_set_column<Master_matrix>::const_iterator Unordered_set_column<Master_matrix>::begin()
605
+ const noexcept
606
+ {
607
+ return column_.begin();
608
+ }
609
+
610
+ template <class Master_matrix>
611
+ inline typename Unordered_set_column<Master_matrix>::iterator Unordered_set_column<Master_matrix>::end() noexcept
612
+ {
613
+ return column_.end();
614
+ }
615
+
616
+ template <class Master_matrix>
617
+ inline typename Unordered_set_column<Master_matrix>::const_iterator Unordered_set_column<Master_matrix>::end()
618
+ const noexcept
619
+ {
620
+ return column_.end();
621
+ }
622
+
623
+ template <class Master_matrix>
624
+ template <class Entry_range>
625
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::operator+=(const Entry_range& column)
626
+ {
627
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Unordered_set_column>),
628
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
629
+ "base element."); // could be removed, if we give the responsibility to the user.
630
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
631
+ "For chain columns, the given column cannot be constant.");
632
+
633
+ _add(column);
634
+
635
+ return *this;
636
+ }
637
+
638
+ template <class Master_matrix>
639
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::operator+=(
640
+ Unordered_set_column& column)
641
+ {
642
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
643
+ // assumes that the addition never zeros out this column.
644
+ if (_add(column)) {
645
+ Chain_opt::swap_pivots(column);
646
+ Dim_opt::swap_dimension(column);
647
+ }
648
+ } else {
649
+ _add(column);
650
+ }
651
+
652
+ return *this;
653
+ }
654
+
655
+ template <class Master_matrix>
656
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::operator*=(unsigned int v)
657
+ {
658
+ if constexpr (Master_matrix::Option_list::is_z2) {
659
+ if (v % 2 == 0) {
660
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
661
+ throw std::invalid_argument("A chain column should not be multiplied by 0.");
662
+ } else {
663
+ clear();
664
+ }
665
+ }
666
+ } else {
667
+ Field_element val = operators_->get_value(v);
668
+
669
+ if (val == Field_operators::get_additive_identity()) {
670
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
671
+ throw std::invalid_argument("A chain column should not be multiplied by 0.");
672
+ } else {
673
+ clear();
674
+ }
675
+ return *this;
676
+ }
677
+
678
+ if (val == Field_operators::get_multiplicative_identity()) return *this;
679
+
680
+ for (Entry* entry : column_) {
681
+ operators_->multiply_inplace(entry->get_element(), val);
682
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entry);
683
+ }
684
+ }
685
+
686
+ return *this;
687
+ }
688
+
689
+ template <class Master_matrix>
690
+ template <class Entry_range>
691
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::multiply_target_and_add(
692
+ const Field_element& val, const Entry_range& column)
693
+ {
694
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Unordered_set_column>),
695
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
696
+ "base element."); // could be removed, if we give the responsibility to the user.
697
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
698
+ "For chain columns, the given column cannot be constant.");
699
+
700
+ if constexpr (Master_matrix::Option_list::is_z2) {
701
+ if (val) {
702
+ _add(column);
703
+ } else {
704
+ clear();
705
+ _add(column);
706
+ }
707
+ } else {
708
+ _multiply_target_and_add(val, column);
709
+ }
710
+
711
+ return *this;
712
+ }
713
+
714
+ template <class Master_matrix>
715
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::multiply_target_and_add(
716
+ const Field_element& val, Unordered_set_column& column)
717
+ {
718
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
719
+ // assumes that the addition never zeros out this column.
720
+ if constexpr (Master_matrix::Option_list::is_z2) {
721
+ if (val) {
722
+ if (_add(column)) {
723
+ Chain_opt::swap_pivots(column);
724
+ Dim_opt::swap_dimension(column);
725
+ }
726
+ } else {
727
+ throw std::invalid_argument("A chain column should not be multiplied by 0.");
728
+ }
729
+ } else {
730
+ if (_multiply_target_and_add(val, column)) {
731
+ Chain_opt::swap_pivots(column);
732
+ Dim_opt::swap_dimension(column);
733
+ }
734
+ }
735
+ } else {
736
+ if constexpr (Master_matrix::Option_list::is_z2) {
737
+ if (val) {
738
+ _add(column);
739
+ } else {
740
+ clear();
741
+ _add(column);
742
+ }
743
+ } else {
744
+ _multiply_target_and_add(val, column);
745
+ }
746
+ }
747
+
748
+ return *this;
749
+ }
750
+
751
+ template <class Master_matrix>
752
+ template <class Entry_range>
753
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::multiply_source_and_add(
754
+ const Entry_range& column, const Field_element& val)
755
+ {
756
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Unordered_set_column>),
757
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
758
+ "base element."); // could be removed, if we give the responsibility to the user.
759
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
760
+ "For chain columns, the given column cannot be constant.");
761
+
762
+ if constexpr (Master_matrix::Option_list::is_z2) {
763
+ if (val) {
764
+ _add(column);
765
+ }
766
+ } else {
767
+ _multiply_source_and_add(column, val);
768
+ }
769
+
770
+ return *this;
771
+ }
772
+
773
+ template <class Master_matrix>
774
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::multiply_source_and_add(
775
+ Unordered_set_column& column, const Field_element& val)
776
+ {
777
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
778
+ // assumes that the addition never zeros out this column.
779
+ if constexpr (Master_matrix::Option_list::is_z2) {
780
+ if (val) {
781
+ if (_add(column)) {
782
+ Chain_opt::swap_pivots(column);
783
+ Dim_opt::swap_dimension(column);
784
+ }
785
+ }
786
+ } else {
787
+ if (_multiply_source_and_add(column, val)) {
788
+ Chain_opt::swap_pivots(column);
789
+ Dim_opt::swap_dimension(column);
790
+ }
791
+ }
792
+ } else {
793
+ if constexpr (Master_matrix::Option_list::is_z2) {
794
+ if (val) {
795
+ _add(column);
796
+ }
797
+ } else {
798
+ _multiply_source_and_add(column, val);
799
+ }
800
+ }
801
+
802
+ return *this;
803
+ }
804
+
805
+ template <class Master_matrix>
806
+ inline void Unordered_set_column<Master_matrix>::push_back(const Entry& entry)
807
+ {
808
+ static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices.");
809
+
810
+ if constexpr (Master_matrix::Option_list::is_z2) {
811
+ _insert_entry(entry.get_row_index());
812
+ } else {
813
+ _insert_entry(entry.get_element(), entry.get_row_index());
814
+ }
815
+ }
816
+
817
+ template <class Master_matrix>
818
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::operator=(
819
+ const Unordered_set_column& other)
820
+ {
821
+ static_assert(!Master_matrix::Option_list::has_row_access, "= assignment not enabled with row access option.");
822
+
823
+ Dim_opt::operator=(other);
824
+ Chain_opt::operator=(other);
825
+
826
+ for (auto* entry : column_) {
827
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
828
+ entryPool_->destroy(entry);
829
+ }
830
+ column_.clear();
831
+
832
+ operators_ = other.operators_;
833
+ entryPool_ = other.entryPool_;
834
+
835
+ for (const Entry* entry : other.column_) {
836
+ if constexpr (Master_matrix::Option_list::is_z2) {
837
+ _insert_entry(entry->get_row_index());
838
+ } else {
839
+ _insert_entry(entry->get_element(), entry->get_row_index());
840
+ }
841
+ }
842
+
843
+ return *this;
844
+ }
845
+
846
+ template <class Master_matrix>
847
+ inline void Unordered_set_column<Master_matrix>::_delete_entry(typename Column_support::iterator& it)
848
+ {
849
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(*it);
850
+ entryPool_->destroy(*it);
851
+ auto tmp = it++;
852
+ // it = column_.erase(it);
853
+ column_.erase(tmp);
854
+ }
855
+
856
+ template <class Master_matrix>
857
+ inline typename Unordered_set_column<Master_matrix>::Entry* Unordered_set_column<Master_matrix>::_insert_entry(
858
+ const Field_element& value, ID_index rowIndex)
859
+ {
860
+ if constexpr (Master_matrix::Option_list::has_row_access) {
861
+ Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
862
+ newEntry->set_element(value);
863
+ column_.insert(newEntry);
864
+ RA_opt::insert_entry(rowIndex, newEntry);
865
+ return newEntry;
866
+ } else {
867
+ Entry* newEntry = entryPool_->construct(rowIndex);
868
+ newEntry->set_element(value);
869
+ column_.insert(newEntry);
870
+ return newEntry;
871
+ }
872
+ }
873
+
874
+ template <class Master_matrix>
875
+ inline void Unordered_set_column<Master_matrix>::_insert_entry(ID_index rowIndex)
876
+ {
877
+ if constexpr (Master_matrix::Option_list::has_row_access) {
878
+ Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
879
+ column_.insert(newEntry);
880
+ RA_opt::insert_entry(rowIndex, newEntry);
881
+ } else {
882
+ Entry* newEntry = entryPool_->construct(rowIndex);
883
+ column_.insert(newEntry);
884
+ }
885
+ }
886
+
887
+ template <class Master_matrix>
888
+ template <class Entry_range>
889
+ inline bool Unordered_set_column<Master_matrix>::_add(const Entry_range& column)
890
+ {
891
+ return _generic_add(
892
+ column,
893
+ [&](const Entry& oldEntry, Entry* newEntry) {
894
+ if constexpr (!Master_matrix::Option_list::is_z2) newEntry->set_element(oldEntry.get_element());
895
+ },
896
+ [&](Entry* targetEntry, const Entry& sourceEntry) {
897
+ if constexpr (!Master_matrix::Option_list::is_z2)
898
+ operators_->add_inplace(targetEntry->get_element(), sourceEntry.get_element());
899
+ });
900
+ }
901
+
902
+ template <class Master_matrix>
903
+ template <class Entry_range>
904
+ inline bool Unordered_set_column<Master_matrix>::_multiply_target_and_add(const Field_element& val,
905
+ const Entry_range& column)
906
+ {
907
+ if (val == 0u) {
908
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
909
+ throw std::invalid_argument("A chain column should not be multiplied by 0.");
910
+ // this would not only mess up the base, but also the pivots stored.
911
+ } else {
912
+ clear();
913
+ for (const Entry& v : column) {
914
+ _insert_entry(v.get_element(), v.get_row_index());
915
+ }
916
+ return true;
917
+ }
918
+ }
919
+
920
+ // because the column is unordered, I don't see a way to do both operations in one go
921
+ // without guarantees on the entry range...
922
+ operator*=(val);
923
+ return _add(column);
924
+ }
925
+
926
+ template <class Master_matrix>
927
+ template <class Entry_range>
928
+ inline bool Unordered_set_column<Master_matrix>::_multiply_source_and_add(const Entry_range& column,
929
+ const Field_element& val)
930
+ {
931
+ if (val == 0u) {
932
+ return false;
933
+ }
934
+
935
+ return _generic_add(
936
+ column,
937
+ [&](const Entry& oldEntry, Entry* newEntry) {
938
+ newEntry->set_element(oldEntry.get_element());
939
+ operators_->multiply_inplace(newEntry->get_element(), val);
940
+ },
941
+ [&](Entry* targetEntry, const Entry& sourceEntry) {
942
+ operators_->multiply_and_add_inplace_back(sourceEntry.get_element(), val, targetEntry->get_element());
943
+ });
944
+ }
945
+
946
+ template <class Master_matrix>
947
+ template <class Entry_range, typename F1, typename F2>
948
+ inline bool Unordered_set_column<Master_matrix>::_generic_add(const Entry_range& source,
949
+ F1&& process_source,
950
+ F2&& update_target)
951
+ {
952
+ bool pivotIsZeroed = false;
953
+
954
+ for (const Entry& entry : source) {
955
+ Entry* newEntry;
956
+ if constexpr (Master_matrix::Option_list::has_row_access) {
957
+ newEntry = entryPool_->construct(RA_opt::columnIndex_, entry.get_row_index());
958
+ } else {
959
+ newEntry = entryPool_->construct(entry.get_row_index());
960
+ }
961
+ auto res = column_.insert(newEntry);
962
+ if (res.second) {
963
+ process_source(entry, newEntry);
964
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::insert_entry(entry.get_row_index(), newEntry);
965
+ } else {
966
+ entryPool_->destroy(newEntry);
967
+ if constexpr (Master_matrix::Option_list::is_z2) {
968
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
969
+ if (entry.get_row_index() == Chain_opt::get_pivot()) pivotIsZeroed = true;
970
+ }
971
+ _delete_entry(res.first);
972
+ } else {
973
+ update_target(*res.first, entry);
974
+ if ((*res.first)->get_element() == Field_operators::get_additive_identity()) {
975
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
976
+ if ((*res.first)->get_row_index() == Chain_opt::get_pivot()) pivotIsZeroed = true;
977
+ }
978
+ _delete_entry(res.first);
979
+ } else {
980
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(**res.first);
981
+ }
982
+ }
983
+ }
984
+ }
985
+
986
+ return pivotIsZeroed;
987
+ }
988
+
989
+ } // namespace persistence_matrix
990
+ } // namespace Gudhi
991
+
992
+ /**
993
+ * @ingroup persistence_matrix
994
+ *
995
+ * @brief Hash method for @ref Gudhi::persistence_matrix::Unordered_set_column.
996
+ *
997
+ * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Unordered_set_column.
998
+ * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Unordered_set_column.
999
+ */
1000
+ template <class Master_matrix>
1001
+ struct std::hash<Gudhi::persistence_matrix::Unordered_set_column<Master_matrix>> {
1002
+ std::size_t operator()(const Gudhi::persistence_matrix::Unordered_set_column<Master_matrix>& column) const {
1003
+ // can't use Gudhi::persistence_matrix::hash_column because unordered
1004
+ std::size_t seed = 0;
1005
+ for (const auto& entry : column) {
1006
+ seed ^= std::hash<unsigned int>()(entry.get_row_index() * static_cast<unsigned int>(entry.get_element()));
1007
+ }
1008
+ return seed;
1009
+ }
1010
+ };
1011
+
1012
+ #endif // PM_UNORDERED_SET_COLUMN_H