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.
Files changed (184) hide show
  1. multipers/.dylibs/libboost_timer.dylib +0 -0
  2. multipers/.dylibs/libc++.1.0.dylib +0 -0
  3. multipers/.dylibs/libtbb.12.17.dylib +0 -0
  4. multipers/__init__.py +33 -0
  5. multipers/_signed_measure_meta.py +426 -0
  6. multipers/_slicer_meta.py +231 -0
  7. multipers/array_api/__init__.py +62 -0
  8. multipers/array_api/numpy.py +124 -0
  9. multipers/array_api/torch.py +133 -0
  10. multipers/data/MOL2.py +458 -0
  11. multipers/data/UCR.py +18 -0
  12. multipers/data/__init__.py +1 -0
  13. multipers/data/graphs.py +466 -0
  14. multipers/data/immuno_regions.py +27 -0
  15. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  16. multipers/data/pytorch2simplextree.py +91 -0
  17. multipers/data/shape3d.py +101 -0
  18. multipers/data/synthetic.py +113 -0
  19. multipers/distances.py +202 -0
  20. multipers/filtration_conversions.pxd +736 -0
  21. multipers/filtration_conversions.pxd.tp +226 -0
  22. multipers/filtrations/__init__.py +21 -0
  23. multipers/filtrations/density.py +529 -0
  24. multipers/filtrations/filtrations.py +480 -0
  25. multipers/filtrations.pxd +534 -0
  26. multipers/filtrations.pxd.tp +332 -0
  27. multipers/function_rips.cpython-312-darwin.so +0 -0
  28. multipers/function_rips.pyx +104 -0
  29. multipers/grids.cpython-312-darwin.so +0 -0
  30. multipers/grids.pyx +538 -0
  31. multipers/gudhi/Persistence_slices_interface.h +213 -0
  32. multipers/gudhi/Simplex_tree_interface.h +274 -0
  33. multipers/gudhi/Simplex_tree_multi_interface.h +648 -0
  34. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
  35. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
  36. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
  37. multipers/gudhi/gudhi/Debug_utils.h +52 -0
  38. multipers/gudhi/gudhi/Degree_rips_bifiltration.h +2307 -0
  39. multipers/gudhi/gudhi/Dynamic_multi_parameter_filtration.h +2524 -0
  40. multipers/gudhi/gudhi/Fields/Multi_field.h +453 -0
  41. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +460 -0
  42. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +444 -0
  43. multipers/gudhi/gudhi/Fields/Multi_field_small.h +584 -0
  44. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +490 -0
  45. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +580 -0
  46. multipers/gudhi/gudhi/Fields/Z2_field.h +391 -0
  47. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +389 -0
  48. multipers/gudhi/gudhi/Fields/Zp_field.h +493 -0
  49. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +384 -0
  50. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +492 -0
  51. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
  52. multipers/gudhi/gudhi/Matrix.h +2200 -0
  53. multipers/gudhi/gudhi/Multi_filtration/Multi_parameter_generator.h +1712 -0
  54. multipers/gudhi/gudhi/Multi_filtration/multi_filtration_conversions.h +237 -0
  55. multipers/gudhi/gudhi/Multi_filtration/multi_filtration_utils.h +225 -0
  56. multipers/gudhi/gudhi/Multi_parameter_filtered_complex.h +485 -0
  57. multipers/gudhi/gudhi/Multi_parameter_filtration.h +2643 -0
  58. multipers/gudhi/gudhi/Multi_persistence/Box.h +233 -0
  59. multipers/gudhi/gudhi/Multi_persistence/Line.h +309 -0
  60. multipers/gudhi/gudhi/Multi_persistence/Multi_parameter_filtered_complex_pcoh_interface.h +268 -0
  61. multipers/gudhi/gudhi/Multi_persistence/Persistence_interface_cohomology.h +159 -0
  62. multipers/gudhi/gudhi/Multi_persistence/Persistence_interface_matrix.h +463 -0
  63. multipers/gudhi/gudhi/Multi_persistence/Point.h +853 -0
  64. multipers/gudhi/gudhi/Off_reader.h +173 -0
  65. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +834 -0
  66. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +838 -0
  67. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +833 -0
  68. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1367 -0
  69. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1157 -0
  70. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +869 -0
  71. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +905 -0
  72. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +122 -0
  73. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +260 -0
  74. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +288 -0
  75. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +170 -0
  76. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +247 -0
  77. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +571 -0
  78. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +182 -0
  79. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +130 -0
  80. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +235 -0
  81. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +312 -0
  82. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1092 -0
  83. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +923 -0
  84. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +914 -0
  85. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +930 -0
  86. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1071 -0
  87. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +203 -0
  88. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +886 -0
  89. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +984 -0
  90. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1213 -0
  91. multipers/gudhi/gudhi/Persistence_matrix/index_mapper.h +58 -0
  92. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +227 -0
  93. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +200 -0
  94. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +166 -0
  95. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +319 -0
  96. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +562 -0
  97. multipers/gudhi/gudhi/Persistence_on_a_line.h +152 -0
  98. multipers/gudhi/gudhi/Persistence_on_rectangle.h +617 -0
  99. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
  100. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
  101. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
  102. multipers/gudhi/gudhi/Persistent_cohomology.h +769 -0
  103. multipers/gudhi/gudhi/Points_off_io.h +171 -0
  104. multipers/gudhi/gudhi/Projective_cover_kernel.h +379 -0
  105. multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
  106. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +559 -0
  107. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
  108. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +121 -0
  109. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
  110. multipers/gudhi/gudhi/Simplex_tree/filtration_value_utils.h +155 -0
  111. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
  112. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
  113. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +60 -0
  114. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +105 -0
  115. multipers/gudhi/gudhi/Simplex_tree.h +3170 -0
  116. multipers/gudhi/gudhi/Slicer.h +848 -0
  117. multipers/gudhi/gudhi/Thread_safe_slicer.h +393 -0
  118. multipers/gudhi/gudhi/distance_functions.h +62 -0
  119. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
  120. multipers/gudhi/gudhi/multi_simplex_tree_helpers.h +147 -0
  121. multipers/gudhi/gudhi/persistence_interval.h +263 -0
  122. multipers/gudhi/gudhi/persistence_matrix_options.h +188 -0
  123. multipers/gudhi/gudhi/reader_utils.h +367 -0
  124. multipers/gudhi/gudhi/simple_mdspan.h +484 -0
  125. multipers/gudhi/gudhi/slicer_helpers.h +779 -0
  126. multipers/gudhi/tmp_h0_pers/mma_interface_h0.h +223 -0
  127. multipers/gudhi/tmp_h0_pers/naive_merge_tree.h +536 -0
  128. multipers/io.cpython-312-darwin.so +0 -0
  129. multipers/io.pyx +472 -0
  130. multipers/ml/__init__.py +0 -0
  131. multipers/ml/accuracies.py +90 -0
  132. multipers/ml/invariants_with_persistable.py +79 -0
  133. multipers/ml/kernels.py +176 -0
  134. multipers/ml/mma.py +713 -0
  135. multipers/ml/one.py +472 -0
  136. multipers/ml/point_clouds.py +352 -0
  137. multipers/ml/signed_measures.py +1667 -0
  138. multipers/ml/sliced_wasserstein.py +461 -0
  139. multipers/ml/tools.py +113 -0
  140. multipers/mma_structures.cpython-312-darwin.so +0 -0
  141. multipers/mma_structures.pxd +134 -0
  142. multipers/mma_structures.pyx +1483 -0
  143. multipers/mma_structures.pyx.tp +1126 -0
  144. multipers/multi_parameter_rank_invariant/diff_helpers.h +85 -0
  145. multipers/multi_parameter_rank_invariant/euler_characteristic.h +95 -0
  146. multipers/multi_parameter_rank_invariant/function_rips.h +317 -0
  147. multipers/multi_parameter_rank_invariant/hilbert_function.h +761 -0
  148. multipers/multi_parameter_rank_invariant/persistence_slices.h +149 -0
  149. multipers/multi_parameter_rank_invariant/rank_invariant.h +350 -0
  150. multipers/multiparameter_edge_collapse.py +41 -0
  151. multipers/multiparameter_module_approximation/approximation.h +2541 -0
  152. multipers/multiparameter_module_approximation/debug.h +107 -0
  153. multipers/multiparameter_module_approximation/format_python-cpp.h +292 -0
  154. multipers/multiparameter_module_approximation/utilities.h +428 -0
  155. multipers/multiparameter_module_approximation.cpython-312-darwin.so +0 -0
  156. multipers/multiparameter_module_approximation.pyx +286 -0
  157. multipers/ops.cpython-312-darwin.so +0 -0
  158. multipers/ops.pyx +231 -0
  159. multipers/pickle.py +89 -0
  160. multipers/plots.py +550 -0
  161. multipers/point_measure.cpython-312-darwin.so +0 -0
  162. multipers/point_measure.pyx +409 -0
  163. multipers/simplex_tree_multi.cpython-312-darwin.so +0 -0
  164. multipers/simplex_tree_multi.pxd +136 -0
  165. multipers/simplex_tree_multi.pyx +11719 -0
  166. multipers/simplex_tree_multi.pyx.tp +2102 -0
  167. multipers/slicer.cpython-312-darwin.so +0 -0
  168. multipers/slicer.pxd +2097 -0
  169. multipers/slicer.pxd.tp +263 -0
  170. multipers/slicer.pyx +13042 -0
  171. multipers/slicer.pyx.tp +1259 -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 +70 -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/vector_interface.pxd +46 -0
  180. multipers-2.4.0b1.dist-info/METADATA +131 -0
  181. multipers-2.4.0b1.dist-info/RECORD +184 -0
  182. multipers-2.4.0b1.dist-info/WHEEL +6 -0
  183. multipers-2.4.0b1.dist-info/licenses/LICENSE +21 -0
  184. multipers-2.4.0b1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,984 @@
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 <stdexcept>
22
+ #include <type_traits>
23
+ #include <algorithm> // std::lexicographical_compare
24
+ #include <utility> //std::swap, std::move & std::exchange
25
+ #include <set>
26
+ #include <vector>
27
+
28
+ #include <boost/iterator/indirect_iterator.hpp>
29
+ #if BOOST_VERSION >= 108100
30
+ #include <boost/unordered/unordered_flat_set.hpp>
31
+ #else
32
+ #include <unordered_set>
33
+ #endif
34
+
35
+ #include <gudhi/Persistence_matrix/allocators/entry_constructors.h>
36
+
37
+ namespace Gudhi {
38
+ namespace persistence_matrix {
39
+
40
+ // For unordered_set container. Outside of Unordered_set_column because of a msvc bug who can't compile properly
41
+ // unordered_flat_set if the hash method is nested.
42
+ template <class Entry>
43
+ struct EntryPointerHash {
44
+ size_t operator()(const Entry* c) const { return std::hash<Entry>()(*c); }
45
+ };
46
+
47
+ template <class Entry>
48
+ struct EntryPointerEq {
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
+ */
64
+ template <class Master_matrix>
65
+ class Unordered_set_column : public Master_matrix::Row_access_option,
66
+ public Master_matrix::Column_dimension_option,
67
+ public Master_matrix::Chain_column_option
68
+ {
69
+ public:
70
+ using Master = Master_matrix;
71
+ using Index = typename Master_matrix::Index;
72
+ using ID_index = typename Master_matrix::ID_index;
73
+ using Dimension = typename Master_matrix::Dimension;
74
+ using Field_element = typename Master_matrix::Element;
75
+ using Entry = typename Master_matrix::Matrix_entry;
76
+ using Column_settings = typename Master_matrix::Column_settings;
77
+
78
+ private:
79
+ using Field_operators = typename Master_matrix::Field_operators;
80
+ using Entry_constructor = typename Master_matrix::Entry_constructor;
81
+
82
+ struct EntryPointerComp {
83
+ bool operator()(const Entry* c1, const Entry* c2) const { return *c1 < *c2; }
84
+ };
85
+
86
+ #if BOOST_VERSION >= 108100
87
+ using Column_support = boost::unordered_flat_set<Entry*, EntryPointerHash<Entry>, EntryPointerEq<Entry>>;
88
+ #else
89
+ using Column_support = std::unordered_set<Entry*, EntryPointerHash<Entry>, EntryPointerEq<Entry>>;
90
+ #endif
91
+
92
+ public:
93
+ using iterator = boost::indirect_iterator<typename Column_support::iterator>;
94
+ using const_iterator = boost::indirect_iterator<typename Column_support::const_iterator>;
95
+ using Content_range = std::vector<Entry>;
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
+ class = std::enable_if_t<!std::is_arithmetic_v<Container>>>
107
+ Unordered_set_column(const Container& nonZeroRowIndices, Dimension dimension, Column_settings* colSettings);
108
+ template <class Container = typename Master_matrix::Boundary,
109
+ class Row_container,
110
+ class = std::enable_if_t<!std::is_arithmetic_v<Container>>>
111
+ Unordered_set_column(Index columnIndex,
112
+ const Container& nonZeroRowIndices,
113
+ Dimension dimension,
114
+ Row_container* rowContainer,
115
+ Column_settings* colSettings);
116
+ Unordered_set_column(ID_index idx, Dimension dimension, Column_settings* colSettings);
117
+ Unordered_set_column(ID_index idx,
118
+ Field_element e,
119
+ Dimension dimension,
120
+ Column_settings* colSettings);
121
+ template <class Row_container>
122
+ Unordered_set_column(Index columnIndex,
123
+ ID_index idx,
124
+ Dimension dimension,
125
+ Row_container* rowContainer,
126
+ Column_settings* colSettings);
127
+ template <class Row_container>
128
+ Unordered_set_column(Index columnIndex,
129
+ ID_index idx,
130
+ Field_element e,
131
+ Dimension dimension,
132
+ Row_container* rowContainer,
133
+ Column_settings* colSettings);
134
+ Unordered_set_column(const Unordered_set_column& column, Column_settings* colSettings = nullptr);
135
+ template <class Row_container>
136
+ Unordered_set_column(const Unordered_set_column& column,
137
+ Index columnIndex,
138
+ Row_container* rowContainer,
139
+ Column_settings* colSettings = nullptr);
140
+ Unordered_set_column(Unordered_set_column&& column) noexcept;
141
+ ~Unordered_set_column();
142
+
143
+ std::vector<Field_element> get_content(int columnLength = -1) const;
144
+ bool is_non_zero(ID_index rowIndex) const;
145
+ [[nodiscard]] bool is_empty() const;
146
+ [[nodiscard]] std::size_t size() const;
147
+
148
+ template <class Row_index_map>
149
+ void reorder(const Row_index_map& valueMap,
150
+ [[maybe_unused]] Index columnIndex = Master_matrix::template get_null_value<Index>());
151
+ void clear();
152
+ void clear(ID_index rowIndex);
153
+
154
+ ID_index get_pivot() const;
155
+ Field_element get_pivot_value() const;
156
+
157
+ iterator begin() noexcept;
158
+ const_iterator begin() const noexcept;
159
+ iterator end() noexcept;
160
+ const_iterator end() const noexcept;
161
+
162
+ Content_range get_non_zero_content_range() const;
163
+
164
+ template <class Entry_range>
165
+ Unordered_set_column& operator+=(const Entry_range& column);
166
+ Unordered_set_column& operator+=(Unordered_set_column& column);
167
+
168
+ Unordered_set_column& operator*=(const Field_element& v);
169
+
170
+ // this = v * this + column
171
+ template <class Entry_range>
172
+ Unordered_set_column& multiply_target_and_add(const Field_element& val, const Entry_range& column);
173
+ Unordered_set_column& multiply_target_and_add(const Field_element& val, Unordered_set_column& column);
174
+ // this = this + column * v
175
+ template <class Entry_range>
176
+ Unordered_set_column& multiply_source_and_add(const Entry_range& column, const Field_element& val);
177
+ Unordered_set_column& multiply_source_and_add(Unordered_set_column& column, const Field_element& val);
178
+
179
+ void push_back(const Entry& entry);
180
+
181
+ friend bool operator==(const Unordered_set_column& c1, const Unordered_set_column& c2)
182
+ {
183
+ if (&c1 == &c2) return true;
184
+ if (c1.column_.size() != c2.column_.size()) return false;
185
+
186
+ for (Entry* entry : c1.column_) {
187
+ auto it = c2.column_.find(entry);
188
+ if (it == c2.column_.end()) return false;
189
+ if (Master_matrix::get_element(**it) != Master_matrix::get_element(*entry)) return false;
190
+ }
191
+ return true;
192
+ }
193
+
194
+ friend bool operator<(const Unordered_set_column& c1, const Unordered_set_column& c2)
195
+ {
196
+ if (&c1 == &c2) return false;
197
+
198
+ auto comp = [](const Entry* n1, const Entry* n2) -> bool {
199
+ Index r1 = Master_matrix::get_row_index(*n1);
200
+ Index r2 = Master_matrix::get_row_index(*n2);
201
+ Field_element e1 = Master_matrix::get_element(*n1);
202
+ Field_element e2 = Master_matrix::get_element(*n2);
203
+
204
+ if (r1 != r2) return r1 < r2;
205
+ if (e1 != e2) return e1 < e2;
206
+
207
+ return false;
208
+ };
209
+
210
+ std::set<Entry*, decltype(comp)> entries1(comp), entries2(comp);
211
+ entries1.insert(c1.column_.begin(), c1.column_.end());
212
+ entries2.insert(c2.column_.begin(), c2.column_.end());
213
+
214
+ return std::lexicographical_compare(entries1.begin(), entries1.end(), entries2.begin(), entries2.end(), comp);
215
+ }
216
+
217
+ // Disabled with row access.
218
+ Unordered_set_column& operator=(const Unordered_set_column& other);
219
+ Unordered_set_column& operator=(Unordered_set_column&& other) noexcept;
220
+
221
+ friend void swap(Unordered_set_column& col1, Unordered_set_column& col2) noexcept
222
+ {
223
+ swap(static_cast<typename Master_matrix::Row_access_option&>(col1),
224
+ static_cast<typename Master_matrix::Row_access_option&>(col2));
225
+ swap(static_cast<typename Master_matrix::Column_dimension_option&>(col1),
226
+ static_cast<typename Master_matrix::Column_dimension_option&>(col2));
227
+ swap(static_cast<typename Master_matrix::Chain_column_option&>(col1),
228
+ static_cast<typename Master_matrix::Chain_column_option&>(col2));
229
+ col1.column_.swap(col2.column_);
230
+ std::swap(col1.operators_, col2.operators_);
231
+ std::swap(col1.entryPool_, col2.entryPool_);
232
+ }
233
+
234
+ private:
235
+ using RA_opt = typename Master_matrix::Row_access_option;
236
+ using Dim_opt = typename Master_matrix::Column_dimension_option;
237
+ using Chain_opt = typename Master_matrix::Chain_column_option;
238
+
239
+ Column_support column_;
240
+ Field_operators const* operators_;
241
+ Entry_constructor* entryPool_;
242
+
243
+ void _delete_entry(typename Column_support::iterator& it);
244
+ Entry* _insert_entry(ID_index rowIndex, const Field_element& value);
245
+ template <class Entry_range>
246
+ bool _add(const Entry_range& column);
247
+ template <class Entry_range>
248
+ bool _multiply_target_and_add(const Field_element& val, const Entry_range& column);
249
+ template <class Entry_range>
250
+ bool _multiply_source_and_add(const Entry_range& column, const Field_element& val);
251
+ template <class Entry_range, typename F1, typename F2>
252
+ bool _generic_add(const Entry_range& source, F1&& process_source, F2&& update_target);
253
+ };
254
+
255
+ template <class Master_matrix>
256
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Column_settings* colSettings)
257
+ : RA_opt(),
258
+ Dim_opt(),
259
+ Chain_opt(),
260
+ operators_(Master_matrix::get_operator_ptr(colSettings)),
261
+ entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor))
262
+ {}
263
+
264
+ template <class Master_matrix>
265
+ template <class Container>
266
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(const Container& nonZeroRowIndices,
267
+ Column_settings* colSettings)
268
+ : Unordered_set_column(nonZeroRowIndices,
269
+ nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1,
270
+ colSettings)
271
+ {
272
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
273
+ "Constructor not available for chain columns, please specify the dimension of the chain.");
274
+ }
275
+
276
+ template <class Master_matrix>
277
+ template <class Container, class Row_container>
278
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Index columnIndex,
279
+ const Container& nonZeroRowIndices,
280
+ Row_container* rowContainer,
281
+ Column_settings* colSettings)
282
+ : Unordered_set_column(columnIndex,
283
+ nonZeroRowIndices,
284
+ nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1,
285
+ rowContainer,
286
+ colSettings)
287
+ {
288
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
289
+ "Constructor not available for chain columns, please specify the dimension of the chain.");
290
+ }
291
+
292
+ template <class Master_matrix>
293
+ template <class Container, class>
294
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(const Container& nonZeroRowIndices,
295
+ Dimension dimension,
296
+ Column_settings* colSettings)
297
+ : RA_opt(),
298
+ Dim_opt(dimension),
299
+ Chain_opt(nonZeroRowIndices.begin() == nonZeroRowIndices.end()
300
+ ? Master_matrix::template get_null_value<ID_index>()
301
+ : Master_matrix::get_row_index(*std::prev(nonZeroRowIndices.end()))),
302
+ column_(nonZeroRowIndices.size()),
303
+ operators_(Master_matrix::get_operator_ptr(colSettings)),
304
+ entryPool_(&(colSettings->entryConstructor))
305
+ {
306
+ for (const auto& id : nonZeroRowIndices) {
307
+ _insert_entry(Master_matrix::get_row_index(id),
308
+ Master_matrix::get_coefficient_value(Master_matrix::get_element(id), operators_));
309
+ }
310
+ }
311
+
312
+ template <class Master_matrix>
313
+ template <class Container, class Row_container, class>
314
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Index columnIndex,
315
+ const Container& nonZeroRowIndices,
316
+ Dimension dimension,
317
+ Row_container* rowContainer,
318
+ Column_settings* colSettings)
319
+ : RA_opt(columnIndex, rowContainer),
320
+ Dim_opt(dimension),
321
+ Chain_opt(nonZeroRowIndices.begin() == nonZeroRowIndices.end()
322
+ ? Master_matrix::template get_null_value<ID_index>()
323
+ : Master_matrix::get_row_index(*std::prev(nonZeroRowIndices.end()))),
324
+ column_(nonZeroRowIndices.size()),
325
+ operators_(Master_matrix::get_operator_ptr(colSettings)),
326
+ entryPool_(&(colSettings->entryConstructor))
327
+ {
328
+ for (const auto& id : nonZeroRowIndices) {
329
+ _insert_entry(Master_matrix::get_row_index(id),
330
+ Master_matrix::get_coefficient_value(Master_matrix::get_element(id), operators_));
331
+ }
332
+ }
333
+
334
+ template <class Master_matrix>
335
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(ID_index idx,
336
+ Dimension dimension,
337
+ Column_settings* colSettings)
338
+ : RA_opt(),
339
+ Dim_opt(dimension),
340
+ Chain_opt(idx),
341
+ column_(1),
342
+ operators_(nullptr),
343
+ entryPool_(&(colSettings->entryConstructor))
344
+ {
345
+ static_assert(Master_matrix::Option_list::is_z2,
346
+ "Constructor not available for Zp != Z2. Please specify the coefficient.");
347
+ _insert_entry(idx, 1);
348
+ }
349
+
350
+ template <class Master_matrix>
351
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(ID_index idx,
352
+ Field_element e,
353
+ Dimension dimension,
354
+ Column_settings* colSettings)
355
+ : RA_opt(),
356
+ Dim_opt(dimension),
357
+ Chain_opt(idx),
358
+ column_(1),
359
+ operators_(&(colSettings->operators)),
360
+ entryPool_(&(colSettings->entryConstructor))
361
+ {
362
+ static_assert(!Master_matrix::Option_list::is_z2,
363
+ "Constructor not available for Zp == Z2. Please do not specify any coefficient.");
364
+ _insert_entry(idx, operators_->get_value(e));
365
+ }
366
+
367
+ template <class Master_matrix>
368
+ template <class Row_container>
369
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Index columnIndex,
370
+ ID_index idx,
371
+ Dimension dimension,
372
+ Row_container* rowContainer,
373
+ Column_settings* colSettings)
374
+ : RA_opt(columnIndex, rowContainer),
375
+ Dim_opt(dimension),
376
+ Chain_opt(idx),
377
+ column_(1),
378
+ operators_(nullptr),
379
+ entryPool_(&(colSettings->entryConstructor))
380
+ {
381
+ static_assert(Master_matrix::Option_list::is_z2,
382
+ "Constructor not available for Zp != Z2. Please specify the coefficient.");
383
+ _insert_entry(idx, 1);
384
+ }
385
+
386
+ template <class Master_matrix>
387
+ template <class Row_container>
388
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Index columnIndex,
389
+ ID_index idx,
390
+ Field_element e,
391
+ Dimension dimension,
392
+ Row_container* rowContainer,
393
+ Column_settings* colSettings)
394
+ : RA_opt(columnIndex, rowContainer),
395
+ Dim_opt(dimension),
396
+ Chain_opt(idx),
397
+ column_(1),
398
+ operators_(&(colSettings->operators)),
399
+ entryPool_(&(colSettings->entryConstructor))
400
+ {
401
+ static_assert(!Master_matrix::Option_list::is_z2,
402
+ "Constructor not available for Zp == Z2. Please do not specify any coefficient.");
403
+ _insert_entry(idx, operators_->get_value(e));
404
+ }
405
+
406
+ template <class Master_matrix>
407
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(const Unordered_set_column& column,
408
+ Column_settings* colSettings)
409
+ : RA_opt(),
410
+ Dim_opt(static_cast<const Dim_opt&>(column)),
411
+ Chain_opt(static_cast<const Chain_opt&>(column)),
412
+ column_(column.column_.bucket_count()),
413
+ operators_(colSettings == nullptr ? column.operators_ : Master_matrix::get_operator_ptr(colSettings)),
414
+ entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
415
+ {
416
+ static_assert(!Master_matrix::Option_list::has_row_access,
417
+ "Simple copy constructor not available when row access option enabled. Please specify the new column "
418
+ "index and the row container.");
419
+
420
+ for (const Entry* entry : column.column_) {
421
+ _insert_entry(entry->get_row_index(), entry->get_element());
422
+ }
423
+ }
424
+
425
+ template <class Master_matrix>
426
+ template <class Row_container>
427
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(const Unordered_set_column& column,
428
+ Index columnIndex,
429
+ Row_container* rowContainer,
430
+ Column_settings* colSettings)
431
+ : RA_opt(columnIndex, rowContainer),
432
+ Dim_opt(static_cast<const Dim_opt&>(column)),
433
+ Chain_opt(static_cast<const Chain_opt&>(column)),
434
+ column_(column.column_.bucket_count()),
435
+ operators_(colSettings == nullptr ? column.operators_ : Master_matrix::get_operator_ptr(colSettings)),
436
+ entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
437
+ {
438
+ for (const Entry* entry : column.column_) {
439
+ _insert_entry(entry->get_row_index(), entry->get_element());
440
+ }
441
+ }
442
+
443
+ template <class Master_matrix>
444
+ inline Unordered_set_column<Master_matrix>::Unordered_set_column(Unordered_set_column&& column) noexcept
445
+ : RA_opt(std::move(static_cast<RA_opt&>(column))),
446
+ Dim_opt(std::move(static_cast<Dim_opt&>(column))),
447
+ Chain_opt(std::move(static_cast<Chain_opt&>(column))),
448
+ column_(std::move(column.column_)),
449
+ operators_(std::exchange(column.operators_, nullptr)),
450
+ entryPool_(std::exchange(column.entryPool_, nullptr))
451
+ {}
452
+
453
+ template <class Master_matrix>
454
+ inline Unordered_set_column<Master_matrix>::~Unordered_set_column()
455
+ {
456
+ for (auto* entry : column_) {
457
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
458
+ entryPool_->destroy(entry);
459
+ }
460
+ }
461
+
462
+ template <class Master_matrix>
463
+ inline std::vector<typename Unordered_set_column<Master_matrix>::Field_element>
464
+ Unordered_set_column<Master_matrix>::get_content(int columnLength) const
465
+ {
466
+ if (columnLength < 0 && column_.size() > 0)
467
+ columnLength = (*std::max_element(column_.begin(), column_.end(), EntryPointerComp()))->get_row_index() + 1;
468
+ else if (columnLength < 0)
469
+ return std::vector<Field_element>();
470
+
471
+ std::vector<Field_element> container(columnLength, 0);
472
+ for (auto it = column_.begin(); it != column_.end(); ++it) {
473
+ if ((*it)->get_row_index() < static_cast<ID_index>(columnLength)) {
474
+ container[(*it)->get_row_index()] = Master_matrix::get_element(**it);
475
+ }
476
+ }
477
+ return container;
478
+ }
479
+
480
+ template <class Master_matrix>
481
+ inline bool Unordered_set_column<Master_matrix>::is_non_zero(ID_index rowIndex) const
482
+ {
483
+ Entry entry(rowIndex);
484
+ return column_.find(&entry) != column_.end();
485
+ }
486
+
487
+ template <class Master_matrix>
488
+ inline bool Unordered_set_column<Master_matrix>::is_empty() const
489
+ {
490
+ return column_.empty();
491
+ }
492
+
493
+ template <class Master_matrix>
494
+ inline std::size_t Unordered_set_column<Master_matrix>::size() const
495
+ {
496
+ return column_.size();
497
+ }
498
+
499
+ template <class Master_matrix>
500
+ template <class Row_index_map>
501
+ inline void Unordered_set_column<Master_matrix>::reorder(const Row_index_map& valueMap,
502
+ [[maybe_unused]] Index columnIndex)
503
+ {
504
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
505
+ "Method not available for chain columns.");
506
+
507
+ Column_support newSet;
508
+
509
+ for (Entry* entry : column_) {
510
+ if constexpr (Master_matrix::Option_list::has_row_access) {
511
+ RA_opt::unlink(entry);
512
+ if (columnIndex != Master_matrix::template get_null_value<Index>()) entry->set_column_index(columnIndex);
513
+ }
514
+ entry->set_row_index(valueMap.at(entry->get_row_index()));
515
+ newSet.insert(entry);
516
+ if constexpr (Master_matrix::Option_list::has_row_access &&
517
+ Master_matrix::Option_list::has_intrusive_rows) // intrusive list
518
+ RA_opt::insert_entry(entry->get_row_index(), entry);
519
+ }
520
+
521
+ // when row is a set, all entries have to be deleted first, to avoid colliding when inserting
522
+ if constexpr (Master_matrix::Option_list::has_row_access && !Master_matrix::Option_list::has_intrusive_rows) { // set
523
+ for (Entry* entry : newSet) {
524
+ RA_opt::insert_entry(entry->get_row_index(), entry);
525
+ }
526
+ }
527
+
528
+ column_.swap(newSet);
529
+ }
530
+
531
+ template <class Master_matrix>
532
+ inline void Unordered_set_column<Master_matrix>::clear()
533
+ {
534
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
535
+ "Method not available for chain columns as a base element should not be empty.");
536
+
537
+ for (auto* entry : column_) {
538
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
539
+ entryPool_->destroy(entry);
540
+ }
541
+
542
+ column_.clear();
543
+ }
544
+
545
+ template <class Master_matrix>
546
+ inline void Unordered_set_column<Master_matrix>::clear(ID_index rowIndex)
547
+ {
548
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
549
+ "Method not available for chain columns.");
550
+
551
+ auto entry = entryPool_->construct(rowIndex);
552
+ auto it = column_.find(entry);
553
+ if (it != column_.end()) {
554
+ _delete_entry(it);
555
+ }
556
+ entryPool_->destroy(entry);
557
+ }
558
+
559
+ template <class Master_matrix>
560
+ inline typename Unordered_set_column<Master_matrix>::ID_index Unordered_set_column<Master_matrix>::get_pivot() const
561
+ {
562
+ static_assert(Master_matrix::isNonBasic,
563
+ "Method not available for base columns."); // could technically be, but is the notion useful then?
564
+
565
+ if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
566
+ if (column_.empty()) return Master_matrix::template get_null_value<ID_index>();
567
+ // linear search could be avoided with storing the pivot. But even then, some modifications of the column requires
568
+ // the max, so not clear how much it is worth it.
569
+ return (*std::max_element(column_.begin(), column_.end(), EntryPointerComp()))->get_row_index();
570
+ } else {
571
+ return Chain_opt::_get_pivot();
572
+ }
573
+ }
574
+
575
+ template <class Master_matrix>
576
+ inline typename Unordered_set_column<Master_matrix>::Field_element
577
+ Unordered_set_column<Master_matrix>::get_pivot_value() const
578
+ {
579
+ static_assert(Master_matrix::isNonBasic,
580
+ "Method not available for base columns."); // could technically be, but is the notion useful then?
581
+
582
+ if constexpr (Master_matrix::Option_list::is_z2) {
583
+ return 1;
584
+ } else {
585
+ if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
586
+ if (column_.empty()) return 0;
587
+ return (*std::max_element(column_.begin(), column_.end(), EntryPointerComp()))->get_element();
588
+ } else {
589
+ if (Chain_opt::_get_pivot() == Master_matrix::template get_null_value<ID_index>()) return Field_element();
590
+ for (const Entry* entry : column_) {
591
+ if (entry->get_row_index() == Chain_opt::_get_pivot()) return entry->get_element();
592
+ }
593
+ return Field_element(); // should never happen if chain column is used properly
594
+ }
595
+ }
596
+ }
597
+
598
+ template <class Master_matrix>
599
+ inline typename Unordered_set_column<Master_matrix>::iterator Unordered_set_column<Master_matrix>::begin() noexcept
600
+ {
601
+ return column_.begin();
602
+ }
603
+
604
+ template <class Master_matrix>
605
+ inline typename Unordered_set_column<Master_matrix>::const_iterator Unordered_set_column<Master_matrix>::begin()
606
+ const noexcept
607
+ {
608
+ return column_.begin();
609
+ }
610
+
611
+ template <class Master_matrix>
612
+ inline typename Unordered_set_column<Master_matrix>::iterator Unordered_set_column<Master_matrix>::end() noexcept
613
+ {
614
+ return column_.end();
615
+ }
616
+
617
+ template <class Master_matrix>
618
+ inline typename Unordered_set_column<Master_matrix>::const_iterator Unordered_set_column<Master_matrix>::end()
619
+ const noexcept
620
+ {
621
+ return column_.end();
622
+ }
623
+
624
+ template <class Master_matrix>
625
+ inline typename Unordered_set_column<Master_matrix>::Content_range
626
+ Unordered_set_column<Master_matrix>::get_non_zero_content_range() const
627
+ {
628
+ Content_range res(column_.size());
629
+ std::size_t i = 0;
630
+ for (const auto& entry : column_) res[i++] = *entry;
631
+ std::sort(res.begin(), res.end());
632
+ return res;
633
+ }
634
+
635
+ template <class Master_matrix>
636
+ template <class Entry_range>
637
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::operator+=(const Entry_range& column)
638
+ {
639
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Unordered_set_column>),
640
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
641
+ "base element."); // could be removed, if we give the responsibility to the user.
642
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
643
+ "For chain columns, the given column cannot be constant.");
644
+
645
+ _add(column);
646
+
647
+ return *this;
648
+ }
649
+
650
+ template <class Master_matrix>
651
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::operator+=(
652
+ Unordered_set_column& column)
653
+ {
654
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
655
+ // assumes that the addition never zeros out this column.
656
+ if (_add(column)) {
657
+ Chain_opt::_swap_pivots(column);
658
+ Dim_opt::_swap_dimension(column);
659
+ }
660
+ } else {
661
+ _add(column);
662
+ }
663
+
664
+ return *this;
665
+ }
666
+
667
+ template <class Master_matrix>
668
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::operator*=(const Field_element& v)
669
+ {
670
+ Field_element val = Master_matrix::get_coefficient_value(v, operators_);
671
+
672
+ if (val == Field_operators::get_additive_identity()) {
673
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
674
+ throw std::invalid_argument("A chain column should not be multiplied by 0.");
675
+ } else {
676
+ clear();
677
+ }
678
+ return *this;
679
+ }
680
+
681
+ if (val == Field_operators::get_multiplicative_identity()) return *this;
682
+
683
+ // multiply_inplace needs a non-const reference to element, so even if Z2 never reaches here, it won't compile
684
+ // without the constexpr, as we are not storing a dummy value just for this purpose.
685
+ if constexpr (!Master_matrix::Option_list::is_z2) {
686
+ for (Entry* entry : column_) {
687
+ operators_->multiply_inplace(entry->get_element(), val);
688
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entry);
689
+ }
690
+ }
691
+
692
+ return *this;
693
+ }
694
+
695
+ template <class Master_matrix>
696
+ template <class Entry_range>
697
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::multiply_target_and_add(
698
+ const Field_element& val,
699
+ const Entry_range& column)
700
+ {
701
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Unordered_set_column>),
702
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
703
+ "base element."); // could be removed, if we give the responsibility to the user.
704
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
705
+ "For chain columns, the given column cannot be constant.");
706
+
707
+ _multiply_target_and_add(Master_matrix::get_coefficient_value(val, operators_), column);
708
+
709
+ return *this;
710
+ }
711
+
712
+ template <class Master_matrix>
713
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::multiply_target_and_add(
714
+ const Field_element& val,
715
+ Unordered_set_column& column)
716
+ {
717
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
718
+ // assumes that the addition never zeros out this column.
719
+ if (_multiply_target_and_add(Master_matrix::get_coefficient_value(val, operators_), column)) {
720
+ Chain_opt::_swap_pivots(column);
721
+ Dim_opt::_swap_dimension(column);
722
+ }
723
+ } else {
724
+ _multiply_target_and_add(Master_matrix::get_coefficient_value(val, operators_), column);
725
+ }
726
+
727
+ return *this;
728
+ }
729
+
730
+ template <class Master_matrix>
731
+ template <class Entry_range>
732
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::multiply_source_and_add(
733
+ const Entry_range& column,
734
+ const Field_element& val)
735
+ {
736
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Unordered_set_column>),
737
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
738
+ "base element."); // could be removed, if we give the responsibility to the user.
739
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
740
+ "For chain columns, the given column cannot be constant.");
741
+
742
+ _multiply_source_and_add(column, Master_matrix::get_coefficient_value(val, operators_));
743
+
744
+ return *this;
745
+ }
746
+
747
+ template <class Master_matrix>
748
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::multiply_source_and_add(
749
+ Unordered_set_column& column,
750
+ const Field_element& val)
751
+ {
752
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
753
+ // assumes that the addition never zeros out this column.
754
+ if (_multiply_source_and_add(column, Master_matrix::get_coefficient_value(val, operators_))) {
755
+ Chain_opt::_swap_pivots(column);
756
+ Dim_opt::_swap_dimension(column);
757
+ }
758
+ } else {
759
+ _multiply_source_and_add(column, Master_matrix::get_coefficient_value(val, operators_));
760
+ }
761
+
762
+ return *this;
763
+ }
764
+
765
+ template <class Master_matrix>
766
+ inline void Unordered_set_column<Master_matrix>::push_back(const Entry& entry)
767
+ {
768
+ static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices.");
769
+
770
+ GUDHI_CHECK(entry.get_row_index() > get_pivot(), "The new row index has to be higher than the current pivot.");
771
+
772
+ _insert_entry(entry.get_row_index(), entry.get_element());
773
+ }
774
+
775
+ template <class Master_matrix>
776
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::operator=(
777
+ const Unordered_set_column& other)
778
+ {
779
+ static_assert(!Master_matrix::Option_list::has_row_access, "= assignment not enabled with row access option.");
780
+
781
+ // to avoid destroying the column when building from it-self in the for loop below...
782
+ if (this == &other) return *this;
783
+
784
+ Dim_opt::operator=(other);
785
+ Chain_opt::operator=(other);
786
+
787
+ for (auto* entry : column_) {
788
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
789
+ entryPool_->destroy(entry);
790
+ }
791
+ column_.clear();
792
+
793
+ operators_ = other.operators_;
794
+ entryPool_ = other.entryPool_;
795
+
796
+ for (const Entry* entry : other.column_) {
797
+ _insert_entry(entry->get_row_index(), entry->get_element());
798
+ }
799
+
800
+ return *this;
801
+ }
802
+
803
+ template <class Master_matrix>
804
+ inline Unordered_set_column<Master_matrix>& Unordered_set_column<Master_matrix>::operator=(
805
+ Unordered_set_column&& other) noexcept
806
+ {
807
+ static_assert(!Master_matrix::Option_list::has_row_access, "= assignment not enabled with row access option.");
808
+
809
+ // to avoid destroying the column before building from it-self...
810
+ if (&column_ == &(other.column_)) return *this;
811
+
812
+ Dim_opt::operator=(std::move(other));
813
+ Chain_opt::operator=(std::move(other));
814
+
815
+ for (auto* entry : column_) {
816
+ if (entry != nullptr) entryPool_->destroy(entry);
817
+ }
818
+
819
+ column_ = std::move(other.column_);
820
+ operators_ = std::exchange(other.operators_, nullptr);
821
+ entryPool_ = std::exchange(other.entryPool_, nullptr);
822
+
823
+ return *this;
824
+ }
825
+
826
+ template <class Master_matrix>
827
+ inline void Unordered_set_column<Master_matrix>::_delete_entry(typename Column_support::iterator& it)
828
+ {
829
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(*it);
830
+ entryPool_->destroy(*it);
831
+ auto tmp = it++;
832
+ // it = column_.erase(it);
833
+ column_.erase(tmp);
834
+ }
835
+
836
+ template <class Master_matrix>
837
+ inline typename Unordered_set_column<Master_matrix>::Entry* Unordered_set_column<Master_matrix>::_insert_entry(
838
+ ID_index rowIndex,
839
+ const Field_element& value)
840
+ {
841
+ Entry* newEntry;
842
+ if constexpr (Master_matrix::Option_list::has_row_access) {
843
+ newEntry = entryPool_->construct(RA_opt::get_column_index(), rowIndex);
844
+ } else {
845
+ newEntry = entryPool_->construct(rowIndex);
846
+ }
847
+ newEntry->set_element(value);
848
+ column_.insert(newEntry);
849
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::insert_entry(rowIndex, newEntry);
850
+ return newEntry;
851
+ }
852
+
853
+ template <class Master_matrix>
854
+ template <class Entry_range>
855
+ inline bool Unordered_set_column<Master_matrix>::_add(const Entry_range& column)
856
+ {
857
+ if (column.begin() == column.end()) return false;
858
+ if (column_.empty()) { // chain should never enter here.
859
+ for (const Entry& entry : column) {
860
+ _insert_entry(entry.get_row_index(), entry.get_element());
861
+ }
862
+ return true;
863
+ }
864
+
865
+ return _generic_add(
866
+ column,
867
+ [&](const Entry& oldEntry, Entry* newEntry) {
868
+ newEntry->set_element(oldEntry.get_element());
869
+ },
870
+ [&](Entry* targetEntry, const Entry& sourceEntry) {
871
+ if constexpr (!Master_matrix::Option_list::is_z2)
872
+ operators_->add_inplace(targetEntry->get_element(), sourceEntry.get_element());
873
+ });
874
+ }
875
+
876
+ template <class Master_matrix>
877
+ template <class Entry_range>
878
+ inline bool Unordered_set_column<Master_matrix>::_multiply_target_and_add(const Field_element& val,
879
+ const Entry_range& column)
880
+ {
881
+ // because the column is unordered, I don't see a way to do both operations in one go
882
+ // without guarantees on the entry range...
883
+ operator*=(val);
884
+ return _add(column) || val == Field_operators::get_additive_identity();
885
+ }
886
+
887
+ template <class Master_matrix>
888
+ template <class Entry_range>
889
+ inline bool Unordered_set_column<Master_matrix>::_multiply_source_and_add(const Entry_range& column,
890
+ const Field_element& val)
891
+ {
892
+ if (val == Field_operators::get_additive_identity() || column.begin() == column.end()) {
893
+ return false;
894
+ }
895
+
896
+ if (val == Field_operators::get_multiplicative_identity()) {
897
+ return _add(column);
898
+ }
899
+
900
+ // multiply_inplace needs a non-const reference to element, so even if Z2 never reaches here, it won't compile
901
+ // without the constexpr, as we are not storing a dummy value just for this purpose.
902
+ if constexpr (!Master_matrix::Option_list::is_z2) {
903
+ return _generic_add(
904
+ column,
905
+ [&](const Entry& oldEntry, Entry* newEntry) {
906
+ newEntry->set_element(oldEntry.get_element());
907
+ operators_->multiply_inplace(newEntry->get_element(), val);
908
+ },
909
+ [&](Entry* targetEntry, const Entry& sourceEntry) {
910
+ operators_->multiply_and_add_inplace_back(sourceEntry.get_element(), val, targetEntry->get_element());
911
+ });
912
+ } else {
913
+ return false; // we should never arrive here, just to suppress the warning
914
+ }
915
+ }
916
+
917
+ template <class Master_matrix>
918
+ template <class Entry_range, typename F1, typename F2>
919
+ inline bool Unordered_set_column<Master_matrix>::_generic_add(const Entry_range& source,
920
+ [[maybe_unused]] F1&& process_source,
921
+ [[maybe_unused]] F2&& update_target)
922
+ {
923
+ bool pivotIsZeroed = false;
924
+
925
+ for (const Entry& entry : source) {
926
+ Entry* newEntry;
927
+ if constexpr (Master_matrix::Option_list::has_row_access) {
928
+ newEntry = entryPool_->construct(RA_opt::get_column_index(), entry.get_row_index());
929
+ } else {
930
+ newEntry = entryPool_->construct(entry.get_row_index());
931
+ }
932
+ auto res = column_.insert(newEntry);
933
+ if (res.second) {
934
+ std::forward<F1>(process_source)(entry, newEntry);
935
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::insert_entry(entry.get_row_index(), newEntry);
936
+ } else {
937
+ entryPool_->destroy(newEntry);
938
+ if constexpr (Master_matrix::Option_list::is_z2) {
939
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
940
+ if (entry.get_row_index() == Chain_opt::_get_pivot()) pivotIsZeroed = true;
941
+ }
942
+ _delete_entry(res.first);
943
+ } else {
944
+ std::forward<F2>(update_target)(*res.first, entry);
945
+ if ((*res.first)->get_element() == Field_operators::get_additive_identity()) {
946
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
947
+ if ((*res.first)->get_row_index() == Chain_opt::_get_pivot()) pivotIsZeroed = true;
948
+ }
949
+ _delete_entry(res.first);
950
+ } else {
951
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(**res.first);
952
+ }
953
+ }
954
+ }
955
+ }
956
+
957
+ return pivotIsZeroed;
958
+ }
959
+
960
+ } // namespace persistence_matrix
961
+ } // namespace Gudhi
962
+
963
+ /**
964
+ * @ingroup persistence_matrix
965
+ *
966
+ * @brief Hash method for @ref Gudhi::persistence_matrix::Unordered_set_column.
967
+ *
968
+ * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Unordered_set_column.
969
+ * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Unordered_set_column.
970
+ */
971
+ template <class Master_matrix>
972
+ struct std::hash<Gudhi::persistence_matrix::Unordered_set_column<Master_matrix>> {
973
+ std::size_t operator()(const Gudhi::persistence_matrix::Unordered_set_column<Master_matrix>& column) const
974
+ {
975
+ // can't use Gudhi::persistence_matrix::hash_column because unordered
976
+ std::size_t seed = 0;
977
+ for (const auto& entry : column) {
978
+ seed ^= std::hash<unsigned int>()(entry.get_row_index() * static_cast<unsigned int>(entry.get_element()));
979
+ }
980
+ return seed;
981
+ }
982
+ };
983
+
984
+ #endif // PM_UNORDERED_SET_COLUMN_H