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