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