multipers 2.2.3__cp311-cp311-win_amd64.whl → 2.3.0__cp311-cp311-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (182) hide show
  1. multipers/__init__.py +33 -31
  2. multipers/_signed_measure_meta.py +430 -430
  3. multipers/_slicer_meta.py +211 -212
  4. multipers/data/MOL2.py +458 -458
  5. multipers/data/UCR.py +18 -18
  6. multipers/data/graphs.py +466 -466
  7. multipers/data/immuno_regions.py +27 -27
  8. multipers/data/pytorch2simplextree.py +90 -90
  9. multipers/data/shape3d.py +101 -101
  10. multipers/data/synthetic.py +113 -111
  11. multipers/distances.py +198 -198
  12. multipers/filtration_conversions.pxd.tp +84 -84
  13. multipers/filtrations/__init__.py +18 -0
  14. multipers/filtrations/filtrations.py +289 -0
  15. multipers/filtrations.pxd +224 -224
  16. multipers/function_rips.cp311-win_amd64.pyd +0 -0
  17. multipers/function_rips.pyx +105 -105
  18. multipers/grids.cp311-win_amd64.pyd +0 -0
  19. multipers/grids.pyx +350 -350
  20. multipers/gudhi/Persistence_slices_interface.h +132 -132
  21. multipers/gudhi/Simplex_tree_interface.h +239 -245
  22. multipers/gudhi/Simplex_tree_multi_interface.h +516 -561
  23. multipers/gudhi/cubical_to_boundary.h +59 -59
  24. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -450
  25. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -1070
  26. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -579
  27. multipers/gudhi/gudhi/Debug_utils.h +45 -45
  28. multipers/gudhi/gudhi/Fields/Multi_field.h +484 -484
  29. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -455
  30. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -450
  31. multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -531
  32. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -507
  33. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -531
  34. multipers/gudhi/gudhi/Fields/Z2_field.h +355 -355
  35. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -376
  36. multipers/gudhi/gudhi/Fields/Zp_field.h +420 -420
  37. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -400
  38. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -418
  39. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -337
  40. multipers/gudhi/gudhi/Matrix.h +2107 -2107
  41. multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -1038
  42. multipers/gudhi/gudhi/Multi_persistence/Box.h +171 -171
  43. multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -282
  44. multipers/gudhi/gudhi/Off_reader.h +173 -173
  45. multipers/gudhi/gudhi/One_critical_filtration.h +1432 -1431
  46. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -769
  47. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -686
  48. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -842
  49. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -1350
  50. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -1105
  51. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -859
  52. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -910
  53. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -139
  54. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -230
  55. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -211
  56. multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -60
  57. multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -60
  58. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -136
  59. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -190
  60. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -616
  61. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -150
  62. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -106
  63. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -219
  64. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -327
  65. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -1140
  66. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -934
  67. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -934
  68. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -980
  69. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -1092
  70. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -192
  71. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -921
  72. multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -1093
  73. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -1012
  74. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -1244
  75. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -186
  76. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -164
  77. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -156
  78. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -376
  79. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -540
  80. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -118
  81. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -173
  82. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -128
  83. multipers/gudhi/gudhi/Persistent_cohomology.h +745 -745
  84. multipers/gudhi/gudhi/Points_off_io.h +171 -171
  85. multipers/gudhi/gudhi/Simple_object_pool.h +69 -69
  86. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -463
  87. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -83
  88. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -106
  89. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -277
  90. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -62
  91. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -27
  92. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -62
  93. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -157
  94. multipers/gudhi/gudhi/Simplex_tree.h +2794 -2794
  95. multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -163
  96. multipers/gudhi/gudhi/distance_functions.h +62 -62
  97. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -104
  98. multipers/gudhi/gudhi/persistence_interval.h +253 -253
  99. multipers/gudhi/gudhi/persistence_matrix_options.h +170 -170
  100. multipers/gudhi/gudhi/reader_utils.h +367 -367
  101. multipers/gudhi/mma_interface_coh.h +256 -255
  102. multipers/gudhi/mma_interface_h0.h +223 -231
  103. multipers/gudhi/mma_interface_matrix.h +284 -282
  104. multipers/gudhi/naive_merge_tree.h +536 -575
  105. multipers/gudhi/scc_io.h +310 -289
  106. multipers/gudhi/truc.h +890 -888
  107. multipers/io.cp311-win_amd64.pyd +0 -0
  108. multipers/io.pyx +711 -711
  109. multipers/ml/accuracies.py +90 -90
  110. multipers/ml/convolutions.py +520 -520
  111. multipers/ml/invariants_with_persistable.py +79 -79
  112. multipers/ml/kernels.py +176 -176
  113. multipers/ml/mma.py +713 -714
  114. multipers/ml/one.py +472 -472
  115. multipers/ml/point_clouds.py +352 -346
  116. multipers/ml/signed_measures.py +1589 -1589
  117. multipers/ml/sliced_wasserstein.py +461 -461
  118. multipers/ml/tools.py +113 -113
  119. multipers/mma_structures.cp311-win_amd64.pyd +0 -0
  120. multipers/mma_structures.pxd +127 -127
  121. multipers/mma_structures.pyx +4 -4
  122. multipers/mma_structures.pyx.tp +1085 -1085
  123. multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -93
  124. multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -97
  125. multipers/multi_parameter_rank_invariant/function_rips.h +322 -322
  126. multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -769
  127. multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -148
  128. multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -369
  129. multipers/multiparameter_edge_collapse.py +41 -41
  130. multipers/multiparameter_module_approximation/approximation.h +2296 -2295
  131. multipers/multiparameter_module_approximation/combinatory.h +129 -129
  132. multipers/multiparameter_module_approximation/debug.h +107 -107
  133. multipers/multiparameter_module_approximation/format_python-cpp.h +286 -286
  134. multipers/multiparameter_module_approximation/heap_column.h +238 -238
  135. multipers/multiparameter_module_approximation/images.h +79 -79
  136. multipers/multiparameter_module_approximation/list_column.h +174 -174
  137. multipers/multiparameter_module_approximation/list_column_2.h +232 -232
  138. multipers/multiparameter_module_approximation/ru_matrix.h +347 -347
  139. multipers/multiparameter_module_approximation/set_column.h +135 -135
  140. multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -36
  141. multipers/multiparameter_module_approximation/unordered_set_column.h +166 -166
  142. multipers/multiparameter_module_approximation/utilities.h +403 -419
  143. multipers/multiparameter_module_approximation/vector_column.h +223 -223
  144. multipers/multiparameter_module_approximation/vector_matrix.h +331 -331
  145. multipers/multiparameter_module_approximation/vineyards.h +464 -464
  146. multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -649
  147. multipers/multiparameter_module_approximation.cp311-win_amd64.pyd +0 -0
  148. multipers/multiparameter_module_approximation.pyx +216 -217
  149. multipers/pickle.py +90 -53
  150. multipers/plots.py +342 -334
  151. multipers/point_measure.cp311-win_amd64.pyd +0 -0
  152. multipers/point_measure.pyx +322 -320
  153. multipers/simplex_tree_multi.cp311-win_amd64.pyd +0 -0
  154. multipers/simplex_tree_multi.pxd +133 -133
  155. multipers/simplex_tree_multi.pyx +18 -15
  156. multipers/simplex_tree_multi.pyx.tp +1939 -1935
  157. multipers/slicer.cp311-win_amd64.pyd +0 -0
  158. multipers/slicer.pxd +81 -20
  159. multipers/slicer.pxd.tp +215 -214
  160. multipers/slicer.pyx +1091 -308
  161. multipers/slicer.pyx.tp +924 -914
  162. multipers/tensor/tensor.h +672 -672
  163. multipers/tensor.pxd +13 -13
  164. multipers/test.pyx +44 -44
  165. multipers/tests/__init__.py +57 -57
  166. multipers/torch/diff_grids.py +217 -217
  167. multipers/torch/rips_density.py +310 -304
  168. {multipers-2.2.3.dist-info → multipers-2.3.0.dist-info}/LICENSE +21 -21
  169. {multipers-2.2.3.dist-info → multipers-2.3.0.dist-info}/METADATA +21 -11
  170. multipers-2.3.0.dist-info/RECORD +182 -0
  171. multipers/tests/test_diff_helper.py +0 -73
  172. multipers/tests/test_hilbert_function.py +0 -82
  173. multipers/tests/test_mma.py +0 -83
  174. multipers/tests/test_point_clouds.py +0 -49
  175. multipers/tests/test_python-cpp_conversion.py +0 -82
  176. multipers/tests/test_signed_betti.py +0 -181
  177. multipers/tests/test_signed_measure.py +0 -89
  178. multipers/tests/test_simplextreemulti.py +0 -221
  179. multipers/tests/test_slicer.py +0 -221
  180. multipers-2.2.3.dist-info/RECORD +0 -189
  181. {multipers-2.2.3.dist-info → multipers-2.3.0.dist-info}/WHEEL +0 -0
  182. {multipers-2.2.3.dist-info → multipers-2.3.0.dist-info}/top_level.txt +0 -0
@@ -1,1244 +1,1244 @@
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 vector_column.h
13
- * @author Hannah Schreiber
14
- * @brief Contains the @ref Gudhi::persistence_matrix::Vector_column class.
15
- * Also defines the std::hash method for @ref Gudhi::persistence_matrix::Vector_column.
16
- */
17
-
18
- #ifndef PM_VECTOR_COLUMN_H
19
- #define PM_VECTOR_COLUMN_H
20
-
21
- #include <cstddef>
22
- #include <vector>
23
- #include <stdexcept>
24
- #include <type_traits>
25
- #include <algorithm> //binary_search
26
- #include <unordered_set>
27
- #include <utility> //std::swap, std::move & std::exchange
28
-
29
- #include <boost/iterator/indirect_iterator.hpp>
30
- #include <gudhi/Persistence_matrix/columns/column_utilities.h>
31
-
32
- namespace Gudhi {
33
- namespace persistence_matrix {
34
-
35
- /**
36
- * @class Vector_column vector_column.h gudhi/Persistence_matrix/columns/vector_column.h
37
- * @ingroup persistence_matrix
38
- *
39
- * @brief Column class following the @ref PersistenceMatrixColumn concept.
40
- *
41
- * Column based on a vector structure. The entries are always ordered by row index, but entries are removed by
42
- * @ref PersistenceMatrixColumn::clear(PersistenceMatrixOptions::Index rowIndex) "clear(Index)" in a lazy way,
43
- * so erased values can still be in the underlying container.
44
- * On the other hand, two entries will never have the same row index.
45
- *
46
- * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced.
47
- * @tparam Entry_constructor Factory of @ref Entry classes.
48
- */
49
- template <class Master_matrix>
50
- class Vector_column : public Master_matrix::Row_access_option,
51
- public Master_matrix::Column_dimension_option,
52
- public Master_matrix::Chain_column_option
53
- {
54
- public:
55
- using Master = Master_matrix;
56
- using Index = typename Master_matrix::Index;
57
- using ID_index = typename Master_matrix::ID_index;
58
- using Dimension = typename Master_matrix::Dimension;
59
- using Field_element = typename Master_matrix::Element;
60
- using Entry = typename Master_matrix::Matrix_entry;
61
- using Column_settings = typename Master_matrix::Column_settings;
62
-
63
- private:
64
- using Field_operators = typename Master_matrix::Field_operators;
65
- using Column_support = std::vector<Entry*>;
66
- using Entry_constructor = typename Master_matrix::Entry_constructor;
67
-
68
- public:
69
- using iterator = boost::indirect_iterator<typename Column_support::iterator>;
70
- using const_iterator = boost::indirect_iterator<typename Column_support::const_iterator>;
71
- using reverse_iterator = boost::indirect_iterator<typename Column_support::reverse_iterator>;
72
- using const_reverse_iterator = boost::indirect_iterator<typename Column_support::const_reverse_iterator>;
73
-
74
- Vector_column(Column_settings* colSettings = nullptr);
75
- template <class Container = typename Master_matrix::Boundary>
76
- Vector_column(const Container& nonZeroRowIndices, Column_settings* colSettings);
77
- template <class Container = typename Master_matrix::Boundary, class Row_container>
78
- Vector_column(Index columnIndex,
79
- const Container& nonZeroRowIndices,
80
- Row_container* rowContainer,
81
- Column_settings* colSettings);
82
- template <class Container = typename Master_matrix::Boundary>
83
- Vector_column(const Container& nonZeroChainRowIndices, Dimension dimension, Column_settings* colSettings);
84
- template <class Container = typename Master_matrix::Boundary, class Row_container>
85
- Vector_column(Index columnIndex,
86
- const Container& nonZeroChainRowIndices,
87
- Dimension dimension,
88
- Row_container* rowContainer,
89
- Column_settings* colSettings);
90
- Vector_column(const Vector_column& column, Column_settings* colSettings = nullptr);
91
- template <class Row_container>
92
- Vector_column(const Vector_column& column,
93
- Index columnIndex,
94
- Row_container* rowContainer,
95
- Column_settings* colSettings = nullptr);
96
- Vector_column(Vector_column&& column) noexcept;
97
- ~Vector_column();
98
-
99
- std::vector<Field_element> get_content(int columnLength = -1) const;
100
- bool is_non_zero(ID_index rowIndex) const;
101
- bool is_empty() const;
102
- std::size_t size() const;
103
-
104
- template <class Row_index_map>
105
- void reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex = -1);
106
- void clear();
107
- // do not clear an entry to 0 if the entry was already 0, otherwise size/is_empty will be wrong.
108
- void clear(ID_index rowIndex);
109
-
110
- ID_index get_pivot();
111
- Field_element get_pivot_value();
112
-
113
- iterator begin() noexcept;
114
- const_iterator begin() const noexcept;
115
- iterator end() noexcept;
116
- const_iterator end() const noexcept;
117
- reverse_iterator rbegin() noexcept;
118
- const_reverse_iterator rbegin() const noexcept;
119
- reverse_iterator rend() noexcept;
120
- const_reverse_iterator rend() const noexcept;
121
-
122
- template <class Entry_range>
123
- Vector_column& operator+=(const Entry_range& column);
124
- Vector_column& operator+=(Vector_column& column);
125
-
126
- Vector_column& operator*=(unsigned int v);
127
-
128
- // this = v * this + column
129
- template <class Entry_range>
130
- Vector_column& multiply_target_and_add(const Field_element& val, const Entry_range& column);
131
- Vector_column& multiply_target_and_add(const Field_element& val, Vector_column& column);
132
- // this = this + column * v
133
- template <class Entry_range>
134
- Vector_column& multiply_source_and_add(const Entry_range& column, const Field_element& val);
135
- Vector_column& multiply_source_and_add(Vector_column& column, const Field_element& val);
136
-
137
- void push_back(const Entry& entry);
138
-
139
- std::size_t compute_hash_value();
140
-
141
- friend bool operator==(const Vector_column& c1, const Vector_column& c2) {
142
- if (&c1 == &c2) return true;
143
- if (c1.erasedValues_.empty() && c2.erasedValues_.empty() && c1.column_.size() != c2.column_.size()) return false;
144
-
145
- auto it1 = c1.column_.begin();
146
- auto it2 = c2.column_.begin();
147
- while (it1 != c1.column_.end() && it2 != c2.column_.end()) {
148
- if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
149
- while (it1 != c1.column_.end() && c1.erasedValues_.find((*it1)->get_row_index()) != c1.erasedValues_.end())
150
- ++it1;
151
- while (it2 != c2.column_.end() && c2.erasedValues_.find((*it2)->get_row_index()) != c2.erasedValues_.end())
152
- ++it2;
153
- if (it1 == c1.column_.end() || it2 == c2.column_.end()) break;
154
- }
155
- if constexpr (Master_matrix::Option_list::is_z2) {
156
- if ((*it1)->get_row_index() != (*it2)->get_row_index()) return false;
157
- } else {
158
- if ((*it1)->get_row_index() != (*it2)->get_row_index() || (*it1)->get_element() != (*it2)->get_element())
159
- return false;
160
- }
161
- ++it1;
162
- ++it2;
163
- }
164
-
165
- if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
166
- while (it1 != c1.column_.end() && c1.erasedValues_.find((*it1)->get_row_index()) != c1.erasedValues_.end()) ++it1;
167
- while (it2 != c2.column_.end() && c2.erasedValues_.find((*it2)->get_row_index()) != c2.erasedValues_.end()) ++it2;
168
- return it2 == c2.column_.end() && it1 == c1.column_.end();
169
- } else {
170
- return true;
171
- }
172
- }
173
- friend bool operator<(const Vector_column& c1, const Vector_column& c2) {
174
- if (&c1 == &c2) return false;
175
-
176
- auto it1 = c1.column_.begin();
177
- auto it2 = c2.column_.begin();
178
- while (it1 != c1.column_.end() && it2 != c2.column_.end()) {
179
- if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
180
- while (it1 != c1.column_.end() && c1.erasedValues_.find((*it1)->get_row_index()) != c1.erasedValues_.end())
181
- ++it1;
182
- while (it2 != c2.column_.end() && c2.erasedValues_.find((*it2)->get_row_index()) != c2.erasedValues_.end())
183
- ++it2;
184
- if (it1 == c1.column_.end() || it2 == c2.column_.end()) break;
185
- }
186
-
187
- if ((*it1)->get_row_index() != (*it2)->get_row_index()) return (*it1)->get_row_index() < (*it2)->get_row_index();
188
- if constexpr (!Master_matrix::Option_list::is_z2) {
189
- if ((*it1)->get_element() != (*it2)->get_element()) return (*it1)->get_element() < (*it2)->get_element();
190
- }
191
- ++it1;
192
- ++it2;
193
- }
194
- if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
195
- while (it1 != c1.column_.end() && c1.erasedValues_.find((*it1)->get_row_index()) != c1.erasedValues_.end()) ++it1;
196
- while (it2 != c2.column_.end() && c2.erasedValues_.find((*it2)->get_row_index()) != c2.erasedValues_.end()) ++it2;
197
- }
198
- return it2 != c2.column_.end();
199
- }
200
-
201
- // Disabled with row access.
202
- Vector_column& operator=(const Vector_column& other);
203
-
204
- friend void swap(Vector_column& col1, Vector_column& col2) {
205
- swap(static_cast<typename Master_matrix::Row_access_option&>(col1),
206
- static_cast<typename Master_matrix::Row_access_option&>(col2));
207
- swap(static_cast<typename Master_matrix::Column_dimension_option&>(col1),
208
- static_cast<typename Master_matrix::Column_dimension_option&>(col2));
209
- swap(static_cast<typename Master_matrix::Chain_column_option&>(col1),
210
- static_cast<typename Master_matrix::Chain_column_option&>(col2));
211
- col1.column_.swap(col2.column_);
212
- col1.erasedValues_.swap(col2.erasedValues_);
213
- std::swap(col1.operators_, col2.operators_);
214
- std::swap(col1.entryPool_, col2.entryPool_);
215
- }
216
-
217
- private:
218
- using RA_opt = typename Master_matrix::Row_access_option;
219
- using Dim_opt = typename Master_matrix::Column_dimension_option;
220
- using Chain_opt = typename Master_matrix::Chain_column_option;
221
-
222
- Column_support column_;
223
- std::unordered_set<ID_index> erasedValues_; // TODO: test other containers? Useless when clear(Index) is never
224
- // called, how much is it worth it?
225
- Field_operators* operators_;
226
- Entry_constructor* entryPool_;
227
-
228
- template <class Column, class Entry_iterator, typename F1, typename F2, typename F3, typename F4>
229
- friend void _generic_merge_entry_to_column(Column& targetColumn,
230
- Entry_iterator& itSource,
231
- typename Column::Column_support::iterator& itTarget,
232
- F1&& process_target,
233
- F2&& process_source,
234
- F3&& update_target1,
235
- F4&& update_target2,
236
- bool& pivotIsZeroed);
237
-
238
- void _delete_entry(Entry* entry);
239
- void _delete_entry(typename Column_support::iterator& it);
240
- Entry* _insert_entry(const Field_element& value, ID_index rowIndex, Column_support& column);
241
- void _insert_entry(ID_index rowIndex, Column_support& column);
242
- void _update_entry(const Field_element& value, ID_index rowIndex, Index position);
243
- void _update_entry(ID_index rowIndex, Index position);
244
- template <class Entry_range>
245
- bool _add(const Entry_range& column);
246
- template <class Entry_range>
247
- bool _multiply_target_and_add(const Field_element& val, const Entry_range& column);
248
- template <class Entry_range>
249
- bool _multiply_source_and_add(const Entry_range& column, const Field_element& val);
250
- template <class Entry_range, typename F1, typename F2, typename F3, typename F4>
251
- bool _generic_add(const Entry_range& source,
252
- F1&& process_target,
253
- F2&& process_source,
254
- F3&& update_target1,
255
- F4&& update_target2);
256
- };
257
-
258
- template <class Master_matrix>
259
- inline Vector_column<Master_matrix>::Vector_column(Column_settings* colSettings)
260
- : RA_opt(),
261
- Dim_opt(),
262
- Chain_opt(),
263
- operators_(nullptr),
264
- entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor))
265
- {
266
- if (operators_ == nullptr && entryPool_ == nullptr) return; // to allow default constructor which gives a dummy column
267
- if constexpr (!Master_matrix::Option_list::is_z2) {
268
- operators_ = &(colSettings->operators);
269
- }
270
- }
271
-
272
- template <class Master_matrix>
273
- template <class Container>
274
- inline Vector_column<Master_matrix>::Vector_column(const Container& nonZeroRowIndices, Column_settings* colSettings)
275
- : RA_opt(),
276
- Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1),
277
- Chain_opt(),
278
- column_(nonZeroRowIndices.size(), nullptr),
279
- operators_(nullptr),
280
- entryPool_(&(colSettings->entryConstructor))
281
- {
282
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
283
- "Constructor not available for chain columns, please specify the dimension of the chain.");
284
-
285
- if constexpr (!Master_matrix::Option_list::is_z2) {
286
- operators_ = &(colSettings->operators);
287
- }
288
-
289
- Index i = 0;
290
- if constexpr (Master_matrix::Option_list::is_z2) {
291
- for (ID_index id : nonZeroRowIndices) {
292
- _update_entry(id, i++);
293
- }
294
- } else {
295
- for (const auto& p : nonZeroRowIndices) {
296
- _update_entry(operators_->get_value(p.second), p.first, i++);
297
- }
298
- }
299
- }
300
-
301
- template <class Master_matrix>
302
- template <class Container, class Row_container>
303
- inline Vector_column<Master_matrix>::Vector_column(Index columnIndex,
304
- const Container& nonZeroRowIndices,
305
- Row_container* rowContainer,
306
- Column_settings* colSettings)
307
- : RA_opt(columnIndex, rowContainer),
308
- Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1),
309
- Chain_opt([&] {
310
- if constexpr (Master_matrix::Option_list::is_z2) {
311
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
312
- } else {
313
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
314
- }
315
- }()),
316
- column_(nonZeroRowIndices.size(), nullptr),
317
- operators_(nullptr),
318
- entryPool_(&(colSettings->entryConstructor))
319
- {
320
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
321
- "Constructor not available for chain columns, please specify the dimension of the chain.");
322
-
323
- if constexpr (!Master_matrix::Option_list::is_z2) {
324
- operators_ = &(colSettings->operators);
325
- }
326
-
327
- Index i = 0;
328
- if constexpr (Master_matrix::Option_list::is_z2) {
329
- for (ID_index id : nonZeroRowIndices) {
330
- _update_entry(id, i++);
331
- }
332
- } else {
333
- for (const auto& p : nonZeroRowIndices) {
334
- _update_entry(operators_->get_value(p.second), p.first, i++);
335
- }
336
- }
337
- }
338
-
339
- template <class Master_matrix>
340
- template <class Container>
341
- inline Vector_column<Master_matrix>::Vector_column(const Container& nonZeroRowIndices,
342
- Dimension dimension,
343
- Column_settings* colSettings)
344
- : RA_opt(),
345
- Dim_opt(dimension),
346
- Chain_opt([&] {
347
- if constexpr (Master_matrix::Option_list::is_z2) {
348
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
349
- } else {
350
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
351
- }
352
- }()),
353
- column_(nonZeroRowIndices.size(), nullptr),
354
- operators_(nullptr),
355
- entryPool_(&(colSettings->entryConstructor))
356
- {
357
- if constexpr (!Master_matrix::Option_list::is_z2) {
358
- operators_ = &(colSettings->operators);
359
- }
360
-
361
- Index i = 0;
362
- if constexpr (Master_matrix::Option_list::is_z2) {
363
- for (ID_index id : nonZeroRowIndices) {
364
- _update_entry(id, i++);
365
- }
366
- } else {
367
- for (const auto& p : nonZeroRowIndices) {
368
- _update_entry(operators_->get_value(p.second), p.first, i++);
369
- }
370
- }
371
- }
372
-
373
- template <class Master_matrix>
374
- template <class Container, class Row_container>
375
- inline Vector_column<Master_matrix>::Vector_column(Index columnIndex,
376
- const Container& nonZeroRowIndices,
377
- Dimension dimension,
378
- Row_container* rowContainer,
379
- Column_settings* colSettings)
380
- : RA_opt(columnIndex, rowContainer),
381
- Dim_opt(dimension),
382
- Chain_opt([&] {
383
- if constexpr (Master_matrix::Option_list::is_z2) {
384
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
385
- } else {
386
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
387
- }
388
- }()),
389
- column_(nonZeroRowIndices.size(), nullptr),
390
- operators_(nullptr),
391
- entryPool_(&(colSettings->entryConstructor))
392
- {
393
- if constexpr (!Master_matrix::Option_list::is_z2) {
394
- operators_ = &(colSettings->operators);
395
- }
396
-
397
- Index i = 0;
398
- if constexpr (Master_matrix::Option_list::is_z2) {
399
- for (ID_index id : nonZeroRowIndices) {
400
- _update_entry(id, i++);
401
- }
402
- } else {
403
- for (const auto& p : nonZeroRowIndices) {
404
- _update_entry(operators_->get_value(p.second), p.first, i++);
405
- }
406
- }
407
- }
408
-
409
- template <class Master_matrix>
410
- inline Vector_column<Master_matrix>::Vector_column(const Vector_column& column, Column_settings* colSettings)
411
- : RA_opt(),
412
- Dim_opt(static_cast<const Dim_opt&>(column)),
413
- Chain_opt(static_cast<const Chain_opt&>(column)),
414
- column_(column.column_.size(), nullptr),
415
- erasedValues_(column.erasedValues_),
416
- operators_(colSettings == nullptr ? column.operators_ : nullptr),
417
- entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
418
- {
419
- static_assert(!Master_matrix::Option_list::has_row_access,
420
- "Simple copy constructor not available when row access option enabled. Please specify the new column "
421
- "index and the row container.");
422
-
423
- if constexpr (!Master_matrix::Option_list::is_z2) {
424
- if (colSettings != nullptr) operators_ = &(colSettings->operators);
425
- }
426
-
427
- Index i = 0;
428
- for (const Entry* entry : column.column_) {
429
- if constexpr (Master_matrix::Option_list::is_z2) {
430
- _update_entry(entry->get_row_index(), i++);
431
- } else {
432
- _update_entry(entry->get_element(), entry->get_row_index(), i++);
433
- }
434
- }
435
- }
436
-
437
- template <class Master_matrix>
438
- template <class Row_container>
439
- inline Vector_column<Master_matrix>::Vector_column(const Vector_column& column,
440
- Index columnIndex,
441
- Row_container* rowContainer,
442
- Column_settings* colSettings)
443
- : RA_opt(columnIndex, rowContainer),
444
- Dim_opt(static_cast<const Dim_opt&>(column)),
445
- Chain_opt(static_cast<const Chain_opt&>(column)),
446
- column_(column.column_.size(), nullptr),
447
- erasedValues_(column.erasedValues_),
448
- operators_(colSettings == nullptr ? column.operators_ : nullptr),
449
- entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
450
- {
451
- if constexpr (!Master_matrix::Option_list::is_z2) {
452
- if (colSettings != nullptr) operators_ = &(colSettings->operators);
453
- }
454
-
455
- Index i = 0;
456
- for (const Entry* entry : column.column_) {
457
- if constexpr (Master_matrix::Option_list::is_z2) {
458
- _update_entry(entry->get_row_index(), i++);
459
- } else {
460
- _update_entry(entry->get_element(), entry->get_row_index(), i++);
461
- }
462
- }
463
- }
464
-
465
- template <class Master_matrix>
466
- inline Vector_column<Master_matrix>::Vector_column(Vector_column&& column) noexcept
467
- : RA_opt(std::move(static_cast<RA_opt&>(column))),
468
- Dim_opt(std::move(static_cast<Dim_opt&>(column))),
469
- Chain_opt(std::move(static_cast<Chain_opt&>(column))),
470
- column_(std::move(column.column_)),
471
- erasedValues_(std::move(column.erasedValues_)),
472
- operators_(std::exchange(column.operators_, nullptr)),
473
- entryPool_(std::exchange(column.entryPool_, nullptr))
474
- {}
475
-
476
- template <class Master_matrix>
477
- inline Vector_column<Master_matrix>::~Vector_column()
478
- {
479
- for (auto* entry : column_) {
480
- _delete_entry(entry);
481
- }
482
- }
483
-
484
- template <class Master_matrix>
485
- inline std::vector<typename Vector_column<Master_matrix>::Field_element> Vector_column<Master_matrix>::get_content(
486
- int columnLength) const
487
- {
488
- if (columnLength < 0 && column_.size() > 0)
489
- columnLength = column_.back()->get_row_index() + 1;
490
- else if (columnLength < 0)
491
- return std::vector<Field_element>();
492
-
493
- std::vector<Field_element> container(columnLength, 0);
494
- for (auto it = column_.begin(); it != column_.end() && (*it)->get_row_index() < static_cast<ID_index>(columnLength);
495
- ++it) {
496
- if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
497
- if (erasedValues_.find((*it)->get_row_index()) != erasedValues_.end()) continue;
498
- }
499
- if constexpr (Master_matrix::Option_list::is_z2) {
500
- container[(*it)->get_row_index()] = 1;
501
- } else {
502
- container[(*it)->get_row_index()] = (*it)->get_element();
503
- }
504
- }
505
- return container;
506
- }
507
-
508
- template <class Master_matrix>
509
- inline bool Vector_column<Master_matrix>::is_non_zero(ID_index rowIndex) const
510
- {
511
- if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type)
512
- if (erasedValues_.find(rowIndex) != erasedValues_.end()) return false;
513
-
514
- Entry entry(rowIndex);
515
- return std::binary_search(column_.begin(), column_.end(), &entry,
516
- [](const Entry* a, const Entry* b) { return a->get_row_index() < b->get_row_index(); });
517
- }
518
-
519
- template <class Master_matrix>
520
- inline bool Vector_column<Master_matrix>::is_empty() const
521
- {
522
- if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
523
- return column_.size() == erasedValues_.size(); // assumes that erasedValues is always a subset of column_, which is
524
- // wrong if someone cleared an non existing value...
525
- } else {
526
- return column_.empty();
527
- }
528
- }
529
-
530
- template <class Master_matrix>
531
- inline std::size_t Vector_column<Master_matrix>::size() const
532
- {
533
- if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
534
- return column_.size() - erasedValues_.size(); // assumes that erasedValues is always a subset of column_, which is
535
- // wrong if someone cleared an non existing value...
536
- } else {
537
- return column_.size();
538
- }
539
- }
540
-
541
- template <class Master_matrix>
542
- template <class Row_index_map>
543
- inline void Vector_column<Master_matrix>::reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex)
544
- {
545
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
546
- "Method not available for chain columns.");
547
-
548
- if (erasedValues_.empty()) { // to avoid useless push_backs.
549
- for (Entry* entry : column_) {
550
- if constexpr (Master_matrix::Option_list::has_row_access) {
551
- RA_opt::unlink(entry);
552
- if (columnIndex != static_cast<Index>(-1)) entry->set_column_index(columnIndex);
553
- }
554
- entry->set_row_index(valueMap.at(entry->get_row_index()));
555
- if constexpr (Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access)
556
- RA_opt::insert_entry(entry->get_row_index(), entry);
557
- }
558
-
559
- // all entries have to be deleted first, to avoid problem with insertion when row is a set
560
- if constexpr (!Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) {
561
- for (Entry* entry : column_) {
562
- RA_opt::insert_entry(entry->get_row_index(), entry);
563
- }
564
- }
565
-
566
- std::sort(column_.begin(), column_.end(), [](const Entry* c1, const Entry* c2) { return *c1 < *c2; });
567
- } else {
568
- Column_support newColumn;
569
- for (Entry* entry : column_) {
570
- if (erasedValues_.find(entry->get_row_index()) == erasedValues_.end()) {
571
- if constexpr (Master_matrix::Option_list::has_row_access) {
572
- RA_opt::unlink(entry);
573
- if (columnIndex != static_cast<Index>(-1)) entry->set_column_index(columnIndex);
574
- }
575
- entry->set_row_index(valueMap.at(entry->get_row_index()));
576
- newColumn.push_back(entry);
577
- if constexpr (Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access)
578
- RA_opt::insert_entry(entry->get_row_index(), entry);
579
- } else {
580
- _delete_entry(entry);
581
- }
582
- }
583
- // all entries have to be deleted first, to avoid problem with insertion when row is a set
584
- if constexpr (!Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) {
585
- for (Entry* entry : column_) {
586
- RA_opt::insert_entry(entry->get_row_index(), entry);
587
- }
588
- }
589
- std::sort(newColumn.begin(), newColumn.end(), [](const Entry* c1, const Entry* c2) { return *c1 < *c2; });
590
- erasedValues_.clear();
591
- column_.swap(newColumn);
592
- }
593
- }
594
-
595
- template <class Master_matrix>
596
- inline void Vector_column<Master_matrix>::clear()
597
- {
598
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
599
- "Method not available for chain columns as a base element should not be empty.");
600
-
601
- for (auto* entry : column_) {
602
- if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
603
- entryPool_->destroy(entry);
604
- }
605
-
606
- column_.clear();
607
- erasedValues_.clear();
608
- }
609
-
610
- template <class Master_matrix>
611
- inline void Vector_column<Master_matrix>::clear(ID_index rowIndex)
612
- {
613
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
614
- "Method not available for chain columns.");
615
-
616
- erasedValues_.insert(rowIndex);
617
- }
618
-
619
- template <class Master_matrix>
620
- inline typename Vector_column<Master_matrix>::ID_index Vector_column<Master_matrix>::get_pivot()
621
- {
622
- static_assert(Master_matrix::isNonBasic,
623
- "Method not available for base columns."); // could technically be, but is the notion useful then?
624
-
625
- if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
626
- if (column_.empty()) return -1;
627
- if (erasedValues_.empty()) return column_.back()->get_row_index();
628
-
629
- auto it = erasedValues_.find(column_.back()->get_row_index());
630
- while (!column_.empty() && it != erasedValues_.end()) {
631
- erasedValues_.erase(it);
632
- _delete_entry(column_.back());
633
- column_.pop_back();
634
- if (!column_.empty()) it = erasedValues_.find(column_.back()->get_row_index());
635
- }
636
-
637
- if (column_.empty()) return -1;
638
- return column_.back()->get_row_index();
639
- } else {
640
- return Chain_opt::get_pivot();
641
- }
642
- }
643
-
644
- template <class Master_matrix>
645
- inline typename Vector_column<Master_matrix>::Field_element Vector_column<Master_matrix>::get_pivot_value()
646
- {
647
- static_assert(Master_matrix::isNonBasic,
648
- "Method not available for base columns."); // could technically be, but is the notion useful then?
649
-
650
- if constexpr (Master_matrix::Option_list::is_z2) {
651
- return 1;
652
- } else {
653
- if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
654
- if (column_.empty()) return 0;
655
- if (erasedValues_.empty()) return column_.back()->get_element();
656
-
657
- auto it = erasedValues_.find(column_.back()->get_row_index());
658
- while (!column_.empty() && it != erasedValues_.end()) {
659
- erasedValues_.erase(it);
660
- _delete_entry(column_.back());
661
- column_.pop_back();
662
- if (!column_.empty()) it = erasedValues_.find(column_.back()->get_row_index());
663
- }
664
-
665
- if (column_.empty()) return 0;
666
- return column_.back()->get_element();
667
- } else {
668
- if (Chain_opt::get_pivot() == static_cast<ID_index>(-1)) return Field_element();
669
- for (const Entry* entry : column_) {
670
- if (entry->get_row_index() == Chain_opt::get_pivot()) return entry->get_element();
671
- }
672
- return Field_element(); // should never happen if chain column is used properly
673
- }
674
- }
675
- }
676
-
677
- template <class Master_matrix>
678
- inline typename Vector_column<Master_matrix>::iterator Vector_column<Master_matrix>::begin() noexcept
679
- {
680
- return column_.begin();
681
- }
682
-
683
- template <class Master_matrix>
684
- inline typename Vector_column<Master_matrix>::const_iterator Vector_column<Master_matrix>::begin() const noexcept
685
- {
686
- return column_.begin();
687
- }
688
-
689
- template <class Master_matrix>
690
- inline typename Vector_column<Master_matrix>::iterator Vector_column<Master_matrix>::end() noexcept
691
- {
692
- return column_.end();
693
- }
694
-
695
- template <class Master_matrix>
696
- inline typename Vector_column<Master_matrix>::const_iterator Vector_column<Master_matrix>::end() const noexcept
697
- {
698
- return column_.end();
699
- }
700
-
701
- template <class Master_matrix>
702
- inline typename Vector_column<Master_matrix>::reverse_iterator Vector_column<Master_matrix>::rbegin() noexcept
703
- {
704
- return column_.rbegin();
705
- }
706
-
707
- template <class Master_matrix>
708
- inline typename Vector_column<Master_matrix>::const_reverse_iterator Vector_column<Master_matrix>::rbegin()
709
- const noexcept
710
- {
711
- return column_.rbegin();
712
- }
713
-
714
- template <class Master_matrix>
715
- inline typename Vector_column<Master_matrix>::reverse_iterator Vector_column<Master_matrix>::rend() noexcept
716
- {
717
- return column_.rend();
718
- }
719
-
720
- template <class Master_matrix>
721
- inline typename Vector_column<Master_matrix>::const_reverse_iterator Vector_column<Master_matrix>::rend()
722
- const noexcept
723
- {
724
- return column_.rend();
725
- }
726
-
727
- template <class Master_matrix>
728
- template <class Entry_range>
729
- inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::operator+=(const Entry_range& column)
730
- {
731
- static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Vector_column>),
732
- "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
733
- "base element."); // could be removed, if we give the responsibility to the user.
734
- static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
735
- "For chain columns, the given column cannot be constant.");
736
-
737
- _add(column);
738
-
739
- return *this;
740
- }
741
-
742
- template <class Master_matrix>
743
- inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::operator+=(Vector_column& column)
744
- {
745
- if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
746
- // assumes that the addition never zeros out this column.
747
- if (_add(column)) {
748
- Chain_opt::swap_pivots(column);
749
- Dim_opt::swap_dimension(column);
750
- }
751
- } else {
752
- _add(column);
753
- }
754
-
755
- return *this;
756
- }
757
-
758
- template <class Master_matrix>
759
- inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::operator*=(unsigned int v)
760
- {
761
- if constexpr (Master_matrix::Option_list::is_z2) {
762
- if (v % 2 == 0) {
763
- if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
764
- throw std::invalid_argument("A chain column should not be multiplied by 0.");
765
- } else {
766
- clear();
767
- }
768
- }
769
- } else {
770
- Field_element val = operators_->get_value(v);
771
-
772
- if (val == Field_operators::get_additive_identity()) {
773
- if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
774
- throw std::invalid_argument("A chain column should not be multiplied by 0.");
775
- } else {
776
- clear();
777
- }
778
- return *this;
779
- }
780
-
781
- if (val == Field_operators::get_multiplicative_identity()) return *this;
782
-
783
- for (Entry* entry : column_) {
784
- operators_->multiply_inplace(entry->get_element(), val);
785
- if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entry);
786
- }
787
- }
788
-
789
- return *this;
790
- }
791
-
792
- template <class Master_matrix>
793
- template <class Entry_range>
794
- inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::multiply_target_and_add(const Field_element& val,
795
- const Entry_range& column)
796
- {
797
- static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Vector_column>),
798
- "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
799
- "base element."); // could be removed, if we give the responsibility to the user.
800
- static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
801
- "For chain columns, the given column cannot be constant.");
802
-
803
- if constexpr (Master_matrix::Option_list::is_z2) {
804
- if (val) {
805
- _add(column);
806
- } else {
807
- clear();
808
- _add(column);
809
- }
810
- } else {
811
- _multiply_target_and_add(val, column);
812
- }
813
-
814
- return *this;
815
- }
816
-
817
- template <class Master_matrix>
818
- inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::multiply_target_and_add(const Field_element& val,
819
- Vector_column& column)
820
- {
821
- if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
822
- // assumes that the addition never zeros out this column.
823
- if constexpr (Master_matrix::Option_list::is_z2) {
824
- if (val) {
825
- if (_add(column)) {
826
- Chain_opt::swap_pivots(column);
827
- Dim_opt::swap_dimension(column);
828
- }
829
- } else {
830
- throw std::invalid_argument("A chain column should not be multiplied by 0.");
831
- }
832
- } else {
833
- if (_multiply_target_and_add(val, column)) {
834
- Chain_opt::swap_pivots(column);
835
- Dim_opt::swap_dimension(column);
836
- }
837
- }
838
- } else {
839
- if constexpr (Master_matrix::Option_list::is_z2) {
840
- if (val) {
841
- _add(column);
842
- } else {
843
- clear();
844
- _add(column);
845
- }
846
- } else {
847
- _multiply_target_and_add(val, column);
848
- }
849
- }
850
-
851
- return *this;
852
- }
853
-
854
- template <class Master_matrix>
855
- template <class Entry_range>
856
- inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::multiply_source_and_add(const Entry_range& column,
857
- const Field_element& val)
858
- {
859
- static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Vector_column>),
860
- "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
861
- "base element."); // could be removed, if we give the responsibility to the user.
862
- static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
863
- "For chain columns, the given column cannot be constant.");
864
-
865
- if constexpr (Master_matrix::Option_list::is_z2) {
866
- if (val) {
867
- _add(column);
868
- }
869
- } else {
870
- _multiply_source_and_add(column, val);
871
- }
872
-
873
- return *this;
874
- }
875
-
876
- template <class Master_matrix>
877
- inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::multiply_source_and_add(Vector_column& column,
878
- const Field_element& val)
879
- {
880
- if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
881
- // assumes that the addition never zeros out this column.
882
- if constexpr (Master_matrix::Option_list::is_z2) {
883
- if (val) {
884
- if (_add(column)) {
885
- Chain_opt::swap_pivots(column);
886
- Dim_opt::swap_dimension(column);
887
- }
888
- }
889
- } else {
890
- if (_multiply_source_and_add(column, val)) {
891
- Chain_opt::swap_pivots(column);
892
- Dim_opt::swap_dimension(column);
893
- }
894
- }
895
- } else {
896
- if constexpr (Master_matrix::Option_list::is_z2) {
897
- if (val) {
898
- _add(column);
899
- }
900
- } else {
901
- _multiply_source_and_add(column, val);
902
- }
903
- }
904
-
905
- return *this;
906
- }
907
-
908
- template <class Master_matrix>
909
- inline void Vector_column<Master_matrix>::push_back(const Entry& entry)
910
- {
911
- static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices.");
912
-
913
- if constexpr (Master_matrix::Option_list::is_z2) {
914
- _insert_entry(entry.get_row_index(), column_);
915
- } else {
916
- _insert_entry(entry.get_element(), entry.get_row_index(), column_);
917
- }
918
- }
919
-
920
- template <class Master_matrix>
921
- inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::operator=(const Vector_column& other)
922
- {
923
- static_assert(!Master_matrix::Option_list::has_row_access, "= assignment not enabled with row access option.");
924
-
925
- Dim_opt::operator=(other);
926
- Chain_opt::operator=(other);
927
-
928
- auto tmpPool = entryPool_;
929
- entryPool_ = other.entryPool_;
930
-
931
- while (column_.size() > other.column_.size()) {
932
- if (column_.back() != nullptr) {
933
- if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(column_.back());
934
- tmpPool->destroy(column_.back());
935
- }
936
- column_.pop_back();
937
- }
938
-
939
- column_.resize(other.column_.size(), nullptr);
940
- Index i = 0;
941
- for (const Entry* entry : other.column_) {
942
- if (column_[i] != nullptr) {
943
- if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(column_[i]);
944
- tmpPool->destroy(column_[i]);
945
- }
946
- if constexpr (Master_matrix::Option_list::is_z2) {
947
- _update_entry(entry->get_row_index(), i++);
948
- } else {
949
- _update_entry(entry->get_element(), entry->get_row_index(), i++);
950
- }
951
- }
952
- erasedValues_ = other.erasedValues_;
953
- operators_ = other.operators_;
954
-
955
- return *this;
956
- }
957
-
958
- template <class Master_matrix>
959
- inline std::size_t Vector_column<Master_matrix>::compute_hash_value()
960
- {
961
- std::size_t seed = 0;
962
- for (Entry* entry : column_) {
963
- if (erasedValues_.find(entry->get_row_index()) == erasedValues_.end()) {
964
- seed ^= std::hash<unsigned int>()(entry->get_row_index() * static_cast<unsigned int>(entry->get_element())) +
965
- 0x9e3779b9 + (seed << 6) + (seed >> 2);
966
- }
967
- }
968
- return seed;
969
- }
970
-
971
- template <class Master_matrix>
972
- inline void Vector_column<Master_matrix>::_delete_entry(Entry* entry)
973
- {
974
- if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
975
- entryPool_->destroy(entry);
976
- }
977
-
978
- template <class Master_matrix>
979
- inline void Vector_column<Master_matrix>::_delete_entry(typename Column_support::iterator& it)
980
- {
981
- _delete_entry(*it);
982
- ++it;
983
- }
984
-
985
- template <class Master_matrix>
986
- inline typename Vector_column<Master_matrix>::Entry* Vector_column<Master_matrix>::_insert_entry(
987
- const Field_element& value, ID_index rowIndex, Column_support& column)
988
- {
989
- if constexpr (Master_matrix::Option_list::has_row_access) {
990
- Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
991
- newEntry->set_element(value);
992
- column.push_back(newEntry);
993
- RA_opt::insert_entry(rowIndex, newEntry);
994
- return newEntry;
995
- } else {
996
- Entry* newEntry = entryPool_->construct(rowIndex);
997
- newEntry->set_element(value);
998
- column.push_back(newEntry);
999
- return newEntry;
1000
- }
1001
- }
1002
-
1003
- template <class Master_matrix>
1004
- inline void Vector_column<Master_matrix>::_insert_entry(ID_index rowIndex, Column_support& column)
1005
- {
1006
- if constexpr (Master_matrix::Option_list::has_row_access) {
1007
- Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
1008
- column.push_back(newEntry);
1009
- RA_opt::insert_entry(rowIndex, newEntry);
1010
- } else {
1011
- Entry* newEntry = entryPool_->construct(rowIndex);
1012
- column.push_back(newEntry);
1013
- }
1014
- }
1015
-
1016
- template <class Master_matrix>
1017
- inline void Vector_column<Master_matrix>::_update_entry(const Field_element& value, ID_index rowIndex, Index position)
1018
- {
1019
- if constexpr (Master_matrix::Option_list::has_row_access) {
1020
- Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
1021
- newEntry->set_element(value);
1022
- column_[position] = newEntry;
1023
- RA_opt::insert_entry(rowIndex, newEntry);
1024
- } else {
1025
- column_[position] = entryPool_->construct(rowIndex);
1026
- column_[position]->set_element(value);
1027
- }
1028
- }
1029
-
1030
- template <class Master_matrix>
1031
- inline void Vector_column<Master_matrix>::_update_entry(ID_index rowIndex, Index position)
1032
- {
1033
- if constexpr (Master_matrix::Option_list::has_row_access) {
1034
- Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
1035
- column_[position] = newEntry;
1036
- RA_opt::insert_entry(rowIndex, newEntry);
1037
- } else {
1038
- column_[position] = entryPool_->construct(rowIndex);
1039
- }
1040
- }
1041
-
1042
- template <class Master_matrix>
1043
- template <class Entry_range>
1044
- inline bool Vector_column<Master_matrix>::_add(const Entry_range& column)
1045
- {
1046
- if (column.begin() == column.end()) return false;
1047
- if (column_.empty()) { // chain should never enter here.
1048
- column_.resize(column.size());
1049
- Index i = 0;
1050
- for (const Entry& entry : column) {
1051
- if constexpr (Master_matrix::Option_list::is_z2) {
1052
- _update_entry(entry.get_row_index(), i++);
1053
- } else {
1054
- _update_entry(entry.get_element(), entry.get_row_index(), i++);
1055
- }
1056
- }
1057
- return true;
1058
- }
1059
-
1060
- Column_support newColumn;
1061
- newColumn.reserve(column_.size() + column.size()); // safe upper bound
1062
-
1063
- auto pivotIsZeroed = _generic_add(
1064
- column,
1065
- [&](Entry* entryTarget) { newColumn.push_back(entryTarget); },
1066
- [&](typename Entry_range::const_iterator& itSource,
1067
- [[maybe_unused]] const typename Column_support::iterator& itTarget) {
1068
- if constexpr (Master_matrix::Option_list::is_z2) {
1069
- _insert_entry(itSource->get_row_index(), newColumn);
1070
- } else {
1071
- _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn);
1072
- }
1073
- },
1074
- [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) {
1075
- if constexpr (!Master_matrix::Option_list::is_z2)
1076
- operators_->add_inplace(targetElement, itSource->get_element());
1077
- },
1078
- [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }
1079
- );
1080
-
1081
- column_.swap(newColumn);
1082
-
1083
- return pivotIsZeroed;
1084
- }
1085
-
1086
- template <class Master_matrix>
1087
- template <class Entry_range>
1088
- inline bool Vector_column<Master_matrix>::_multiply_target_and_add(const Field_element& val, const Entry_range& column)
1089
- {
1090
- if (val == 0u) {
1091
- if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
1092
- throw std::invalid_argument("A chain column should not be multiplied by 0.");
1093
- // this would not only mess up the base, but also the pivots stored.
1094
- } else {
1095
- clear();
1096
- }
1097
- }
1098
- if (column_.empty()) { // chain should never enter here.
1099
- column_.resize(column.size());
1100
- Index i = 0;
1101
- for (const Entry& entry : column) {
1102
- if constexpr (Master_matrix::Option_list::is_z2) {
1103
- _update_entry(entry.get_row_index(), i++);
1104
- } else {
1105
- _update_entry(entry.get_element(), entry.get_row_index(), i++);
1106
- }
1107
- }
1108
- if constexpr (std::is_same_v<Entry_range, Vector_column<Master_matrix> >) erasedValues_ = column.erasedValues_;
1109
- return true;
1110
- }
1111
-
1112
- Column_support newColumn;
1113
- newColumn.reserve(column_.size() + column.size()); // safe upper bound
1114
-
1115
- auto pivotIsZeroed = _generic_add(
1116
- column,
1117
- [&](Entry* entryTarget) {
1118
- operators_->multiply_inplace(entryTarget->get_element(), val);
1119
- if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entryTarget);
1120
- newColumn.push_back(entryTarget);
1121
- },
1122
- [&](typename Entry_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) {
1123
- _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn);
1124
- },
1125
- [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) {
1126
- operators_->multiply_and_add_inplace_front(targetElement, val, itSource->get_element());
1127
- },
1128
- [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }
1129
- );
1130
-
1131
- column_.swap(newColumn);
1132
-
1133
- return pivotIsZeroed;
1134
- }
1135
-
1136
- template <class Master_matrix>
1137
- template <class Entry_range>
1138
- inline bool Vector_column<Master_matrix>::_multiply_source_and_add(const Entry_range& column, const Field_element& val)
1139
- {
1140
- if (val == 0u || column.begin() == column.end()) {
1141
- return false;
1142
- }
1143
-
1144
- Column_support newColumn;
1145
- newColumn.reserve(column_.size() + column.size()); // safe upper bound
1146
-
1147
- auto pivotIsZeroed = _generic_add(
1148
- column,
1149
- [&](Entry* entryTarget) { newColumn.push_back(entryTarget); },
1150
- [&](typename Entry_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) {
1151
- Entry* newEntry = _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn);
1152
- operators_->multiply_inplace(newEntry->get_element(), val);
1153
- if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*newEntry);
1154
- },
1155
- [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) {
1156
- operators_->multiply_and_add_inplace_back(itSource->get_element(), val, targetElement);
1157
- },
1158
- [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }
1159
- );
1160
-
1161
- column_.swap(newColumn);
1162
-
1163
- return pivotIsZeroed;
1164
- }
1165
-
1166
- template <class Master_matrix>
1167
- template <class Entry_range, typename F1, typename F2, typename F3, typename F4>
1168
- inline bool Vector_column<Master_matrix>::_generic_add(const Entry_range& column,
1169
- F1&& process_target,
1170
- F2&& process_source,
1171
- F3&& update_target1,
1172
- F4&& update_target2)
1173
- {
1174
- auto updateTargetIterator = [&](typename Column_support::iterator& itTarget) {
1175
- if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
1176
- while (itTarget != column_.end() && erasedValues_.find((*itTarget)->get_row_index()) != erasedValues_.end()) {
1177
- _delete_entry(*itTarget);
1178
- ++itTarget;
1179
- }
1180
- }
1181
- };
1182
- auto updateSourceIterator = [&](typename Entry_range::const_iterator& itSource) {
1183
- if constexpr (std::is_same_v<Entry_range, Vector_column<Master_matrix> > &&
1184
- (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type)) {
1185
- while (itSource != column.end() &&
1186
- column.erasedValues_.find(itSource->get_row_index()) != column.erasedValues_.end())
1187
- ++itSource;
1188
- }
1189
- };
1190
-
1191
- bool pivotIsZeroed = false;
1192
-
1193
- auto itTarget = column_.begin();
1194
- auto itSource = column.begin();
1195
- while (itTarget != column_.end() && itSource != column.end()) {
1196
- updateTargetIterator(itTarget);
1197
- updateSourceIterator(itSource);
1198
- if (itTarget == column_.end() || itSource == column.end()) break;
1199
-
1200
- _generic_merge_entry_to_column(*this, itSource, itTarget,
1201
- process_target, process_source, update_target1, update_target2,
1202
- pivotIsZeroed);
1203
- }
1204
-
1205
- while (itSource != column.end()) {
1206
- updateSourceIterator(itSource);
1207
- if (itSource == column.end()) break;
1208
-
1209
- process_source(itSource, column_.end());
1210
- ++itSource;
1211
- }
1212
-
1213
- while (itTarget != column_.end()) {
1214
- updateTargetIterator(itTarget);
1215
- if (itTarget == column_.end()) break;
1216
-
1217
- process_target(*itTarget);
1218
- ++itTarget;
1219
- }
1220
-
1221
- erasedValues_.clear();
1222
-
1223
- return pivotIsZeroed;
1224
- }
1225
-
1226
- } // namespace persistence_matrix
1227
- } // namespace Gudhi
1228
-
1229
- /**
1230
- * @ingroup persistence_matrix
1231
- *
1232
- * @brief Hash method for @ref Gudhi::persistence_matrix::Vector_column.
1233
- *
1234
- * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Vector_column.
1235
- * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Vector_column.
1236
- */
1237
- template <class Master_matrix>
1238
- struct std::hash<Gudhi::persistence_matrix::Vector_column<Master_matrix> > {
1239
- std::size_t operator()(const Gudhi::persistence_matrix::Vector_column<Master_matrix>& column) const {
1240
- return column.compute_hash_value();
1241
- }
1242
- };
1243
-
1244
- #endif // PM_VECTOR_COLUMN_H
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 vector_column.h
13
+ * @author Hannah Schreiber
14
+ * @brief Contains the @ref Gudhi::persistence_matrix::Vector_column class.
15
+ * Also defines the std::hash method for @ref Gudhi::persistence_matrix::Vector_column.
16
+ */
17
+
18
+ #ifndef PM_VECTOR_COLUMN_H
19
+ #define PM_VECTOR_COLUMN_H
20
+
21
+ #include <cstddef>
22
+ #include <vector>
23
+ #include <stdexcept>
24
+ #include <type_traits>
25
+ #include <algorithm> //binary_search
26
+ #include <unordered_set>
27
+ #include <utility> //std::swap, std::move & std::exchange
28
+
29
+ #include <boost/iterator/indirect_iterator.hpp>
30
+ #include <gudhi/Persistence_matrix/columns/column_utilities.h>
31
+
32
+ namespace Gudhi {
33
+ namespace persistence_matrix {
34
+
35
+ /**
36
+ * @class Vector_column vector_column.h gudhi/Persistence_matrix/columns/vector_column.h
37
+ * @ingroup persistence_matrix
38
+ *
39
+ * @brief Column class following the @ref PersistenceMatrixColumn concept.
40
+ *
41
+ * Column based on a vector structure. The entries are always ordered by row index, but entries are removed by
42
+ * @ref PersistenceMatrixColumn::clear(PersistenceMatrixOptions::Index rowIndex) "clear(Index)" in a lazy way,
43
+ * so erased values can still be in the underlying container.
44
+ * On the other hand, two entries will never have the same row index.
45
+ *
46
+ * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced.
47
+ * @tparam Entry_constructor Factory of @ref Entry classes.
48
+ */
49
+ template <class Master_matrix>
50
+ class Vector_column : public Master_matrix::Row_access_option,
51
+ public Master_matrix::Column_dimension_option,
52
+ public Master_matrix::Chain_column_option
53
+ {
54
+ public:
55
+ using Master = Master_matrix;
56
+ using Index = typename Master_matrix::Index;
57
+ using ID_index = typename Master_matrix::ID_index;
58
+ using Dimension = typename Master_matrix::Dimension;
59
+ using Field_element = typename Master_matrix::Element;
60
+ using Entry = typename Master_matrix::Matrix_entry;
61
+ using Column_settings = typename Master_matrix::Column_settings;
62
+
63
+ private:
64
+ using Field_operators = typename Master_matrix::Field_operators;
65
+ using Column_support = std::vector<Entry*>;
66
+ using Entry_constructor = typename Master_matrix::Entry_constructor;
67
+
68
+ public:
69
+ using iterator = boost::indirect_iterator<typename Column_support::iterator>;
70
+ using const_iterator = boost::indirect_iterator<typename Column_support::const_iterator>;
71
+ using reverse_iterator = boost::indirect_iterator<typename Column_support::reverse_iterator>;
72
+ using const_reverse_iterator = boost::indirect_iterator<typename Column_support::const_reverse_iterator>;
73
+
74
+ Vector_column(Column_settings* colSettings = nullptr);
75
+ template <class Container = typename Master_matrix::Boundary>
76
+ Vector_column(const Container& nonZeroRowIndices, Column_settings* colSettings);
77
+ template <class Container = typename Master_matrix::Boundary, class Row_container>
78
+ Vector_column(Index columnIndex,
79
+ const Container& nonZeroRowIndices,
80
+ Row_container* rowContainer,
81
+ Column_settings* colSettings);
82
+ template <class Container = typename Master_matrix::Boundary>
83
+ Vector_column(const Container& nonZeroChainRowIndices, Dimension dimension, Column_settings* colSettings);
84
+ template <class Container = typename Master_matrix::Boundary, class Row_container>
85
+ Vector_column(Index columnIndex,
86
+ const Container& nonZeroChainRowIndices,
87
+ Dimension dimension,
88
+ Row_container* rowContainer,
89
+ Column_settings* colSettings);
90
+ Vector_column(const Vector_column& column, Column_settings* colSettings = nullptr);
91
+ template <class Row_container>
92
+ Vector_column(const Vector_column& column,
93
+ Index columnIndex,
94
+ Row_container* rowContainer,
95
+ Column_settings* colSettings = nullptr);
96
+ Vector_column(Vector_column&& column) noexcept;
97
+ ~Vector_column();
98
+
99
+ std::vector<Field_element> get_content(int columnLength = -1) const;
100
+ bool is_non_zero(ID_index rowIndex) const;
101
+ bool is_empty() const;
102
+ std::size_t size() const;
103
+
104
+ template <class Row_index_map>
105
+ void reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex = -1);
106
+ void clear();
107
+ // do not clear an entry to 0 if the entry was already 0, otherwise size/is_empty will be wrong.
108
+ void clear(ID_index rowIndex);
109
+
110
+ ID_index get_pivot();
111
+ Field_element get_pivot_value();
112
+
113
+ iterator begin() noexcept;
114
+ const_iterator begin() const noexcept;
115
+ iterator end() noexcept;
116
+ const_iterator end() const noexcept;
117
+ reverse_iterator rbegin() noexcept;
118
+ const_reverse_iterator rbegin() const noexcept;
119
+ reverse_iterator rend() noexcept;
120
+ const_reverse_iterator rend() const noexcept;
121
+
122
+ template <class Entry_range>
123
+ Vector_column& operator+=(const Entry_range& column);
124
+ Vector_column& operator+=(Vector_column& column);
125
+
126
+ Vector_column& operator*=(unsigned int v);
127
+
128
+ // this = v * this + column
129
+ template <class Entry_range>
130
+ Vector_column& multiply_target_and_add(const Field_element& val, const Entry_range& column);
131
+ Vector_column& multiply_target_and_add(const Field_element& val, Vector_column& column);
132
+ // this = this + column * v
133
+ template <class Entry_range>
134
+ Vector_column& multiply_source_and_add(const Entry_range& column, const Field_element& val);
135
+ Vector_column& multiply_source_and_add(Vector_column& column, const Field_element& val);
136
+
137
+ void push_back(const Entry& entry);
138
+
139
+ std::size_t compute_hash_value();
140
+
141
+ friend bool operator==(const Vector_column& c1, const Vector_column& c2) {
142
+ if (&c1 == &c2) return true;
143
+ if (c1.erasedValues_.empty() && c2.erasedValues_.empty() && c1.column_.size() != c2.column_.size()) return false;
144
+
145
+ auto it1 = c1.column_.begin();
146
+ auto it2 = c2.column_.begin();
147
+ while (it1 != c1.column_.end() && it2 != c2.column_.end()) {
148
+ if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
149
+ while (it1 != c1.column_.end() && c1.erasedValues_.find((*it1)->get_row_index()) != c1.erasedValues_.end())
150
+ ++it1;
151
+ while (it2 != c2.column_.end() && c2.erasedValues_.find((*it2)->get_row_index()) != c2.erasedValues_.end())
152
+ ++it2;
153
+ if (it1 == c1.column_.end() || it2 == c2.column_.end()) break;
154
+ }
155
+ if constexpr (Master_matrix::Option_list::is_z2) {
156
+ if ((*it1)->get_row_index() != (*it2)->get_row_index()) return false;
157
+ } else {
158
+ if ((*it1)->get_row_index() != (*it2)->get_row_index() || (*it1)->get_element() != (*it2)->get_element())
159
+ return false;
160
+ }
161
+ ++it1;
162
+ ++it2;
163
+ }
164
+
165
+ if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
166
+ while (it1 != c1.column_.end() && c1.erasedValues_.find((*it1)->get_row_index()) != c1.erasedValues_.end()) ++it1;
167
+ while (it2 != c2.column_.end() && c2.erasedValues_.find((*it2)->get_row_index()) != c2.erasedValues_.end()) ++it2;
168
+ return it2 == c2.column_.end() && it1 == c1.column_.end();
169
+ } else {
170
+ return true;
171
+ }
172
+ }
173
+ friend bool operator<(const Vector_column& c1, const Vector_column& c2) {
174
+ if (&c1 == &c2) return false;
175
+
176
+ auto it1 = c1.column_.begin();
177
+ auto it2 = c2.column_.begin();
178
+ while (it1 != c1.column_.end() && it2 != c2.column_.end()) {
179
+ if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
180
+ while (it1 != c1.column_.end() && c1.erasedValues_.find((*it1)->get_row_index()) != c1.erasedValues_.end())
181
+ ++it1;
182
+ while (it2 != c2.column_.end() && c2.erasedValues_.find((*it2)->get_row_index()) != c2.erasedValues_.end())
183
+ ++it2;
184
+ if (it1 == c1.column_.end() || it2 == c2.column_.end()) break;
185
+ }
186
+
187
+ if ((*it1)->get_row_index() != (*it2)->get_row_index()) return (*it1)->get_row_index() < (*it2)->get_row_index();
188
+ if constexpr (!Master_matrix::Option_list::is_z2) {
189
+ if ((*it1)->get_element() != (*it2)->get_element()) return (*it1)->get_element() < (*it2)->get_element();
190
+ }
191
+ ++it1;
192
+ ++it2;
193
+ }
194
+ if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
195
+ while (it1 != c1.column_.end() && c1.erasedValues_.find((*it1)->get_row_index()) != c1.erasedValues_.end()) ++it1;
196
+ while (it2 != c2.column_.end() && c2.erasedValues_.find((*it2)->get_row_index()) != c2.erasedValues_.end()) ++it2;
197
+ }
198
+ return it2 != c2.column_.end();
199
+ }
200
+
201
+ // Disabled with row access.
202
+ Vector_column& operator=(const Vector_column& other);
203
+
204
+ friend void swap(Vector_column& col1, Vector_column& col2) {
205
+ swap(static_cast<typename Master_matrix::Row_access_option&>(col1),
206
+ static_cast<typename Master_matrix::Row_access_option&>(col2));
207
+ swap(static_cast<typename Master_matrix::Column_dimension_option&>(col1),
208
+ static_cast<typename Master_matrix::Column_dimension_option&>(col2));
209
+ swap(static_cast<typename Master_matrix::Chain_column_option&>(col1),
210
+ static_cast<typename Master_matrix::Chain_column_option&>(col2));
211
+ col1.column_.swap(col2.column_);
212
+ col1.erasedValues_.swap(col2.erasedValues_);
213
+ std::swap(col1.operators_, col2.operators_);
214
+ std::swap(col1.entryPool_, col2.entryPool_);
215
+ }
216
+
217
+ private:
218
+ using RA_opt = typename Master_matrix::Row_access_option;
219
+ using Dim_opt = typename Master_matrix::Column_dimension_option;
220
+ using Chain_opt = typename Master_matrix::Chain_column_option;
221
+
222
+ Column_support column_;
223
+ std::unordered_set<ID_index> erasedValues_; // TODO: test other containers? Useless when clear(Index) is never
224
+ // called, how much is it worth it?
225
+ Field_operators* operators_;
226
+ Entry_constructor* entryPool_;
227
+
228
+ template <class Column, class Entry_iterator, typename F1, typename F2, typename F3, typename F4>
229
+ friend void _generic_merge_entry_to_column(Column& targetColumn,
230
+ Entry_iterator& itSource,
231
+ typename Column::Column_support::iterator& itTarget,
232
+ F1&& process_target,
233
+ F2&& process_source,
234
+ F3&& update_target1,
235
+ F4&& update_target2,
236
+ bool& pivotIsZeroed);
237
+
238
+ void _delete_entry(Entry* entry);
239
+ void _delete_entry(typename Column_support::iterator& it);
240
+ Entry* _insert_entry(const Field_element& value, ID_index rowIndex, Column_support& column);
241
+ void _insert_entry(ID_index rowIndex, Column_support& column);
242
+ void _update_entry(const Field_element& value, ID_index rowIndex, Index position);
243
+ void _update_entry(ID_index rowIndex, Index position);
244
+ template <class Entry_range>
245
+ bool _add(const Entry_range& column);
246
+ template <class Entry_range>
247
+ bool _multiply_target_and_add(const Field_element& val, const Entry_range& column);
248
+ template <class Entry_range>
249
+ bool _multiply_source_and_add(const Entry_range& column, const Field_element& val);
250
+ template <class Entry_range, typename F1, typename F2, typename F3, typename F4>
251
+ bool _generic_add(const Entry_range& source,
252
+ F1&& process_target,
253
+ F2&& process_source,
254
+ F3&& update_target1,
255
+ F4&& update_target2);
256
+ };
257
+
258
+ template <class Master_matrix>
259
+ inline Vector_column<Master_matrix>::Vector_column(Column_settings* colSettings)
260
+ : RA_opt(),
261
+ Dim_opt(),
262
+ Chain_opt(),
263
+ operators_(nullptr),
264
+ entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor))
265
+ {
266
+ if (operators_ == nullptr && entryPool_ == nullptr) return; // to allow default constructor which gives a dummy column
267
+ if constexpr (!Master_matrix::Option_list::is_z2) {
268
+ operators_ = &(colSettings->operators);
269
+ }
270
+ }
271
+
272
+ template <class Master_matrix>
273
+ template <class Container>
274
+ inline Vector_column<Master_matrix>::Vector_column(const Container& nonZeroRowIndices, Column_settings* colSettings)
275
+ : RA_opt(),
276
+ Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1),
277
+ Chain_opt(),
278
+ column_(nonZeroRowIndices.size(), nullptr),
279
+ operators_(nullptr),
280
+ entryPool_(&(colSettings->entryConstructor))
281
+ {
282
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
283
+ "Constructor not available for chain columns, please specify the dimension of the chain.");
284
+
285
+ if constexpr (!Master_matrix::Option_list::is_z2) {
286
+ operators_ = &(colSettings->operators);
287
+ }
288
+
289
+ Index i = 0;
290
+ if constexpr (Master_matrix::Option_list::is_z2) {
291
+ for (ID_index id : nonZeroRowIndices) {
292
+ _update_entry(id, i++);
293
+ }
294
+ } else {
295
+ for (const auto& p : nonZeroRowIndices) {
296
+ _update_entry(operators_->get_value(p.second), p.first, i++);
297
+ }
298
+ }
299
+ }
300
+
301
+ template <class Master_matrix>
302
+ template <class Container, class Row_container>
303
+ inline Vector_column<Master_matrix>::Vector_column(Index columnIndex,
304
+ const Container& nonZeroRowIndices,
305
+ Row_container* rowContainer,
306
+ Column_settings* colSettings)
307
+ : RA_opt(columnIndex, rowContainer),
308
+ Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1),
309
+ Chain_opt([&] {
310
+ if constexpr (Master_matrix::Option_list::is_z2) {
311
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
312
+ } else {
313
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
314
+ }
315
+ }()),
316
+ column_(nonZeroRowIndices.size(), nullptr),
317
+ operators_(nullptr),
318
+ entryPool_(&(colSettings->entryConstructor))
319
+ {
320
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
321
+ "Constructor not available for chain columns, please specify the dimension of the chain.");
322
+
323
+ if constexpr (!Master_matrix::Option_list::is_z2) {
324
+ operators_ = &(colSettings->operators);
325
+ }
326
+
327
+ Index i = 0;
328
+ if constexpr (Master_matrix::Option_list::is_z2) {
329
+ for (ID_index id : nonZeroRowIndices) {
330
+ _update_entry(id, i++);
331
+ }
332
+ } else {
333
+ for (const auto& p : nonZeroRowIndices) {
334
+ _update_entry(operators_->get_value(p.second), p.first, i++);
335
+ }
336
+ }
337
+ }
338
+
339
+ template <class Master_matrix>
340
+ template <class Container>
341
+ inline Vector_column<Master_matrix>::Vector_column(const Container& nonZeroRowIndices,
342
+ Dimension dimension,
343
+ Column_settings* colSettings)
344
+ : RA_opt(),
345
+ Dim_opt(dimension),
346
+ Chain_opt([&] {
347
+ if constexpr (Master_matrix::Option_list::is_z2) {
348
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
349
+ } else {
350
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
351
+ }
352
+ }()),
353
+ column_(nonZeroRowIndices.size(), nullptr),
354
+ operators_(nullptr),
355
+ entryPool_(&(colSettings->entryConstructor))
356
+ {
357
+ if constexpr (!Master_matrix::Option_list::is_z2) {
358
+ operators_ = &(colSettings->operators);
359
+ }
360
+
361
+ Index i = 0;
362
+ if constexpr (Master_matrix::Option_list::is_z2) {
363
+ for (ID_index id : nonZeroRowIndices) {
364
+ _update_entry(id, i++);
365
+ }
366
+ } else {
367
+ for (const auto& p : nonZeroRowIndices) {
368
+ _update_entry(operators_->get_value(p.second), p.first, i++);
369
+ }
370
+ }
371
+ }
372
+
373
+ template <class Master_matrix>
374
+ template <class Container, class Row_container>
375
+ inline Vector_column<Master_matrix>::Vector_column(Index columnIndex,
376
+ const Container& nonZeroRowIndices,
377
+ Dimension dimension,
378
+ Row_container* rowContainer,
379
+ Column_settings* colSettings)
380
+ : RA_opt(columnIndex, rowContainer),
381
+ Dim_opt(dimension),
382
+ Chain_opt([&] {
383
+ if constexpr (Master_matrix::Option_list::is_z2) {
384
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
385
+ } else {
386
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
387
+ }
388
+ }()),
389
+ column_(nonZeroRowIndices.size(), nullptr),
390
+ operators_(nullptr),
391
+ entryPool_(&(colSettings->entryConstructor))
392
+ {
393
+ if constexpr (!Master_matrix::Option_list::is_z2) {
394
+ operators_ = &(colSettings->operators);
395
+ }
396
+
397
+ Index i = 0;
398
+ if constexpr (Master_matrix::Option_list::is_z2) {
399
+ for (ID_index id : nonZeroRowIndices) {
400
+ _update_entry(id, i++);
401
+ }
402
+ } else {
403
+ for (const auto& p : nonZeroRowIndices) {
404
+ _update_entry(operators_->get_value(p.second), p.first, i++);
405
+ }
406
+ }
407
+ }
408
+
409
+ template <class Master_matrix>
410
+ inline Vector_column<Master_matrix>::Vector_column(const Vector_column& column, Column_settings* colSettings)
411
+ : RA_opt(),
412
+ Dim_opt(static_cast<const Dim_opt&>(column)),
413
+ Chain_opt(static_cast<const Chain_opt&>(column)),
414
+ column_(column.column_.size(), nullptr),
415
+ erasedValues_(column.erasedValues_),
416
+ operators_(colSettings == nullptr ? column.operators_ : nullptr),
417
+ entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
418
+ {
419
+ static_assert(!Master_matrix::Option_list::has_row_access,
420
+ "Simple copy constructor not available when row access option enabled. Please specify the new column "
421
+ "index and the row container.");
422
+
423
+ if constexpr (!Master_matrix::Option_list::is_z2) {
424
+ if (colSettings != nullptr) operators_ = &(colSettings->operators);
425
+ }
426
+
427
+ Index i = 0;
428
+ for (const Entry* entry : column.column_) {
429
+ if constexpr (Master_matrix::Option_list::is_z2) {
430
+ _update_entry(entry->get_row_index(), i++);
431
+ } else {
432
+ _update_entry(entry->get_element(), entry->get_row_index(), i++);
433
+ }
434
+ }
435
+ }
436
+
437
+ template <class Master_matrix>
438
+ template <class Row_container>
439
+ inline Vector_column<Master_matrix>::Vector_column(const Vector_column& column,
440
+ Index columnIndex,
441
+ Row_container* rowContainer,
442
+ Column_settings* colSettings)
443
+ : RA_opt(columnIndex, rowContainer),
444
+ Dim_opt(static_cast<const Dim_opt&>(column)),
445
+ Chain_opt(static_cast<const Chain_opt&>(column)),
446
+ column_(column.column_.size(), nullptr),
447
+ erasedValues_(column.erasedValues_),
448
+ operators_(colSettings == nullptr ? column.operators_ : nullptr),
449
+ entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
450
+ {
451
+ if constexpr (!Master_matrix::Option_list::is_z2) {
452
+ if (colSettings != nullptr) operators_ = &(colSettings->operators);
453
+ }
454
+
455
+ Index i = 0;
456
+ for (const Entry* entry : column.column_) {
457
+ if constexpr (Master_matrix::Option_list::is_z2) {
458
+ _update_entry(entry->get_row_index(), i++);
459
+ } else {
460
+ _update_entry(entry->get_element(), entry->get_row_index(), i++);
461
+ }
462
+ }
463
+ }
464
+
465
+ template <class Master_matrix>
466
+ inline Vector_column<Master_matrix>::Vector_column(Vector_column&& column) noexcept
467
+ : RA_opt(std::move(static_cast<RA_opt&>(column))),
468
+ Dim_opt(std::move(static_cast<Dim_opt&>(column))),
469
+ Chain_opt(std::move(static_cast<Chain_opt&>(column))),
470
+ column_(std::move(column.column_)),
471
+ erasedValues_(std::move(column.erasedValues_)),
472
+ operators_(std::exchange(column.operators_, nullptr)),
473
+ entryPool_(std::exchange(column.entryPool_, nullptr))
474
+ {}
475
+
476
+ template <class Master_matrix>
477
+ inline Vector_column<Master_matrix>::~Vector_column()
478
+ {
479
+ for (auto* entry : column_) {
480
+ _delete_entry(entry);
481
+ }
482
+ }
483
+
484
+ template <class Master_matrix>
485
+ inline std::vector<typename Vector_column<Master_matrix>::Field_element> Vector_column<Master_matrix>::get_content(
486
+ int columnLength) const
487
+ {
488
+ if (columnLength < 0 && column_.size() > 0)
489
+ columnLength = column_.back()->get_row_index() + 1;
490
+ else if (columnLength < 0)
491
+ return std::vector<Field_element>();
492
+
493
+ std::vector<Field_element> container(columnLength, 0);
494
+ for (auto it = column_.begin(); it != column_.end() && (*it)->get_row_index() < static_cast<ID_index>(columnLength);
495
+ ++it) {
496
+ if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
497
+ if (erasedValues_.find((*it)->get_row_index()) != erasedValues_.end()) continue;
498
+ }
499
+ if constexpr (Master_matrix::Option_list::is_z2) {
500
+ container[(*it)->get_row_index()] = 1;
501
+ } else {
502
+ container[(*it)->get_row_index()] = (*it)->get_element();
503
+ }
504
+ }
505
+ return container;
506
+ }
507
+
508
+ template <class Master_matrix>
509
+ inline bool Vector_column<Master_matrix>::is_non_zero(ID_index rowIndex) const
510
+ {
511
+ if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type)
512
+ if (erasedValues_.find(rowIndex) != erasedValues_.end()) return false;
513
+
514
+ Entry entry(rowIndex);
515
+ return std::binary_search(column_.begin(), column_.end(), &entry,
516
+ [](const Entry* a, const Entry* b) { return a->get_row_index() < b->get_row_index(); });
517
+ }
518
+
519
+ template <class Master_matrix>
520
+ inline bool Vector_column<Master_matrix>::is_empty() const
521
+ {
522
+ if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
523
+ return column_.size() == erasedValues_.size(); // assumes that erasedValues is always a subset of column_, which is
524
+ // wrong if someone cleared an non existing value...
525
+ } else {
526
+ return column_.empty();
527
+ }
528
+ }
529
+
530
+ template <class Master_matrix>
531
+ inline std::size_t Vector_column<Master_matrix>::size() const
532
+ {
533
+ if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
534
+ return column_.size() - erasedValues_.size(); // assumes that erasedValues is always a subset of column_, which is
535
+ // wrong if someone cleared an non existing value...
536
+ } else {
537
+ return column_.size();
538
+ }
539
+ }
540
+
541
+ template <class Master_matrix>
542
+ template <class Row_index_map>
543
+ inline void Vector_column<Master_matrix>::reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex)
544
+ {
545
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
546
+ "Method not available for chain columns.");
547
+
548
+ if (erasedValues_.empty()) { // to avoid useless push_backs.
549
+ for (Entry* entry : column_) {
550
+ if constexpr (Master_matrix::Option_list::has_row_access) {
551
+ RA_opt::unlink(entry);
552
+ if (columnIndex != static_cast<Index>(-1)) entry->set_column_index(columnIndex);
553
+ }
554
+ entry->set_row_index(valueMap.at(entry->get_row_index()));
555
+ if constexpr (Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access)
556
+ RA_opt::insert_entry(entry->get_row_index(), entry);
557
+ }
558
+
559
+ // all entries have to be deleted first, to avoid problem with insertion when row is a set
560
+ if constexpr (!Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) {
561
+ for (Entry* entry : column_) {
562
+ RA_opt::insert_entry(entry->get_row_index(), entry);
563
+ }
564
+ }
565
+
566
+ std::sort(column_.begin(), column_.end(), [](const Entry* c1, const Entry* c2) { return *c1 < *c2; });
567
+ } else {
568
+ Column_support newColumn;
569
+ for (Entry* entry : column_) {
570
+ if (erasedValues_.find(entry->get_row_index()) == erasedValues_.end()) {
571
+ if constexpr (Master_matrix::Option_list::has_row_access) {
572
+ RA_opt::unlink(entry);
573
+ if (columnIndex != static_cast<Index>(-1)) entry->set_column_index(columnIndex);
574
+ }
575
+ entry->set_row_index(valueMap.at(entry->get_row_index()));
576
+ newColumn.push_back(entry);
577
+ if constexpr (Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access)
578
+ RA_opt::insert_entry(entry->get_row_index(), entry);
579
+ } else {
580
+ _delete_entry(entry);
581
+ }
582
+ }
583
+ // all entries have to be deleted first, to avoid problem with insertion when row is a set
584
+ if constexpr (!Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) {
585
+ for (Entry* entry : column_) {
586
+ RA_opt::insert_entry(entry->get_row_index(), entry);
587
+ }
588
+ }
589
+ std::sort(newColumn.begin(), newColumn.end(), [](const Entry* c1, const Entry* c2) { return *c1 < *c2; });
590
+ erasedValues_.clear();
591
+ column_.swap(newColumn);
592
+ }
593
+ }
594
+
595
+ template <class Master_matrix>
596
+ inline void Vector_column<Master_matrix>::clear()
597
+ {
598
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
599
+ "Method not available for chain columns as a base element should not be empty.");
600
+
601
+ for (auto* entry : column_) {
602
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
603
+ entryPool_->destroy(entry);
604
+ }
605
+
606
+ column_.clear();
607
+ erasedValues_.clear();
608
+ }
609
+
610
+ template <class Master_matrix>
611
+ inline void Vector_column<Master_matrix>::clear(ID_index rowIndex)
612
+ {
613
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
614
+ "Method not available for chain columns.");
615
+
616
+ erasedValues_.insert(rowIndex);
617
+ }
618
+
619
+ template <class Master_matrix>
620
+ inline typename Vector_column<Master_matrix>::ID_index Vector_column<Master_matrix>::get_pivot()
621
+ {
622
+ static_assert(Master_matrix::isNonBasic,
623
+ "Method not available for base columns."); // could technically be, but is the notion useful then?
624
+
625
+ if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
626
+ if (column_.empty()) return -1;
627
+ if (erasedValues_.empty()) return column_.back()->get_row_index();
628
+
629
+ auto it = erasedValues_.find(column_.back()->get_row_index());
630
+ while (!column_.empty() && it != erasedValues_.end()) {
631
+ erasedValues_.erase(it);
632
+ _delete_entry(column_.back());
633
+ column_.pop_back();
634
+ if (!column_.empty()) it = erasedValues_.find(column_.back()->get_row_index());
635
+ }
636
+
637
+ if (column_.empty()) return -1;
638
+ return column_.back()->get_row_index();
639
+ } else {
640
+ return Chain_opt::get_pivot();
641
+ }
642
+ }
643
+
644
+ template <class Master_matrix>
645
+ inline typename Vector_column<Master_matrix>::Field_element Vector_column<Master_matrix>::get_pivot_value()
646
+ {
647
+ static_assert(Master_matrix::isNonBasic,
648
+ "Method not available for base columns."); // could technically be, but is the notion useful then?
649
+
650
+ if constexpr (Master_matrix::Option_list::is_z2) {
651
+ return 1;
652
+ } else {
653
+ if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
654
+ if (column_.empty()) return 0;
655
+ if (erasedValues_.empty()) return column_.back()->get_element();
656
+
657
+ auto it = erasedValues_.find(column_.back()->get_row_index());
658
+ while (!column_.empty() && it != erasedValues_.end()) {
659
+ erasedValues_.erase(it);
660
+ _delete_entry(column_.back());
661
+ column_.pop_back();
662
+ if (!column_.empty()) it = erasedValues_.find(column_.back()->get_row_index());
663
+ }
664
+
665
+ if (column_.empty()) return 0;
666
+ return column_.back()->get_element();
667
+ } else {
668
+ if (Chain_opt::get_pivot() == static_cast<ID_index>(-1)) return Field_element();
669
+ for (const Entry* entry : column_) {
670
+ if (entry->get_row_index() == Chain_opt::get_pivot()) return entry->get_element();
671
+ }
672
+ return Field_element(); // should never happen if chain column is used properly
673
+ }
674
+ }
675
+ }
676
+
677
+ template <class Master_matrix>
678
+ inline typename Vector_column<Master_matrix>::iterator Vector_column<Master_matrix>::begin() noexcept
679
+ {
680
+ return column_.begin();
681
+ }
682
+
683
+ template <class Master_matrix>
684
+ inline typename Vector_column<Master_matrix>::const_iterator Vector_column<Master_matrix>::begin() const noexcept
685
+ {
686
+ return column_.begin();
687
+ }
688
+
689
+ template <class Master_matrix>
690
+ inline typename Vector_column<Master_matrix>::iterator Vector_column<Master_matrix>::end() noexcept
691
+ {
692
+ return column_.end();
693
+ }
694
+
695
+ template <class Master_matrix>
696
+ inline typename Vector_column<Master_matrix>::const_iterator Vector_column<Master_matrix>::end() const noexcept
697
+ {
698
+ return column_.end();
699
+ }
700
+
701
+ template <class Master_matrix>
702
+ inline typename Vector_column<Master_matrix>::reverse_iterator Vector_column<Master_matrix>::rbegin() noexcept
703
+ {
704
+ return column_.rbegin();
705
+ }
706
+
707
+ template <class Master_matrix>
708
+ inline typename Vector_column<Master_matrix>::const_reverse_iterator Vector_column<Master_matrix>::rbegin()
709
+ const noexcept
710
+ {
711
+ return column_.rbegin();
712
+ }
713
+
714
+ template <class Master_matrix>
715
+ inline typename Vector_column<Master_matrix>::reverse_iterator Vector_column<Master_matrix>::rend() noexcept
716
+ {
717
+ return column_.rend();
718
+ }
719
+
720
+ template <class Master_matrix>
721
+ inline typename Vector_column<Master_matrix>::const_reverse_iterator Vector_column<Master_matrix>::rend()
722
+ const noexcept
723
+ {
724
+ return column_.rend();
725
+ }
726
+
727
+ template <class Master_matrix>
728
+ template <class Entry_range>
729
+ inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::operator+=(const Entry_range& column)
730
+ {
731
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Vector_column>),
732
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
733
+ "base element."); // could be removed, if we give the responsibility to the user.
734
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
735
+ "For chain columns, the given column cannot be constant.");
736
+
737
+ _add(column);
738
+
739
+ return *this;
740
+ }
741
+
742
+ template <class Master_matrix>
743
+ inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::operator+=(Vector_column& column)
744
+ {
745
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
746
+ // assumes that the addition never zeros out this column.
747
+ if (_add(column)) {
748
+ Chain_opt::swap_pivots(column);
749
+ Dim_opt::swap_dimension(column);
750
+ }
751
+ } else {
752
+ _add(column);
753
+ }
754
+
755
+ return *this;
756
+ }
757
+
758
+ template <class Master_matrix>
759
+ inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::operator*=(unsigned int v)
760
+ {
761
+ if constexpr (Master_matrix::Option_list::is_z2) {
762
+ if (v % 2 == 0) {
763
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
764
+ throw std::invalid_argument("A chain column should not be multiplied by 0.");
765
+ } else {
766
+ clear();
767
+ }
768
+ }
769
+ } else {
770
+ Field_element val = operators_->get_value(v);
771
+
772
+ if (val == Field_operators::get_additive_identity()) {
773
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
774
+ throw std::invalid_argument("A chain column should not be multiplied by 0.");
775
+ } else {
776
+ clear();
777
+ }
778
+ return *this;
779
+ }
780
+
781
+ if (val == Field_operators::get_multiplicative_identity()) return *this;
782
+
783
+ for (Entry* entry : column_) {
784
+ operators_->multiply_inplace(entry->get_element(), val);
785
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entry);
786
+ }
787
+ }
788
+
789
+ return *this;
790
+ }
791
+
792
+ template <class Master_matrix>
793
+ template <class Entry_range>
794
+ inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::multiply_target_and_add(const Field_element& val,
795
+ const Entry_range& column)
796
+ {
797
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Vector_column>),
798
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
799
+ "base element."); // could be removed, if we give the responsibility to the user.
800
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
801
+ "For chain columns, the given column cannot be constant.");
802
+
803
+ if constexpr (Master_matrix::Option_list::is_z2) {
804
+ if (val) {
805
+ _add(column);
806
+ } else {
807
+ clear();
808
+ _add(column);
809
+ }
810
+ } else {
811
+ _multiply_target_and_add(val, column);
812
+ }
813
+
814
+ return *this;
815
+ }
816
+
817
+ template <class Master_matrix>
818
+ inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::multiply_target_and_add(const Field_element& val,
819
+ Vector_column& column)
820
+ {
821
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
822
+ // assumes that the addition never zeros out this column.
823
+ if constexpr (Master_matrix::Option_list::is_z2) {
824
+ if (val) {
825
+ if (_add(column)) {
826
+ Chain_opt::swap_pivots(column);
827
+ Dim_opt::swap_dimension(column);
828
+ }
829
+ } else {
830
+ throw std::invalid_argument("A chain column should not be multiplied by 0.");
831
+ }
832
+ } else {
833
+ if (_multiply_target_and_add(val, column)) {
834
+ Chain_opt::swap_pivots(column);
835
+ Dim_opt::swap_dimension(column);
836
+ }
837
+ }
838
+ } else {
839
+ if constexpr (Master_matrix::Option_list::is_z2) {
840
+ if (val) {
841
+ _add(column);
842
+ } else {
843
+ clear();
844
+ _add(column);
845
+ }
846
+ } else {
847
+ _multiply_target_and_add(val, column);
848
+ }
849
+ }
850
+
851
+ return *this;
852
+ }
853
+
854
+ template <class Master_matrix>
855
+ template <class Entry_range>
856
+ inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::multiply_source_and_add(const Entry_range& column,
857
+ const Field_element& val)
858
+ {
859
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Vector_column>),
860
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
861
+ "base element."); // could be removed, if we give the responsibility to the user.
862
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
863
+ "For chain columns, the given column cannot be constant.");
864
+
865
+ if constexpr (Master_matrix::Option_list::is_z2) {
866
+ if (val) {
867
+ _add(column);
868
+ }
869
+ } else {
870
+ _multiply_source_and_add(column, val);
871
+ }
872
+
873
+ return *this;
874
+ }
875
+
876
+ template <class Master_matrix>
877
+ inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::multiply_source_and_add(Vector_column& column,
878
+ const Field_element& val)
879
+ {
880
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
881
+ // assumes that the addition never zeros out this column.
882
+ if constexpr (Master_matrix::Option_list::is_z2) {
883
+ if (val) {
884
+ if (_add(column)) {
885
+ Chain_opt::swap_pivots(column);
886
+ Dim_opt::swap_dimension(column);
887
+ }
888
+ }
889
+ } else {
890
+ if (_multiply_source_and_add(column, val)) {
891
+ Chain_opt::swap_pivots(column);
892
+ Dim_opt::swap_dimension(column);
893
+ }
894
+ }
895
+ } else {
896
+ if constexpr (Master_matrix::Option_list::is_z2) {
897
+ if (val) {
898
+ _add(column);
899
+ }
900
+ } else {
901
+ _multiply_source_and_add(column, val);
902
+ }
903
+ }
904
+
905
+ return *this;
906
+ }
907
+
908
+ template <class Master_matrix>
909
+ inline void Vector_column<Master_matrix>::push_back(const Entry& entry)
910
+ {
911
+ static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices.");
912
+
913
+ if constexpr (Master_matrix::Option_list::is_z2) {
914
+ _insert_entry(entry.get_row_index(), column_);
915
+ } else {
916
+ _insert_entry(entry.get_element(), entry.get_row_index(), column_);
917
+ }
918
+ }
919
+
920
+ template <class Master_matrix>
921
+ inline Vector_column<Master_matrix>& Vector_column<Master_matrix>::operator=(const Vector_column& other)
922
+ {
923
+ static_assert(!Master_matrix::Option_list::has_row_access, "= assignment not enabled with row access option.");
924
+
925
+ Dim_opt::operator=(other);
926
+ Chain_opt::operator=(other);
927
+
928
+ auto tmpPool = entryPool_;
929
+ entryPool_ = other.entryPool_;
930
+
931
+ while (column_.size() > other.column_.size()) {
932
+ if (column_.back() != nullptr) {
933
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(column_.back());
934
+ tmpPool->destroy(column_.back());
935
+ }
936
+ column_.pop_back();
937
+ }
938
+
939
+ column_.resize(other.column_.size(), nullptr);
940
+ Index i = 0;
941
+ for (const Entry* entry : other.column_) {
942
+ if (column_[i] != nullptr) {
943
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(column_[i]);
944
+ tmpPool->destroy(column_[i]);
945
+ }
946
+ if constexpr (Master_matrix::Option_list::is_z2) {
947
+ _update_entry(entry->get_row_index(), i++);
948
+ } else {
949
+ _update_entry(entry->get_element(), entry->get_row_index(), i++);
950
+ }
951
+ }
952
+ erasedValues_ = other.erasedValues_;
953
+ operators_ = other.operators_;
954
+
955
+ return *this;
956
+ }
957
+
958
+ template <class Master_matrix>
959
+ inline std::size_t Vector_column<Master_matrix>::compute_hash_value()
960
+ {
961
+ std::size_t seed = 0;
962
+ for (Entry* entry : column_) {
963
+ if (erasedValues_.find(entry->get_row_index()) == erasedValues_.end()) {
964
+ seed ^= std::hash<unsigned int>()(entry->get_row_index() * static_cast<unsigned int>(entry->get_element())) +
965
+ 0x9e3779b9 + (seed << 6) + (seed >> 2);
966
+ }
967
+ }
968
+ return seed;
969
+ }
970
+
971
+ template <class Master_matrix>
972
+ inline void Vector_column<Master_matrix>::_delete_entry(Entry* entry)
973
+ {
974
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry);
975
+ entryPool_->destroy(entry);
976
+ }
977
+
978
+ template <class Master_matrix>
979
+ inline void Vector_column<Master_matrix>::_delete_entry(typename Column_support::iterator& it)
980
+ {
981
+ _delete_entry(*it);
982
+ ++it;
983
+ }
984
+
985
+ template <class Master_matrix>
986
+ inline typename Vector_column<Master_matrix>::Entry* Vector_column<Master_matrix>::_insert_entry(
987
+ const Field_element& value, ID_index rowIndex, Column_support& column)
988
+ {
989
+ if constexpr (Master_matrix::Option_list::has_row_access) {
990
+ Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
991
+ newEntry->set_element(value);
992
+ column.push_back(newEntry);
993
+ RA_opt::insert_entry(rowIndex, newEntry);
994
+ return newEntry;
995
+ } else {
996
+ Entry* newEntry = entryPool_->construct(rowIndex);
997
+ newEntry->set_element(value);
998
+ column.push_back(newEntry);
999
+ return newEntry;
1000
+ }
1001
+ }
1002
+
1003
+ template <class Master_matrix>
1004
+ inline void Vector_column<Master_matrix>::_insert_entry(ID_index rowIndex, Column_support& column)
1005
+ {
1006
+ if constexpr (Master_matrix::Option_list::has_row_access) {
1007
+ Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
1008
+ column.push_back(newEntry);
1009
+ RA_opt::insert_entry(rowIndex, newEntry);
1010
+ } else {
1011
+ Entry* newEntry = entryPool_->construct(rowIndex);
1012
+ column.push_back(newEntry);
1013
+ }
1014
+ }
1015
+
1016
+ template <class Master_matrix>
1017
+ inline void Vector_column<Master_matrix>::_update_entry(const Field_element& value, ID_index rowIndex, Index position)
1018
+ {
1019
+ if constexpr (Master_matrix::Option_list::has_row_access) {
1020
+ Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
1021
+ newEntry->set_element(value);
1022
+ column_[position] = newEntry;
1023
+ RA_opt::insert_entry(rowIndex, newEntry);
1024
+ } else {
1025
+ column_[position] = entryPool_->construct(rowIndex);
1026
+ column_[position]->set_element(value);
1027
+ }
1028
+ }
1029
+
1030
+ template <class Master_matrix>
1031
+ inline void Vector_column<Master_matrix>::_update_entry(ID_index rowIndex, Index position)
1032
+ {
1033
+ if constexpr (Master_matrix::Option_list::has_row_access) {
1034
+ Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex);
1035
+ column_[position] = newEntry;
1036
+ RA_opt::insert_entry(rowIndex, newEntry);
1037
+ } else {
1038
+ column_[position] = entryPool_->construct(rowIndex);
1039
+ }
1040
+ }
1041
+
1042
+ template <class Master_matrix>
1043
+ template <class Entry_range>
1044
+ inline bool Vector_column<Master_matrix>::_add(const Entry_range& column)
1045
+ {
1046
+ if (column.begin() == column.end()) return false;
1047
+ if (column_.empty()) { // chain should never enter here.
1048
+ column_.resize(column.size());
1049
+ Index i = 0;
1050
+ for (const Entry& entry : column) {
1051
+ if constexpr (Master_matrix::Option_list::is_z2) {
1052
+ _update_entry(entry.get_row_index(), i++);
1053
+ } else {
1054
+ _update_entry(entry.get_element(), entry.get_row_index(), i++);
1055
+ }
1056
+ }
1057
+ return true;
1058
+ }
1059
+
1060
+ Column_support newColumn;
1061
+ newColumn.reserve(column_.size() + column.size()); // safe upper bound
1062
+
1063
+ auto pivotIsZeroed = _generic_add(
1064
+ column,
1065
+ [&](Entry* entryTarget) { newColumn.push_back(entryTarget); },
1066
+ [&](typename Entry_range::const_iterator& itSource,
1067
+ [[maybe_unused]] const typename Column_support::iterator& itTarget) {
1068
+ if constexpr (Master_matrix::Option_list::is_z2) {
1069
+ _insert_entry(itSource->get_row_index(), newColumn);
1070
+ } else {
1071
+ _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn);
1072
+ }
1073
+ },
1074
+ [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) {
1075
+ if constexpr (!Master_matrix::Option_list::is_z2)
1076
+ operators_->add_inplace(targetElement, itSource->get_element());
1077
+ },
1078
+ [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }
1079
+ );
1080
+
1081
+ column_.swap(newColumn);
1082
+
1083
+ return pivotIsZeroed;
1084
+ }
1085
+
1086
+ template <class Master_matrix>
1087
+ template <class Entry_range>
1088
+ inline bool Vector_column<Master_matrix>::_multiply_target_and_add(const Field_element& val, const Entry_range& column)
1089
+ {
1090
+ if (val == 0u) {
1091
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
1092
+ throw std::invalid_argument("A chain column should not be multiplied by 0.");
1093
+ // this would not only mess up the base, but also the pivots stored.
1094
+ } else {
1095
+ clear();
1096
+ }
1097
+ }
1098
+ if (column_.empty()) { // chain should never enter here.
1099
+ column_.resize(column.size());
1100
+ Index i = 0;
1101
+ for (const Entry& entry : column) {
1102
+ if constexpr (Master_matrix::Option_list::is_z2) {
1103
+ _update_entry(entry.get_row_index(), i++);
1104
+ } else {
1105
+ _update_entry(entry.get_element(), entry.get_row_index(), i++);
1106
+ }
1107
+ }
1108
+ if constexpr (std::is_same_v<Entry_range, Vector_column<Master_matrix> >) erasedValues_ = column.erasedValues_;
1109
+ return true;
1110
+ }
1111
+
1112
+ Column_support newColumn;
1113
+ newColumn.reserve(column_.size() + column.size()); // safe upper bound
1114
+
1115
+ auto pivotIsZeroed = _generic_add(
1116
+ column,
1117
+ [&](Entry* entryTarget) {
1118
+ operators_->multiply_inplace(entryTarget->get_element(), val);
1119
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entryTarget);
1120
+ newColumn.push_back(entryTarget);
1121
+ },
1122
+ [&](typename Entry_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) {
1123
+ _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn);
1124
+ },
1125
+ [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) {
1126
+ operators_->multiply_and_add_inplace_front(targetElement, val, itSource->get_element());
1127
+ },
1128
+ [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }
1129
+ );
1130
+
1131
+ column_.swap(newColumn);
1132
+
1133
+ return pivotIsZeroed;
1134
+ }
1135
+
1136
+ template <class Master_matrix>
1137
+ template <class Entry_range>
1138
+ inline bool Vector_column<Master_matrix>::_multiply_source_and_add(const Entry_range& column, const Field_element& val)
1139
+ {
1140
+ if (val == 0u || column.begin() == column.end()) {
1141
+ return false;
1142
+ }
1143
+
1144
+ Column_support newColumn;
1145
+ newColumn.reserve(column_.size() + column.size()); // safe upper bound
1146
+
1147
+ auto pivotIsZeroed = _generic_add(
1148
+ column,
1149
+ [&](Entry* entryTarget) { newColumn.push_back(entryTarget); },
1150
+ [&](typename Entry_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) {
1151
+ Entry* newEntry = _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn);
1152
+ operators_->multiply_inplace(newEntry->get_element(), val);
1153
+ if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*newEntry);
1154
+ },
1155
+ [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) {
1156
+ operators_->multiply_and_add_inplace_back(itSource->get_element(), val, targetElement);
1157
+ },
1158
+ [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }
1159
+ );
1160
+
1161
+ column_.swap(newColumn);
1162
+
1163
+ return pivotIsZeroed;
1164
+ }
1165
+
1166
+ template <class Master_matrix>
1167
+ template <class Entry_range, typename F1, typename F2, typename F3, typename F4>
1168
+ inline bool Vector_column<Master_matrix>::_generic_add(const Entry_range& column,
1169
+ F1&& process_target,
1170
+ F2&& process_source,
1171
+ F3&& update_target1,
1172
+ F4&& update_target2)
1173
+ {
1174
+ auto updateTargetIterator = [&](typename Column_support::iterator& itTarget) {
1175
+ if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) {
1176
+ while (itTarget != column_.end() && erasedValues_.find((*itTarget)->get_row_index()) != erasedValues_.end()) {
1177
+ _delete_entry(*itTarget);
1178
+ ++itTarget;
1179
+ }
1180
+ }
1181
+ };
1182
+ auto updateSourceIterator = [&](typename Entry_range::const_iterator& itSource) {
1183
+ if constexpr (std::is_same_v<Entry_range, Vector_column<Master_matrix> > &&
1184
+ (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type)) {
1185
+ while (itSource != column.end() &&
1186
+ column.erasedValues_.find(itSource->get_row_index()) != column.erasedValues_.end())
1187
+ ++itSource;
1188
+ }
1189
+ };
1190
+
1191
+ bool pivotIsZeroed = false;
1192
+
1193
+ auto itTarget = column_.begin();
1194
+ auto itSource = column.begin();
1195
+ while (itTarget != column_.end() && itSource != column.end()) {
1196
+ updateTargetIterator(itTarget);
1197
+ updateSourceIterator(itSource);
1198
+ if (itTarget == column_.end() || itSource == column.end()) break;
1199
+
1200
+ _generic_merge_entry_to_column(*this, itSource, itTarget,
1201
+ process_target, process_source, update_target1, update_target2,
1202
+ pivotIsZeroed);
1203
+ }
1204
+
1205
+ while (itSource != column.end()) {
1206
+ updateSourceIterator(itSource);
1207
+ if (itSource == column.end()) break;
1208
+
1209
+ process_source(itSource, column_.end());
1210
+ ++itSource;
1211
+ }
1212
+
1213
+ while (itTarget != column_.end()) {
1214
+ updateTargetIterator(itTarget);
1215
+ if (itTarget == column_.end()) break;
1216
+
1217
+ process_target(*itTarget);
1218
+ ++itTarget;
1219
+ }
1220
+
1221
+ erasedValues_.clear();
1222
+
1223
+ return pivotIsZeroed;
1224
+ }
1225
+
1226
+ } // namespace persistence_matrix
1227
+ } // namespace Gudhi
1228
+
1229
+ /**
1230
+ * @ingroup persistence_matrix
1231
+ *
1232
+ * @brief Hash method for @ref Gudhi::persistence_matrix::Vector_column.
1233
+ *
1234
+ * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Vector_column.
1235
+ * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Vector_column.
1236
+ */
1237
+ template <class Master_matrix>
1238
+ struct std::hash<Gudhi::persistence_matrix::Vector_column<Master_matrix> > {
1239
+ std::size_t operator()(const Gudhi::persistence_matrix::Vector_column<Master_matrix>& column) const {
1240
+ return column.compute_hash_value();
1241
+ }
1242
+ };
1243
+
1244
+ #endif // PM_VECTOR_COLUMN_H