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