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