multipers 2.3.3b6__cp311-cp311-macosx_11_0_arm64.whl

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

Potentially problematic release.


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

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