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