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