multipers 2.2.3__cp310-cp310-win_amd64.whl → 2.3.0__cp310-cp310-win_amd64.whl

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

Potentially problematic release.


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

Files changed (182) hide show
  1. multipers/__init__.py +33 -31
  2. multipers/_signed_measure_meta.py +430 -430
  3. multipers/_slicer_meta.py +211 -212
  4. multipers/data/MOL2.py +458 -458
  5. multipers/data/UCR.py +18 -18
  6. multipers/data/graphs.py +466 -466
  7. multipers/data/immuno_regions.py +27 -27
  8. multipers/data/pytorch2simplextree.py +90 -90
  9. multipers/data/shape3d.py +101 -101
  10. multipers/data/synthetic.py +113 -111
  11. multipers/distances.py +198 -198
  12. multipers/filtration_conversions.pxd.tp +84 -84
  13. multipers/filtrations/__init__.py +18 -0
  14. multipers/filtrations/filtrations.py +289 -0
  15. multipers/filtrations.pxd +224 -224
  16. multipers/function_rips.cp310-win_amd64.pyd +0 -0
  17. multipers/function_rips.pyx +105 -105
  18. multipers/grids.cp310-win_amd64.pyd +0 -0
  19. multipers/grids.pyx +350 -350
  20. multipers/gudhi/Persistence_slices_interface.h +132 -132
  21. multipers/gudhi/Simplex_tree_interface.h +239 -245
  22. multipers/gudhi/Simplex_tree_multi_interface.h +516 -561
  23. multipers/gudhi/cubical_to_boundary.h +59 -59
  24. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -450
  25. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -1070
  26. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -579
  27. multipers/gudhi/gudhi/Debug_utils.h +45 -45
  28. multipers/gudhi/gudhi/Fields/Multi_field.h +484 -484
  29. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -455
  30. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -450
  31. multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -531
  32. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -507
  33. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -531
  34. multipers/gudhi/gudhi/Fields/Z2_field.h +355 -355
  35. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -376
  36. multipers/gudhi/gudhi/Fields/Zp_field.h +420 -420
  37. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -400
  38. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -418
  39. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -337
  40. multipers/gudhi/gudhi/Matrix.h +2107 -2107
  41. multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -1038
  42. multipers/gudhi/gudhi/Multi_persistence/Box.h +171 -171
  43. multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -282
  44. multipers/gudhi/gudhi/Off_reader.h +173 -173
  45. multipers/gudhi/gudhi/One_critical_filtration.h +1432 -1431
  46. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -769
  47. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -686
  48. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -842
  49. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -1350
  50. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -1105
  51. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -859
  52. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -910
  53. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -139
  54. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -230
  55. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -211
  56. multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -60
  57. multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -60
  58. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -136
  59. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -190
  60. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -616
  61. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -150
  62. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -106
  63. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -219
  64. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -327
  65. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -1140
  66. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -934
  67. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -934
  68. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -980
  69. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -1092
  70. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -192
  71. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -921
  72. multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -1093
  73. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -1012
  74. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -1244
  75. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -186
  76. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -164
  77. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -156
  78. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -376
  79. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -540
  80. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -118
  81. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -173
  82. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -128
  83. multipers/gudhi/gudhi/Persistent_cohomology.h +745 -745
  84. multipers/gudhi/gudhi/Points_off_io.h +171 -171
  85. multipers/gudhi/gudhi/Simple_object_pool.h +69 -69
  86. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -463
  87. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -83
  88. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -106
  89. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -277
  90. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -62
  91. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -27
  92. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -62
  93. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -157
  94. multipers/gudhi/gudhi/Simplex_tree.h +2794 -2794
  95. multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -163
  96. multipers/gudhi/gudhi/distance_functions.h +62 -62
  97. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -104
  98. multipers/gudhi/gudhi/persistence_interval.h +253 -253
  99. multipers/gudhi/gudhi/persistence_matrix_options.h +170 -170
  100. multipers/gudhi/gudhi/reader_utils.h +367 -367
  101. multipers/gudhi/mma_interface_coh.h +256 -255
  102. multipers/gudhi/mma_interface_h0.h +223 -231
  103. multipers/gudhi/mma_interface_matrix.h +284 -282
  104. multipers/gudhi/naive_merge_tree.h +536 -575
  105. multipers/gudhi/scc_io.h +310 -289
  106. multipers/gudhi/truc.h +890 -888
  107. multipers/io.cp310-win_amd64.pyd +0 -0
  108. multipers/io.pyx +711 -711
  109. multipers/ml/accuracies.py +90 -90
  110. multipers/ml/convolutions.py +520 -520
  111. multipers/ml/invariants_with_persistable.py +79 -79
  112. multipers/ml/kernels.py +176 -176
  113. multipers/ml/mma.py +713 -714
  114. multipers/ml/one.py +472 -472
  115. multipers/ml/point_clouds.py +352 -346
  116. multipers/ml/signed_measures.py +1589 -1589
  117. multipers/ml/sliced_wasserstein.py +461 -461
  118. multipers/ml/tools.py +113 -113
  119. multipers/mma_structures.cp310-win_amd64.pyd +0 -0
  120. multipers/mma_structures.pxd +127 -127
  121. multipers/mma_structures.pyx +4 -4
  122. multipers/mma_structures.pyx.tp +1085 -1085
  123. multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -93
  124. multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -97
  125. multipers/multi_parameter_rank_invariant/function_rips.h +322 -322
  126. multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -769
  127. multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -148
  128. multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -369
  129. multipers/multiparameter_edge_collapse.py +41 -41
  130. multipers/multiparameter_module_approximation/approximation.h +2296 -2295
  131. multipers/multiparameter_module_approximation/combinatory.h +129 -129
  132. multipers/multiparameter_module_approximation/debug.h +107 -107
  133. multipers/multiparameter_module_approximation/format_python-cpp.h +286 -286
  134. multipers/multiparameter_module_approximation/heap_column.h +238 -238
  135. multipers/multiparameter_module_approximation/images.h +79 -79
  136. multipers/multiparameter_module_approximation/list_column.h +174 -174
  137. multipers/multiparameter_module_approximation/list_column_2.h +232 -232
  138. multipers/multiparameter_module_approximation/ru_matrix.h +347 -347
  139. multipers/multiparameter_module_approximation/set_column.h +135 -135
  140. multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -36
  141. multipers/multiparameter_module_approximation/unordered_set_column.h +166 -166
  142. multipers/multiparameter_module_approximation/utilities.h +403 -419
  143. multipers/multiparameter_module_approximation/vector_column.h +223 -223
  144. multipers/multiparameter_module_approximation/vector_matrix.h +331 -331
  145. multipers/multiparameter_module_approximation/vineyards.h +464 -464
  146. multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -649
  147. multipers/multiparameter_module_approximation.cp310-win_amd64.pyd +0 -0
  148. multipers/multiparameter_module_approximation.pyx +216 -217
  149. multipers/pickle.py +90 -53
  150. multipers/plots.py +342 -334
  151. multipers/point_measure.cp310-win_amd64.pyd +0 -0
  152. multipers/point_measure.pyx +322 -320
  153. multipers/simplex_tree_multi.cp310-win_amd64.pyd +0 -0
  154. multipers/simplex_tree_multi.pxd +133 -133
  155. multipers/simplex_tree_multi.pyx +18 -15
  156. multipers/simplex_tree_multi.pyx.tp +1939 -1935
  157. multipers/slicer.cp310-win_amd64.pyd +0 -0
  158. multipers/slicer.pxd +81 -20
  159. multipers/slicer.pxd.tp +215 -214
  160. multipers/slicer.pyx +1091 -308
  161. multipers/slicer.pyx.tp +924 -914
  162. multipers/tensor/tensor.h +672 -672
  163. multipers/tensor.pxd +13 -13
  164. multipers/test.pyx +44 -44
  165. multipers/tests/__init__.py +57 -57
  166. multipers/torch/diff_grids.py +217 -217
  167. multipers/torch/rips_density.py +310 -304
  168. {multipers-2.2.3.dist-info → multipers-2.3.0.dist-info}/LICENSE +21 -21
  169. {multipers-2.2.3.dist-info → multipers-2.3.0.dist-info}/METADATA +21 -11
  170. multipers-2.3.0.dist-info/RECORD +182 -0
  171. multipers/tests/test_diff_helper.py +0 -73
  172. multipers/tests/test_hilbert_function.py +0 -82
  173. multipers/tests/test_mma.py +0 -83
  174. multipers/tests/test_point_clouds.py +0 -49
  175. multipers/tests/test_python-cpp_conversion.py +0 -82
  176. multipers/tests/test_signed_betti.py +0 -181
  177. multipers/tests/test_signed_measure.py +0 -89
  178. multipers/tests/test_simplextreemulti.py +0 -221
  179. multipers/tests/test_slicer.py +0 -221
  180. multipers-2.2.3.dist-info/RECORD +0 -189
  181. {multipers-2.2.3.dist-info → multipers-2.3.0.dist-info}/WHEEL +0 -0
  182. {multipers-2.2.3.dist-info → multipers-2.3.0.dist-info}/top_level.txt +0 -0
@@ -1,934 +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_set_column.h
13
- * @author Hannah Schreiber
14
- * @brief Contains the @ref Gudhi::persistence_matrix::Intrusive_set_column class.
15
- * Also defines the std::hash method for @ref Gudhi::persistence_matrix::Intrusive_set_column.
16
- */
17
-
18
- #ifndef PM_INTRUSIVE_SET_COLUMN_H
19
- #define PM_INTRUSIVE_SET_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/set.hpp>
27
-
28
- #include <gudhi/Debug_utils.h>
29
- #include <gudhi/Persistence_matrix/allocators/entry_constructors.h>
30
- #include <gudhi/Persistence_matrix/columns/column_utilities.h>
31
-
32
- namespace Gudhi {
33
- namespace persistence_matrix {
34
-
35
- /**
36
- * @class Intrusive_set_column intrusive_set_column.h gudhi/Persistence_matrix/columns/intrusive_set_column.h
37
- * @ingroup persistence_matrix
38
- *
39
- * @brief Column class following the @ref PersistenceMatrixColumn concept.
40
- *
41
- * Column based on a intrusive set structure. The entries are ordered by row index and only non-zero values
42
- * are stored uniquely in the underlying container.
43
- *
44
- * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced.
45
- * @tparam Entry_constructor Factory of @ref Entry classes.
46
- */
47
- template <class Master_matrix>
48
- class Intrusive_set_column : public Master_matrix::Row_access_option,
49
- public Master_matrix::Column_dimension_option,
50
- public Master_matrix::Chain_column_option
51
- {
52
- public:
53
- using Master = Master_matrix;
54
- using Index = typename Master_matrix::Index;
55
- using ID_index = typename Master_matrix::ID_index;
56
- using Dimension = typename Master_matrix::Dimension;
57
- using Field_element = typename Master_matrix::Element;
58
- using Entry = typename Master_matrix::Matrix_entry;
59
- using Column_settings = typename Master_matrix::Column_settings;
60
-
61
- private:
62
- using Field_operators = typename Master_matrix::Field_operators;
63
- using Column_support =
64
- boost::intrusive::set<Entry, boost::intrusive::constant_time_size<false>,
65
- boost::intrusive::base_hook<typename Master_matrix::Base_hook_matrix_set_column> >;
66
- using Entry_constructor = typename Master_matrix::Entry_constructor;
67
-
68
- public:
69
- using iterator = typename Column_support::iterator;
70
- using const_iterator = typename Column_support::const_iterator;
71
- using reverse_iterator = typename Column_support::reverse_iterator;
72
- using const_reverse_iterator = typename Column_support::const_reverse_iterator;
73
-
74
- Intrusive_set_column(Column_settings* colSettings = nullptr);
75
- template <class Container = typename Master_matrix::Boundary>
76
- Intrusive_set_column(const Container& nonZeroRowIndices, Column_settings* colSettings);
77
- template <class Container = typename Master_matrix::Boundary, class Row_container>
78
- Intrusive_set_column(Index columnIndex,
79
- const Container& nonZeroRowIndices,
80
- Row_container* rowContainer,
81
- Column_settings* colSettings);
82
- template <class Container = typename Master_matrix::Boundary>
83
- Intrusive_set_column(const Container& nonZeroChainRowIndices, Dimension dimension, Column_settings* colSettings);
84
- template <class Container = typename Master_matrix::Boundary, class Row_container>
85
- Intrusive_set_column(Index columnIndex,
86
- const Container& nonZeroChainRowIndices,
87
- Dimension dimension,
88
- Row_container* rowContainer,
89
- Column_settings* colSettings);
90
- Intrusive_set_column(const Intrusive_set_column& column, Column_settings* colSettings = nullptr);
91
- template <class Row_container>
92
- Intrusive_set_column(const Intrusive_set_column& column,
93
- Index columnIndex,
94
- Row_container* rowContainer,
95
- Column_settings* colSettings = nullptr);
96
- Intrusive_set_column(Intrusive_set_column&& column) noexcept;
97
- ~Intrusive_set_column();
98
-
99
- std::vector<Field_element> get_content(int columnLength = -1) const;
100
- bool is_non_zero(ID_index rowIndex) const;
101
- bool is_empty() const;
102
- std::size_t size() const;
103
-
104
- template <class Row_index_map>
105
- void reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex = -1);
106
- void clear();
107
- void clear(ID_index rowIndex);
108
-
109
- ID_index get_pivot() const;
110
- Field_element get_pivot_value() const;
111
-
112
- iterator begin() noexcept;
113
- const_iterator begin() const noexcept;
114
- iterator end() noexcept;
115
- const_iterator end() const noexcept;
116
- reverse_iterator rbegin() noexcept;
117
- const_reverse_iterator rbegin() const noexcept;
118
- reverse_iterator rend() noexcept;
119
- const_reverse_iterator rend() const noexcept;
120
-
121
- template <class Entry_range>
122
- Intrusive_set_column& operator+=(const Entry_range& column);
123
- Intrusive_set_column& operator+=(Intrusive_set_column& column);
124
-
125
- Intrusive_set_column& operator*=(unsigned int v);
126
-
127
- // this = v * this + column
128
- template <class Entry_range>
129
- Intrusive_set_column& multiply_target_and_add(const Field_element& val, const Entry_range& column);
130
- Intrusive_set_column& multiply_target_and_add(const Field_element& val, Intrusive_set_column& column);
131
- // this = this + column * v
132
- template <class Entry_range>
133
- Intrusive_set_column& multiply_source_and_add(const Entry_range& column, const Field_element& val);
134
- Intrusive_set_column& multiply_source_and_add(Intrusive_set_column& column, const Field_element& val);
135
-
136
- void push_back(const Entry& entry);
137
-
138
- friend bool operator==(const Intrusive_set_column& c1, const Intrusive_set_column& c2) {
139
- if (&c1 == &c2) return true;
140
-
141
- if constexpr (Master_matrix::Option_list::is_z2) {
142
- return c1.column_ == c2.column_;
143
- } else {
144
- auto it1 = c1.column_.begin();
145
- auto it2 = c2.column_.begin();
146
- if (c1.column_.size() != c2.column_.size()) return false;
147
- while (it1 != c1.column_.end() && it2 != c2.column_.end()) {
148
- if (it1->get_row_index() != it2->get_row_index() || it1->get_element() != it2->get_element()) return false;
149
- ++it1;
150
- ++it2;
151
- }
152
- return true;
153
- }
154
- }
155
- friend bool operator<(const Intrusive_set_column& c1, const Intrusive_set_column& c2) {
156
- if (&c1 == &c2) return false;
157
-
158
- if constexpr (Master_matrix::Option_list::is_z2) {
159
- return c1.column_ < c2.column_;
160
- } else {
161
- auto it1 = c1.column_.begin();
162
- auto it2 = c2.column_.begin();
163
- while (it1 != c1.column_.end() && it2 != c2.column_.end()) {
164
- if (it1->get_row_index() != it2->get_row_index()) return it1->get_row_index() < it2->get_row_index();
165
- if (it1->get_element() != it2->get_element()) return it1->get_element() < it2->get_element();
166
- ++it1;
167
- ++it2;
168
- }
169
- return it2 != c2.column_.end();
170
- }
171
- }
172
-
173
- // Disabled with row access.
174
- Intrusive_set_column& operator=(const Intrusive_set_column& other);
175
-
176
- friend void swap(Intrusive_set_column& col1, Intrusive_set_column& col2) {
177
- swap(static_cast<typename Master_matrix::Row_access_option&>(col1),
178
- static_cast<typename Master_matrix::Row_access_option&>(col2));
179
- swap(static_cast<typename Master_matrix::Column_dimension_option&>(col1),
180
- static_cast<typename Master_matrix::Column_dimension_option&>(col2));
181
- swap(static_cast<typename Master_matrix::Chain_column_option&>(col1),
182
- static_cast<typename Master_matrix::Chain_column_option&>(col2));
183
- col1.column_.swap(col2.column_);
184
- std::swap(col1.operators_, col2.operators_);
185
- std::swap(col1.entryPool_, col2.entryPool_);
186
- }
187
-
188
- private:
189
- using RA_opt = typename Master_matrix::Row_access_option;
190
- using Dim_opt = typename Master_matrix::Column_dimension_option;
191
- using Chain_opt = typename Master_matrix::Chain_column_option;
192
-
193
- // Cloner object function for boost intrusive container
194
- struct New_cloner {
195
- New_cloner(Entry_constructor* entryPool) : entryPool_(entryPool) {};
196
-
197
- Entry* operator()(const Entry& clone_this) { return entryPool_->construct(clone_this); }
198
-
199
- Entry_constructor* entryPool_;
200
- };
201
-
202
- // The disposer object function for boost intrusive container
203
- struct Delete_disposer {
204
- Delete_disposer() {};
205
- Delete_disposer(Intrusive_set_column* col) : col_(col) {};
206
-
207
- void operator()(Entry* delete_this) {
208
- if constexpr (Master_matrix::Option_list::has_row_access) col_->unlink(delete_this);
209
- col_->entryPool_->destroy(delete_this);
210
- }
211
-
212
- Intrusive_set_column* col_;
213
- };
214
-
215
- Column_support column_;
216
- Field_operators* operators_;
217
- Entry_constructor* entryPool_;
218
-
219
- template <class Column, class Entry_iterator, typename F1, typename F2, typename F3, typename F4>
220
- friend void _generic_merge_entry_to_column(Column& targetColumn,
221
- Entry_iterator& itSource,
222
- typename Column::Column_support::iterator& itTarget,
223
- F1&& process_target,
224
- F2&& process_source,
225
- F3&& update_target1,
226
- F4&& update_target2,
227
- bool& pivotIsZeroed);
228
- template <class Column, class Entry_range, typename F1, typename F2, typename F3, typename F4, typename F5>
229
- friend bool _generic_add_to_column(const Entry_range& source,
230
- Column& targetColumn,
231
- F1&& process_target,
232
- F2&& process_source,
233
- F3&& update_target1,
234
- F4&& update_target2,
235
- F5&& finish_target);
236
- template <class Column, class Entry_range>
237
- friend bool _add_to_column(const Entry_range& source, Column& targetColumn);
238
- template <class Column, class Entry_range>
239
- friend bool _multiply_target_and_add_to_column(const typename Column::Field_element& val,
240
- const Entry_range& source,
241
- Column& targetColumn);
242
- template <class Column, class Entry_range>
243
- friend bool _multiply_source_and_add_to_column(const typename Column::Field_element& val,
244
- const Entry_range& source,
245
- Column& targetColumn);
246
-
247
- void _delete_entry(iterator& it);
248
- Entry* _insert_entry(const Field_element& value, ID_index rowIndex, const iterator& position);
249
- void _insert_entry(ID_index rowIndex, const iterator& position);
250
- template <class Entry_range>
251
- bool _add(const Entry_range& column);
252
- template <class Entry_range>
253
- bool _multiply_target_and_add(const Field_element& val, const Entry_range& column);
254
- template <class Entry_range>
255
- bool _multiply_source_and_add(const Entry_range& column, const Field_element& val);
256
- };
257
-
258
- template <class Master_matrix>
259
- inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(Column_settings* colSettings)
260
- : RA_opt(),
261
- Dim_opt(),
262
- Chain_opt(),
263
- operators_(nullptr),
264
- entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor))
265
- {
266
- if (operators_ == nullptr && entryPool_ == 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_set_column<Master_matrix>::Intrusive_set_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
- {
282
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
283
- "Constructor not available for chain columns, please specify the dimension of the chain.");
284
-
285
- if constexpr (Master_matrix::Option_list::is_z2) {
286
- for (ID_index id : nonZeroRowIndices) {
287
- _insert_entry(id, column_.end());
288
- }
289
- } else {
290
- operators_ = &(colSettings->operators);
291
- for (const auto& p : nonZeroRowIndices) {
292
- _insert_entry(operators_->get_value(p.second), p.first, column_.end());
293
- }
294
- }
295
- }
296
-
297
- template <class Master_matrix>
298
- template <class Container, class Row_container>
299
- inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(Index columnIndex,
300
- const Container& nonZeroRowIndices,
301
- Row_container* rowContainer,
302
- Column_settings* colSettings)
303
- : RA_opt(columnIndex, rowContainer),
304
- Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1),
305
- Chain_opt([&] {
306
- if constexpr (Master_matrix::Option_list::is_z2) {
307
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
308
- } else {
309
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
310
- }
311
- }()),
312
- operators_(nullptr),
313
- entryPool_(&(colSettings->entryConstructor))
314
- {
315
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
316
- "Constructor not available for chain columns, please specify the dimension of the chain.");
317
-
318
- if constexpr (Master_matrix::Option_list::is_z2) {
319
- for (ID_index id : nonZeroRowIndices) {
320
- _insert_entry(id, column_.end());
321
- }
322
- } else {
323
- operators_ = &(colSettings->operators);
324
- for (const auto& p : nonZeroRowIndices) {
325
- _insert_entry(operators_->get_value(p.second), p.first, column_.end());
326
- }
327
- }
328
- }
329
-
330
- template <class Master_matrix>
331
- template <class Container>
332
- inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(const Container& nonZeroRowIndices,
333
- Dimension dimension,
334
- Column_settings* colSettings)
335
- : RA_opt(),
336
- Dim_opt(dimension),
337
- Chain_opt([&] {
338
- if constexpr (Master_matrix::Option_list::is_z2) {
339
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
340
- } else {
341
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
342
- }
343
- }()),
344
- operators_(nullptr),
345
- entryPool_(&(colSettings->entryConstructor))
346
- {
347
- if constexpr (Master_matrix::Option_list::is_z2) {
348
- for (ID_index id : nonZeroRowIndices) {
349
- _insert_entry(id, column_.end());
350
- }
351
- } else {
352
- operators_ = &(colSettings->operators);
353
- for (const auto& p : nonZeroRowIndices) {
354
- _insert_entry(operators_->get_value(p.second), p.first, column_.end());
355
- }
356
- }
357
- }
358
-
359
- template <class Master_matrix>
360
- template <class Container, class Row_container>
361
- inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(Index columnIndex,
362
- const Container& nonZeroRowIndices,
363
- Dimension dimension,
364
- Row_container* rowContainer,
365
- Column_settings* colSettings)
366
- : RA_opt(columnIndex, rowContainer),
367
- Dim_opt(dimension),
368
- Chain_opt([&] {
369
- if constexpr (Master_matrix::Option_list::is_z2) {
370
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
371
- } else {
372
- return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
373
- }
374
- }()),
375
- operators_(nullptr),
376
- entryPool_(&(colSettings->entryConstructor))
377
- {
378
- if constexpr (Master_matrix::Option_list::is_z2) {
379
- for (ID_index id : nonZeroRowIndices) {
380
- _insert_entry(id, column_.end());
381
- }
382
- } else {
383
- operators_ = &(colSettings->operators);
384
- for (const auto& p : nonZeroRowIndices) {
385
- _insert_entry(operators_->get_value(p.second), p.first, column_.end());
386
- }
387
- }
388
- }
389
-
390
- template <class Master_matrix>
391
- inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(const Intrusive_set_column& column,
392
- Column_settings* colSettings)
393
- : RA_opt(),
394
- Dim_opt(static_cast<const Dim_opt&>(column)),
395
- Chain_opt(static_cast<const Chain_opt&>(column)),
396
- operators_(colSettings == nullptr ? column.operators_ : nullptr),
397
- entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
398
- {
399
- static_assert(!Master_matrix::Option_list::has_row_access,
400
- "Simple copy constructor not available when row access option enabled. Please specify the new column "
401
- "index and the row container.");
402
-
403
- if constexpr (!Master_matrix::Option_list::is_z2) {
404
- if (colSettings != nullptr) operators_ = &(colSettings->operators);
405
- }
406
-
407
- column_.clone_from(column.column_, New_cloner(entryPool_), Delete_disposer(this));
408
- }
409
-
410
- template <class Master_matrix>
411
- template <class Row_container>
412
- inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(const Intrusive_set_column& column,
413
- Index columnIndex,
414
- Row_container* rowContainer,
415
- Column_settings* colSettings)
416
- : RA_opt(columnIndex, rowContainer),
417
- Dim_opt(static_cast<const Dim_opt&>(column)),
418
- Chain_opt(static_cast<const Chain_opt&>(column)),
419
- operators_(colSettings == nullptr ? column.operators_ : nullptr),
420
- entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
421
- {
422
- if constexpr (!Master_matrix::Option_list::is_z2) {
423
- if (colSettings != nullptr) operators_ = &(colSettings->operators);
424
- }
425
-
426
- for (const Entry& entry : column.column_) {
427
- if constexpr (Master_matrix::Option_list::is_z2) {
428
- _insert_entry(entry.get_row_index(), column_.end());
429
- } else {
430
- _insert_entry(entry.get_element(), entry.get_row_index(), column_.end());
431
- }
432
- }
433
- }
434
-
435
- template <class Master_matrix>
436
- inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(Intrusive_set_column&& column) noexcept
437
- : RA_opt(std::move(static_cast<RA_opt&>(column))),
438
- Dim_opt(std::move(static_cast<Dim_opt&>(column))),
439
- Chain_opt(std::move(static_cast<Chain_opt&>(column))),
440
- column_(std::move(column.column_)),
441
- operators_(std::exchange(column.operators_, nullptr)),
442
- entryPool_(std::exchange(column.entryPool_, nullptr))
443
- {}
444
-
445
- template <class Master_matrix>
446
- inline Intrusive_set_column<Master_matrix>::~Intrusive_set_column()
447
- {
448
- column_.clear_and_dispose(Delete_disposer(this));
449
- }
450
-
451
- template <class Master_matrix>
452
- inline std::vector<typename Intrusive_set_column<Master_matrix>::Field_element>
453
- Intrusive_set_column<Master_matrix>::get_content(int columnLength) const
454
- {
455
- if (columnLength < 0 && column_.size() > 0)
456
- columnLength = column_.rbegin()->get_row_index() + 1;
457
- else if (columnLength < 0)
458
- return std::vector<Field_element>();
459
-
460
- std::vector<Field_element> container(columnLength);
461
- for (auto it = column_.begin(); it != column_.end() && it->get_row_index() < static_cast<ID_index>(columnLength);
462
- ++it) {
463
- if constexpr (Master_matrix::Option_list::is_z2) {
464
- container[it->get_row_index()] = 1;
465
- } else {
466
- container[it->get_row_index()] = it->get_element();
467
- }
468
- }
469
- return container;
470
- }
471
-
472
- template <class Master_matrix>
473
- inline bool Intrusive_set_column<Master_matrix>::is_non_zero(ID_index rowIndex) const
474
- {
475
- return column_.find(Entry(rowIndex)) != column_.end();
476
- }
477
-
478
- template <class Master_matrix>
479
- inline bool Intrusive_set_column<Master_matrix>::is_empty() const
480
- {
481
- return column_.empty();
482
- }
483
-
484
- template <class Master_matrix>
485
- inline std::size_t Intrusive_set_column<Master_matrix>::size() const
486
- {
487
- return column_.size();
488
- }
489
-
490
- template <class Master_matrix>
491
- template <class Row_index_map>
492
- inline void Intrusive_set_column<Master_matrix>::reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex)
493
- {
494
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
495
- "Method not available for chain columns.");
496
-
497
- Column_support newSet;
498
-
499
- if constexpr (Master_matrix::Option_list::has_row_access) {
500
- for (auto it = column_.begin(); it != column_.end();) {
501
- Entry* newEntry = entryPool_->construct(
502
- columnIndex == static_cast<Index>(-1) ? RA_opt::columnIndex_ : columnIndex, valueMap.at(it->get_row_index()));
503
- if constexpr (!Master_matrix::Option_list::is_z2) {
504
- newEntry->set_element(it->get_element());
505
- }
506
- newSet.insert(newSet.end(), *newEntry);
507
- _delete_entry(it); // increases it
508
- if constexpr (Master_matrix::Option_list::has_intrusive_rows) // intrusive list
509
- RA_opt::insert_entry(newEntry->get_row_index(), newEntry);
510
- }
511
-
512
- // when row is a set, all entries have to be deleted first, to avoid colliding when inserting
513
- if constexpr (!Master_matrix::Option_list::has_intrusive_rows) { // set
514
- for (Entry& entry : newSet) {
515
- RA_opt::insert_entry(entry.get_row_index(), &entry);
516
- }
517
- }
518
- } else {
519
- for (auto it = column_.begin(); it != column_.end();) {
520
- Entry* newEntry = entryPool_->construct(valueMap.at(it->get_row_index()));
521
- if constexpr (!Master_matrix::Option_list::is_z2) {
522
- newEntry->set_element(it->get_element());
523
- }
524
- newSet.insert(newSet.end(), *newEntry);
525
- _delete_entry(it); // increases it
526
- }
527
- }
528
-
529
- column_.swap(newSet);
530
- }
531
-
532
- template <class Master_matrix>
533
- inline void Intrusive_set_column<Master_matrix>::clear()
534
- {
535
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
536
- "Method not available for chain columns as a base element should not be empty.");
537
-
538
- column_.clear_and_dispose(Delete_disposer(this));
539
- }
540
-
541
- template <class Master_matrix>
542
- inline void Intrusive_set_column<Master_matrix>::clear(ID_index rowIndex)
543
- {
544
- static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
545
- "Method not available for chain columns.");
546
-
547
- auto it = column_.find(Entry(rowIndex));
548
- if (it != column_.end()) {
549
- _delete_entry(it);
550
- }
551
- }
552
-
553
- template <class Master_matrix>
554
- inline typename Intrusive_set_column<Master_matrix>::ID_index Intrusive_set_column<Master_matrix>::get_pivot() const
555
- {
556
- static_assert(Master_matrix::isNonBasic,
557
- "Method not available for base columns."); // could technically be, but is the notion useful then?
558
-
559
- if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
560
- if (column_.empty()) return -1;
561
- return column_.rbegin()->get_row_index();
562
- } else {
563
- return Chain_opt::get_pivot();
564
- }
565
- }
566
-
567
- template <class Master_matrix>
568
- inline typename Intrusive_set_column<Master_matrix>::Field_element
569
- Intrusive_set_column<Master_matrix>::get_pivot_value() const
570
- {
571
- static_assert(Master_matrix::isNonBasic,
572
- "Method not available for base columns."); // could technically be, but is the notion useful then?
573
-
574
- if constexpr (Master_matrix::Option_list::is_z2) {
575
- return 1;
576
- } else {
577
- if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
578
- if (column_.empty()) return 0;
579
- return column_.rbegin()->get_element();
580
- } else {
581
- if (Chain_opt::get_pivot() == static_cast<ID_index>(-1)) return 0;
582
- auto it = column_.find(Entry(Chain_opt::get_pivot()));
583
- GUDHI_CHECK(it != column_.end(),
584
- "Intrusive_set_column::get_pivot_value - Pivot not found only if the column was misused.");
585
- return it->get_element();
586
- }
587
- }
588
- }
589
-
590
- template <class Master_matrix>
591
- inline typename Intrusive_set_column<Master_matrix>::iterator Intrusive_set_column<Master_matrix>::begin() noexcept
592
- {
593
- return column_.begin();
594
- }
595
-
596
- template <class Master_matrix>
597
- inline typename Intrusive_set_column<Master_matrix>::const_iterator Intrusive_set_column<Master_matrix>::begin()
598
- const noexcept
599
- {
600
- return column_.begin();
601
- }
602
-
603
- template <class Master_matrix>
604
- inline typename Intrusive_set_column<Master_matrix>::iterator Intrusive_set_column<Master_matrix>::end() noexcept
605
- {
606
- return column_.end();
607
- }
608
-
609
- template <class Master_matrix>
610
- inline typename Intrusive_set_column<Master_matrix>::const_iterator Intrusive_set_column<Master_matrix>::end()
611
- const noexcept
612
- {
613
- return column_.end();
614
- }
615
-
616
- template <class Master_matrix>
617
- inline typename Intrusive_set_column<Master_matrix>::reverse_iterator
618
- Intrusive_set_column<Master_matrix>::rbegin() noexcept
619
- {
620
- return column_.rbegin();
621
- }
622
-
623
- template <class Master_matrix>
624
- inline typename Intrusive_set_column<Master_matrix>::const_reverse_iterator
625
- Intrusive_set_column<Master_matrix>::rbegin() const noexcept
626
- {
627
- return column_.rbegin();
628
- }
629
-
630
- template <class Master_matrix>
631
- inline typename Intrusive_set_column<Master_matrix>::reverse_iterator
632
- Intrusive_set_column<Master_matrix>::rend() noexcept
633
- {
634
- return column_.rend();
635
- }
636
-
637
- template <class Master_matrix>
638
- inline typename Intrusive_set_column<Master_matrix>::const_reverse_iterator Intrusive_set_column<Master_matrix>::rend()
639
- const noexcept
640
- {
641
- return column_.rend();
642
- }
643
-
644
- template <class Master_matrix>
645
- template <class Entry_range>
646
- inline Intrusive_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::operator+=(const Entry_range& column)
647
- {
648
- static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Intrusive_set_column>),
649
- "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
650
- "base element."); // could be removed, if we give the responsibility to the user.
651
- static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
652
- "For chain columns, the given column cannot be constant.");
653
-
654
- _add(column);
655
-
656
- return *this;
657
- }
658
-
659
- template <class Master_matrix>
660
- inline Intrusive_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::operator+=(
661
- Intrusive_set_column& column)
662
- {
663
- if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
664
- // assumes that the addition never zeros out this column.
665
- if (_add(column)) {
666
- Chain_opt::swap_pivots(column);
667
- Dim_opt::swap_dimension(column);
668
- }
669
- } else {
670
- _add(column);
671
- }
672
-
673
- return *this;
674
- }
675
-
676
- template <class Master_matrix>
677
- inline Intrusive_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::operator*=(unsigned int v)
678
- {
679
- if constexpr (Master_matrix::Option_list::is_z2) {
680
- if (v % 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 val = operators_->get_value(v);
689
-
690
- if (val == 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 (val == Field_operators::get_multiplicative_identity()) return *this;
700
-
701
- for (Entry& entry : column_) {
702
- operators_->multiply_inplace(entry.get_element(), val);
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_set_column<Master_matrix>& Intrusive_set_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_set_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_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::multiply_target_and_add(
737
- const Field_element& val, Intrusive_set_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_set_column<Master_matrix>& Intrusive_set_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_set_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_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::multiply_source_and_add(
796
- Intrusive_set_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_set_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_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::operator=(
840
- const Intrusive_set_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_set_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_set_column<Master_matrix>::Entry* Intrusive_set_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_set_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_set_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_set_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_set_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_set_column.
923
- *
924
- * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Intrusive_set_column.
925
- * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Intrusive_set_column.
926
- */
927
- template <class Master_matrix>
928
- struct std::hash<Gudhi::persistence_matrix::Intrusive_set_column<Master_matrix> > {
929
- std::size_t operator()(const Gudhi::persistence_matrix::Intrusive_set_column<Master_matrix>& column) const {
930
- return Gudhi::persistence_matrix::hash_column(column);
931
- }
932
- };
933
-
934
- #endif // PM_INTRUSIVE_SET_COLUMN_H
1
+ /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2
+ * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3
+ * Author(s): Hannah Schreiber
4
+ *
5
+ * Copyright (C) 2022-24 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+ /**
12
+ * @file intrusive_set_column.h
13
+ * @author Hannah Schreiber
14
+ * @brief Contains the @ref Gudhi::persistence_matrix::Intrusive_set_column class.
15
+ * Also defines the std::hash method for @ref Gudhi::persistence_matrix::Intrusive_set_column.
16
+ */
17
+
18
+ #ifndef PM_INTRUSIVE_SET_COLUMN_H
19
+ #define PM_INTRUSIVE_SET_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/set.hpp>
27
+
28
+ #include <gudhi/Debug_utils.h>
29
+ #include <gudhi/Persistence_matrix/allocators/entry_constructors.h>
30
+ #include <gudhi/Persistence_matrix/columns/column_utilities.h>
31
+
32
+ namespace Gudhi {
33
+ namespace persistence_matrix {
34
+
35
+ /**
36
+ * @class Intrusive_set_column intrusive_set_column.h gudhi/Persistence_matrix/columns/intrusive_set_column.h
37
+ * @ingroup persistence_matrix
38
+ *
39
+ * @brief Column class following the @ref PersistenceMatrixColumn concept.
40
+ *
41
+ * Column based on a intrusive set structure. The entries are ordered by row index and only non-zero values
42
+ * are stored uniquely in the underlying container.
43
+ *
44
+ * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced.
45
+ * @tparam Entry_constructor Factory of @ref Entry classes.
46
+ */
47
+ template <class Master_matrix>
48
+ class Intrusive_set_column : public Master_matrix::Row_access_option,
49
+ public Master_matrix::Column_dimension_option,
50
+ public Master_matrix::Chain_column_option
51
+ {
52
+ public:
53
+ using Master = Master_matrix;
54
+ using Index = typename Master_matrix::Index;
55
+ using ID_index = typename Master_matrix::ID_index;
56
+ using Dimension = typename Master_matrix::Dimension;
57
+ using Field_element = typename Master_matrix::Element;
58
+ using Entry = typename Master_matrix::Matrix_entry;
59
+ using Column_settings = typename Master_matrix::Column_settings;
60
+
61
+ private:
62
+ using Field_operators = typename Master_matrix::Field_operators;
63
+ using Column_support =
64
+ boost::intrusive::set<Entry, boost::intrusive::constant_time_size<false>,
65
+ boost::intrusive::base_hook<typename Master_matrix::Base_hook_matrix_set_column> >;
66
+ using Entry_constructor = typename Master_matrix::Entry_constructor;
67
+
68
+ public:
69
+ using iterator = typename Column_support::iterator;
70
+ using const_iterator = typename Column_support::const_iterator;
71
+ using reverse_iterator = typename Column_support::reverse_iterator;
72
+ using const_reverse_iterator = typename Column_support::const_reverse_iterator;
73
+
74
+ Intrusive_set_column(Column_settings* colSettings = nullptr);
75
+ template <class Container = typename Master_matrix::Boundary>
76
+ Intrusive_set_column(const Container& nonZeroRowIndices, Column_settings* colSettings);
77
+ template <class Container = typename Master_matrix::Boundary, class Row_container>
78
+ Intrusive_set_column(Index columnIndex,
79
+ const Container& nonZeroRowIndices,
80
+ Row_container* rowContainer,
81
+ Column_settings* colSettings);
82
+ template <class Container = typename Master_matrix::Boundary>
83
+ Intrusive_set_column(const Container& nonZeroChainRowIndices, Dimension dimension, Column_settings* colSettings);
84
+ template <class Container = typename Master_matrix::Boundary, class Row_container>
85
+ Intrusive_set_column(Index columnIndex,
86
+ const Container& nonZeroChainRowIndices,
87
+ Dimension dimension,
88
+ Row_container* rowContainer,
89
+ Column_settings* colSettings);
90
+ Intrusive_set_column(const Intrusive_set_column& column, Column_settings* colSettings = nullptr);
91
+ template <class Row_container>
92
+ Intrusive_set_column(const Intrusive_set_column& column,
93
+ Index columnIndex,
94
+ Row_container* rowContainer,
95
+ Column_settings* colSettings = nullptr);
96
+ Intrusive_set_column(Intrusive_set_column&& column) noexcept;
97
+ ~Intrusive_set_column();
98
+
99
+ std::vector<Field_element> get_content(int columnLength = -1) const;
100
+ bool is_non_zero(ID_index rowIndex) const;
101
+ bool is_empty() const;
102
+ std::size_t size() const;
103
+
104
+ template <class Row_index_map>
105
+ void reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex = -1);
106
+ void clear();
107
+ void clear(ID_index rowIndex);
108
+
109
+ ID_index get_pivot() const;
110
+ Field_element get_pivot_value() const;
111
+
112
+ iterator begin() noexcept;
113
+ const_iterator begin() const noexcept;
114
+ iterator end() noexcept;
115
+ const_iterator end() const noexcept;
116
+ reverse_iterator rbegin() noexcept;
117
+ const_reverse_iterator rbegin() const noexcept;
118
+ reverse_iterator rend() noexcept;
119
+ const_reverse_iterator rend() const noexcept;
120
+
121
+ template <class Entry_range>
122
+ Intrusive_set_column& operator+=(const Entry_range& column);
123
+ Intrusive_set_column& operator+=(Intrusive_set_column& column);
124
+
125
+ Intrusive_set_column& operator*=(unsigned int v);
126
+
127
+ // this = v * this + column
128
+ template <class Entry_range>
129
+ Intrusive_set_column& multiply_target_and_add(const Field_element& val, const Entry_range& column);
130
+ Intrusive_set_column& multiply_target_and_add(const Field_element& val, Intrusive_set_column& column);
131
+ // this = this + column * v
132
+ template <class Entry_range>
133
+ Intrusive_set_column& multiply_source_and_add(const Entry_range& column, const Field_element& val);
134
+ Intrusive_set_column& multiply_source_and_add(Intrusive_set_column& column, const Field_element& val);
135
+
136
+ void push_back(const Entry& entry);
137
+
138
+ friend bool operator==(const Intrusive_set_column& c1, const Intrusive_set_column& c2) {
139
+ if (&c1 == &c2) return true;
140
+
141
+ if constexpr (Master_matrix::Option_list::is_z2) {
142
+ return c1.column_ == c2.column_;
143
+ } else {
144
+ auto it1 = c1.column_.begin();
145
+ auto it2 = c2.column_.begin();
146
+ if (c1.column_.size() != c2.column_.size()) return false;
147
+ while (it1 != c1.column_.end() && it2 != c2.column_.end()) {
148
+ if (it1->get_row_index() != it2->get_row_index() || it1->get_element() != it2->get_element()) return false;
149
+ ++it1;
150
+ ++it2;
151
+ }
152
+ return true;
153
+ }
154
+ }
155
+ friend bool operator<(const Intrusive_set_column& c1, const Intrusive_set_column& c2) {
156
+ if (&c1 == &c2) return false;
157
+
158
+ if constexpr (Master_matrix::Option_list::is_z2) {
159
+ return c1.column_ < c2.column_;
160
+ } else {
161
+ auto it1 = c1.column_.begin();
162
+ auto it2 = c2.column_.begin();
163
+ while (it1 != c1.column_.end() && it2 != c2.column_.end()) {
164
+ if (it1->get_row_index() != it2->get_row_index()) return it1->get_row_index() < it2->get_row_index();
165
+ if (it1->get_element() != it2->get_element()) return it1->get_element() < it2->get_element();
166
+ ++it1;
167
+ ++it2;
168
+ }
169
+ return it2 != c2.column_.end();
170
+ }
171
+ }
172
+
173
+ // Disabled with row access.
174
+ Intrusive_set_column& operator=(const Intrusive_set_column& other);
175
+
176
+ friend void swap(Intrusive_set_column& col1, Intrusive_set_column& col2) {
177
+ swap(static_cast<typename Master_matrix::Row_access_option&>(col1),
178
+ static_cast<typename Master_matrix::Row_access_option&>(col2));
179
+ swap(static_cast<typename Master_matrix::Column_dimension_option&>(col1),
180
+ static_cast<typename Master_matrix::Column_dimension_option&>(col2));
181
+ swap(static_cast<typename Master_matrix::Chain_column_option&>(col1),
182
+ static_cast<typename Master_matrix::Chain_column_option&>(col2));
183
+ col1.column_.swap(col2.column_);
184
+ std::swap(col1.operators_, col2.operators_);
185
+ std::swap(col1.entryPool_, col2.entryPool_);
186
+ }
187
+
188
+ private:
189
+ using RA_opt = typename Master_matrix::Row_access_option;
190
+ using Dim_opt = typename Master_matrix::Column_dimension_option;
191
+ using Chain_opt = typename Master_matrix::Chain_column_option;
192
+
193
+ // Cloner object function for boost intrusive container
194
+ struct New_cloner {
195
+ New_cloner(Entry_constructor* entryPool) : entryPool_(entryPool) {};
196
+
197
+ Entry* operator()(const Entry& clone_this) { return entryPool_->construct(clone_this); }
198
+
199
+ Entry_constructor* entryPool_;
200
+ };
201
+
202
+ // The disposer object function for boost intrusive container
203
+ struct Delete_disposer {
204
+ Delete_disposer() {};
205
+ Delete_disposer(Intrusive_set_column* col) : col_(col) {};
206
+
207
+ void operator()(Entry* delete_this) {
208
+ if constexpr (Master_matrix::Option_list::has_row_access) col_->unlink(delete_this);
209
+ col_->entryPool_->destroy(delete_this);
210
+ }
211
+
212
+ Intrusive_set_column* col_;
213
+ };
214
+
215
+ Column_support column_;
216
+ Field_operators* operators_;
217
+ Entry_constructor* entryPool_;
218
+
219
+ template <class Column, class Entry_iterator, typename F1, typename F2, typename F3, typename F4>
220
+ friend void _generic_merge_entry_to_column(Column& targetColumn,
221
+ Entry_iterator& itSource,
222
+ typename Column::Column_support::iterator& itTarget,
223
+ F1&& process_target,
224
+ F2&& process_source,
225
+ F3&& update_target1,
226
+ F4&& update_target2,
227
+ bool& pivotIsZeroed);
228
+ template <class Column, class Entry_range, typename F1, typename F2, typename F3, typename F4, typename F5>
229
+ friend bool _generic_add_to_column(const Entry_range& source,
230
+ Column& targetColumn,
231
+ F1&& process_target,
232
+ F2&& process_source,
233
+ F3&& update_target1,
234
+ F4&& update_target2,
235
+ F5&& finish_target);
236
+ template <class Column, class Entry_range>
237
+ friend bool _add_to_column(const Entry_range& source, Column& targetColumn);
238
+ template <class Column, class Entry_range>
239
+ friend bool _multiply_target_and_add_to_column(const typename Column::Field_element& val,
240
+ const Entry_range& source,
241
+ Column& targetColumn);
242
+ template <class Column, class Entry_range>
243
+ friend bool _multiply_source_and_add_to_column(const typename Column::Field_element& val,
244
+ const Entry_range& source,
245
+ Column& targetColumn);
246
+
247
+ void _delete_entry(iterator& it);
248
+ Entry* _insert_entry(const Field_element& value, ID_index rowIndex, const iterator& position);
249
+ void _insert_entry(ID_index rowIndex, const iterator& position);
250
+ template <class Entry_range>
251
+ bool _add(const Entry_range& column);
252
+ template <class Entry_range>
253
+ bool _multiply_target_and_add(const Field_element& val, const Entry_range& column);
254
+ template <class Entry_range>
255
+ bool _multiply_source_and_add(const Entry_range& column, const Field_element& val);
256
+ };
257
+
258
+ template <class Master_matrix>
259
+ inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(Column_settings* colSettings)
260
+ : RA_opt(),
261
+ Dim_opt(),
262
+ Chain_opt(),
263
+ operators_(nullptr),
264
+ entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor))
265
+ {
266
+ if (operators_ == nullptr && entryPool_ == 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_set_column<Master_matrix>::Intrusive_set_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
+ {
282
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
283
+ "Constructor not available for chain columns, please specify the dimension of the chain.");
284
+
285
+ if constexpr (Master_matrix::Option_list::is_z2) {
286
+ for (ID_index id : nonZeroRowIndices) {
287
+ _insert_entry(id, column_.end());
288
+ }
289
+ } else {
290
+ operators_ = &(colSettings->operators);
291
+ for (const auto& p : nonZeroRowIndices) {
292
+ _insert_entry(operators_->get_value(p.second), p.first, column_.end());
293
+ }
294
+ }
295
+ }
296
+
297
+ template <class Master_matrix>
298
+ template <class Container, class Row_container>
299
+ inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(Index columnIndex,
300
+ const Container& nonZeroRowIndices,
301
+ Row_container* rowContainer,
302
+ Column_settings* colSettings)
303
+ : RA_opt(columnIndex, rowContainer),
304
+ Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1),
305
+ Chain_opt([&] {
306
+ if constexpr (Master_matrix::Option_list::is_z2) {
307
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
308
+ } else {
309
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
310
+ }
311
+ }()),
312
+ operators_(nullptr),
313
+ entryPool_(&(colSettings->entryConstructor))
314
+ {
315
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
316
+ "Constructor not available for chain columns, please specify the dimension of the chain.");
317
+
318
+ if constexpr (Master_matrix::Option_list::is_z2) {
319
+ for (ID_index id : nonZeroRowIndices) {
320
+ _insert_entry(id, column_.end());
321
+ }
322
+ } else {
323
+ operators_ = &(colSettings->operators);
324
+ for (const auto& p : nonZeroRowIndices) {
325
+ _insert_entry(operators_->get_value(p.second), p.first, column_.end());
326
+ }
327
+ }
328
+ }
329
+
330
+ template <class Master_matrix>
331
+ template <class Container>
332
+ inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(const Container& nonZeroRowIndices,
333
+ Dimension dimension,
334
+ Column_settings* colSettings)
335
+ : RA_opt(),
336
+ Dim_opt(dimension),
337
+ Chain_opt([&] {
338
+ if constexpr (Master_matrix::Option_list::is_z2) {
339
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
340
+ } else {
341
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
342
+ }
343
+ }()),
344
+ operators_(nullptr),
345
+ entryPool_(&(colSettings->entryConstructor))
346
+ {
347
+ if constexpr (Master_matrix::Option_list::is_z2) {
348
+ for (ID_index id : nonZeroRowIndices) {
349
+ _insert_entry(id, column_.end());
350
+ }
351
+ } else {
352
+ operators_ = &(colSettings->operators);
353
+ for (const auto& p : nonZeroRowIndices) {
354
+ _insert_entry(operators_->get_value(p.second), p.first, column_.end());
355
+ }
356
+ }
357
+ }
358
+
359
+ template <class Master_matrix>
360
+ template <class Container, class Row_container>
361
+ inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(Index columnIndex,
362
+ const Container& nonZeroRowIndices,
363
+ Dimension dimension,
364
+ Row_container* rowContainer,
365
+ Column_settings* colSettings)
366
+ : RA_opt(columnIndex, rowContainer),
367
+ Dim_opt(dimension),
368
+ Chain_opt([&] {
369
+ if constexpr (Master_matrix::Option_list::is_z2) {
370
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : *std::prev(nonZeroRowIndices.end());
371
+ } else {
372
+ return nonZeroRowIndices.begin() == nonZeroRowIndices.end() ? -1 : std::prev(nonZeroRowIndices.end())->first;
373
+ }
374
+ }()),
375
+ operators_(nullptr),
376
+ entryPool_(&(colSettings->entryConstructor))
377
+ {
378
+ if constexpr (Master_matrix::Option_list::is_z2) {
379
+ for (ID_index id : nonZeroRowIndices) {
380
+ _insert_entry(id, column_.end());
381
+ }
382
+ } else {
383
+ operators_ = &(colSettings->operators);
384
+ for (const auto& p : nonZeroRowIndices) {
385
+ _insert_entry(operators_->get_value(p.second), p.first, column_.end());
386
+ }
387
+ }
388
+ }
389
+
390
+ template <class Master_matrix>
391
+ inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(const Intrusive_set_column& column,
392
+ Column_settings* colSettings)
393
+ : RA_opt(),
394
+ Dim_opt(static_cast<const Dim_opt&>(column)),
395
+ Chain_opt(static_cast<const Chain_opt&>(column)),
396
+ operators_(colSettings == nullptr ? column.operators_ : nullptr),
397
+ entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
398
+ {
399
+ static_assert(!Master_matrix::Option_list::has_row_access,
400
+ "Simple copy constructor not available when row access option enabled. Please specify the new column "
401
+ "index and the row container.");
402
+
403
+ if constexpr (!Master_matrix::Option_list::is_z2) {
404
+ if (colSettings != nullptr) operators_ = &(colSettings->operators);
405
+ }
406
+
407
+ column_.clone_from(column.column_, New_cloner(entryPool_), Delete_disposer(this));
408
+ }
409
+
410
+ template <class Master_matrix>
411
+ template <class Row_container>
412
+ inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(const Intrusive_set_column& column,
413
+ Index columnIndex,
414
+ Row_container* rowContainer,
415
+ Column_settings* colSettings)
416
+ : RA_opt(columnIndex, rowContainer),
417
+ Dim_opt(static_cast<const Dim_opt&>(column)),
418
+ Chain_opt(static_cast<const Chain_opt&>(column)),
419
+ operators_(colSettings == nullptr ? column.operators_ : nullptr),
420
+ entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor))
421
+ {
422
+ if constexpr (!Master_matrix::Option_list::is_z2) {
423
+ if (colSettings != nullptr) operators_ = &(colSettings->operators);
424
+ }
425
+
426
+ for (const Entry& entry : column.column_) {
427
+ if constexpr (Master_matrix::Option_list::is_z2) {
428
+ _insert_entry(entry.get_row_index(), column_.end());
429
+ } else {
430
+ _insert_entry(entry.get_element(), entry.get_row_index(), column_.end());
431
+ }
432
+ }
433
+ }
434
+
435
+ template <class Master_matrix>
436
+ inline Intrusive_set_column<Master_matrix>::Intrusive_set_column(Intrusive_set_column&& column) noexcept
437
+ : RA_opt(std::move(static_cast<RA_opt&>(column))),
438
+ Dim_opt(std::move(static_cast<Dim_opt&>(column))),
439
+ Chain_opt(std::move(static_cast<Chain_opt&>(column))),
440
+ column_(std::move(column.column_)),
441
+ operators_(std::exchange(column.operators_, nullptr)),
442
+ entryPool_(std::exchange(column.entryPool_, nullptr))
443
+ {}
444
+
445
+ template <class Master_matrix>
446
+ inline Intrusive_set_column<Master_matrix>::~Intrusive_set_column()
447
+ {
448
+ column_.clear_and_dispose(Delete_disposer(this));
449
+ }
450
+
451
+ template <class Master_matrix>
452
+ inline std::vector<typename Intrusive_set_column<Master_matrix>::Field_element>
453
+ Intrusive_set_column<Master_matrix>::get_content(int columnLength) const
454
+ {
455
+ if (columnLength < 0 && column_.size() > 0)
456
+ columnLength = column_.rbegin()->get_row_index() + 1;
457
+ else if (columnLength < 0)
458
+ return std::vector<Field_element>();
459
+
460
+ std::vector<Field_element> container(columnLength);
461
+ for (auto it = column_.begin(); it != column_.end() && it->get_row_index() < static_cast<ID_index>(columnLength);
462
+ ++it) {
463
+ if constexpr (Master_matrix::Option_list::is_z2) {
464
+ container[it->get_row_index()] = 1;
465
+ } else {
466
+ container[it->get_row_index()] = it->get_element();
467
+ }
468
+ }
469
+ return container;
470
+ }
471
+
472
+ template <class Master_matrix>
473
+ inline bool Intrusive_set_column<Master_matrix>::is_non_zero(ID_index rowIndex) const
474
+ {
475
+ return column_.find(Entry(rowIndex)) != column_.end();
476
+ }
477
+
478
+ template <class Master_matrix>
479
+ inline bool Intrusive_set_column<Master_matrix>::is_empty() const
480
+ {
481
+ return column_.empty();
482
+ }
483
+
484
+ template <class Master_matrix>
485
+ inline std::size_t Intrusive_set_column<Master_matrix>::size() const
486
+ {
487
+ return column_.size();
488
+ }
489
+
490
+ template <class Master_matrix>
491
+ template <class Row_index_map>
492
+ inline void Intrusive_set_column<Master_matrix>::reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex)
493
+ {
494
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
495
+ "Method not available for chain columns.");
496
+
497
+ Column_support newSet;
498
+
499
+ if constexpr (Master_matrix::Option_list::has_row_access) {
500
+ for (auto it = column_.begin(); it != column_.end();) {
501
+ Entry* newEntry = entryPool_->construct(
502
+ columnIndex == static_cast<Index>(-1) ? RA_opt::columnIndex_ : columnIndex, valueMap.at(it->get_row_index()));
503
+ if constexpr (!Master_matrix::Option_list::is_z2) {
504
+ newEntry->set_element(it->get_element());
505
+ }
506
+ newSet.insert(newSet.end(), *newEntry);
507
+ _delete_entry(it); // increases it
508
+ if constexpr (Master_matrix::Option_list::has_intrusive_rows) // intrusive list
509
+ RA_opt::insert_entry(newEntry->get_row_index(), newEntry);
510
+ }
511
+
512
+ // when row is a set, all entries have to be deleted first, to avoid colliding when inserting
513
+ if constexpr (!Master_matrix::Option_list::has_intrusive_rows) { // set
514
+ for (Entry& entry : newSet) {
515
+ RA_opt::insert_entry(entry.get_row_index(), &entry);
516
+ }
517
+ }
518
+ } else {
519
+ for (auto it = column_.begin(); it != column_.end();) {
520
+ Entry* newEntry = entryPool_->construct(valueMap.at(it->get_row_index()));
521
+ if constexpr (!Master_matrix::Option_list::is_z2) {
522
+ newEntry->set_element(it->get_element());
523
+ }
524
+ newSet.insert(newSet.end(), *newEntry);
525
+ _delete_entry(it); // increases it
526
+ }
527
+ }
528
+
529
+ column_.swap(newSet);
530
+ }
531
+
532
+ template <class Master_matrix>
533
+ inline void Intrusive_set_column<Master_matrix>::clear()
534
+ {
535
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
536
+ "Method not available for chain columns as a base element should not be empty.");
537
+
538
+ column_.clear_and_dispose(Delete_disposer(this));
539
+ }
540
+
541
+ template <class Master_matrix>
542
+ inline void Intrusive_set_column<Master_matrix>::clear(ID_index rowIndex)
543
+ {
544
+ static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type,
545
+ "Method not available for chain columns.");
546
+
547
+ auto it = column_.find(Entry(rowIndex));
548
+ if (it != column_.end()) {
549
+ _delete_entry(it);
550
+ }
551
+ }
552
+
553
+ template <class Master_matrix>
554
+ inline typename Intrusive_set_column<Master_matrix>::ID_index Intrusive_set_column<Master_matrix>::get_pivot() const
555
+ {
556
+ static_assert(Master_matrix::isNonBasic,
557
+ "Method not available for base columns."); // could technically be, but is the notion useful then?
558
+
559
+ if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
560
+ if (column_.empty()) return -1;
561
+ return column_.rbegin()->get_row_index();
562
+ } else {
563
+ return Chain_opt::get_pivot();
564
+ }
565
+ }
566
+
567
+ template <class Master_matrix>
568
+ inline typename Intrusive_set_column<Master_matrix>::Field_element
569
+ Intrusive_set_column<Master_matrix>::get_pivot_value() const
570
+ {
571
+ static_assert(Master_matrix::isNonBasic,
572
+ "Method not available for base columns."); // could technically be, but is the notion useful then?
573
+
574
+ if constexpr (Master_matrix::Option_list::is_z2) {
575
+ return 1;
576
+ } else {
577
+ if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
578
+ if (column_.empty()) return 0;
579
+ return column_.rbegin()->get_element();
580
+ } else {
581
+ if (Chain_opt::get_pivot() == static_cast<ID_index>(-1)) return 0;
582
+ auto it = column_.find(Entry(Chain_opt::get_pivot()));
583
+ GUDHI_CHECK(it != column_.end(),
584
+ "Intrusive_set_column::get_pivot_value - Pivot not found only if the column was misused.");
585
+ return it->get_element();
586
+ }
587
+ }
588
+ }
589
+
590
+ template <class Master_matrix>
591
+ inline typename Intrusive_set_column<Master_matrix>::iterator Intrusive_set_column<Master_matrix>::begin() noexcept
592
+ {
593
+ return column_.begin();
594
+ }
595
+
596
+ template <class Master_matrix>
597
+ inline typename Intrusive_set_column<Master_matrix>::const_iterator Intrusive_set_column<Master_matrix>::begin()
598
+ const noexcept
599
+ {
600
+ return column_.begin();
601
+ }
602
+
603
+ template <class Master_matrix>
604
+ inline typename Intrusive_set_column<Master_matrix>::iterator Intrusive_set_column<Master_matrix>::end() noexcept
605
+ {
606
+ return column_.end();
607
+ }
608
+
609
+ template <class Master_matrix>
610
+ inline typename Intrusive_set_column<Master_matrix>::const_iterator Intrusive_set_column<Master_matrix>::end()
611
+ const noexcept
612
+ {
613
+ return column_.end();
614
+ }
615
+
616
+ template <class Master_matrix>
617
+ inline typename Intrusive_set_column<Master_matrix>::reverse_iterator
618
+ Intrusive_set_column<Master_matrix>::rbegin() noexcept
619
+ {
620
+ return column_.rbegin();
621
+ }
622
+
623
+ template <class Master_matrix>
624
+ inline typename Intrusive_set_column<Master_matrix>::const_reverse_iterator
625
+ Intrusive_set_column<Master_matrix>::rbegin() const noexcept
626
+ {
627
+ return column_.rbegin();
628
+ }
629
+
630
+ template <class Master_matrix>
631
+ inline typename Intrusive_set_column<Master_matrix>::reverse_iterator
632
+ Intrusive_set_column<Master_matrix>::rend() noexcept
633
+ {
634
+ return column_.rend();
635
+ }
636
+
637
+ template <class Master_matrix>
638
+ inline typename Intrusive_set_column<Master_matrix>::const_reverse_iterator Intrusive_set_column<Master_matrix>::rend()
639
+ const noexcept
640
+ {
641
+ return column_.rend();
642
+ }
643
+
644
+ template <class Master_matrix>
645
+ template <class Entry_range>
646
+ inline Intrusive_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::operator+=(const Entry_range& column)
647
+ {
648
+ static_assert((!Master_matrix::isNonBasic || std::is_same_v<Entry_range, Intrusive_set_column>),
649
+ "For boundary columns, the range has to be a column of same type to help ensure the validity of the "
650
+ "base element."); // could be removed, if we give the responsibility to the user.
651
+ static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type),
652
+ "For chain columns, the given column cannot be constant.");
653
+
654
+ _add(column);
655
+
656
+ return *this;
657
+ }
658
+
659
+ template <class Master_matrix>
660
+ inline Intrusive_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::operator+=(
661
+ Intrusive_set_column& column)
662
+ {
663
+ if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) {
664
+ // assumes that the addition never zeros out this column.
665
+ if (_add(column)) {
666
+ Chain_opt::swap_pivots(column);
667
+ Dim_opt::swap_dimension(column);
668
+ }
669
+ } else {
670
+ _add(column);
671
+ }
672
+
673
+ return *this;
674
+ }
675
+
676
+ template <class Master_matrix>
677
+ inline Intrusive_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::operator*=(unsigned int v)
678
+ {
679
+ if constexpr (Master_matrix::Option_list::is_z2) {
680
+ if (v % 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 val = operators_->get_value(v);
689
+
690
+ if (val == 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 (val == Field_operators::get_multiplicative_identity()) return *this;
700
+
701
+ for (Entry& entry : column_) {
702
+ operators_->multiply_inplace(entry.get_element(), val);
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_set_column<Master_matrix>& Intrusive_set_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_set_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_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::multiply_target_and_add(
737
+ const Field_element& val, Intrusive_set_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_set_column<Master_matrix>& Intrusive_set_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_set_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_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::multiply_source_and_add(
796
+ Intrusive_set_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_set_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_set_column<Master_matrix>& Intrusive_set_column<Master_matrix>::operator=(
840
+ const Intrusive_set_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_set_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_set_column<Master_matrix>::Entry* Intrusive_set_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_set_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_set_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_set_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_set_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_set_column.
923
+ *
924
+ * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Intrusive_set_column.
925
+ * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Intrusive_set_column.
926
+ */
927
+ template <class Master_matrix>
928
+ struct std::hash<Gudhi::persistence_matrix::Intrusive_set_column<Master_matrix> > {
929
+ std::size_t operator()(const Gudhi::persistence_matrix::Intrusive_set_column<Master_matrix>& column) const {
930
+ return Gudhi::persistence_matrix::hash_column(column);
931
+ }
932
+ };
933
+
934
+ #endif // PM_INTRUSIVE_SET_COLUMN_H