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