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