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