Loading...
Searching...
No Matches
ru_rep_cycles.h
Go to the documentation of this file.
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
17#ifndef PM_RU_REP_CYCLES_H
18#define PM_RU_REP_CYCLES_H
19
20#include <utility> //std::move
21#include <algorithm> //std::sort
22#include <vector>
23
24namespace Gudhi {
25namespace persistence_matrix {
26
35 friend void swap([[maybe_unused]] Dummy_ru_representative_cycles& d1,
36 [[maybe_unused]] Dummy_ru_representative_cycles& d2) {}
37};
38
39// TODO: add coefficients ? Only Z2 token into account for now.
48template <class Master_matrix>
50{
51 public:
52 using index = typename Master_matrix::index;
53 using Bar = typename Master_matrix::Bar;
54 using cycle_type = typename Master_matrix::cycle_type;
72
77
84 const std::vector<cycle_type>& get_representative_cycles();
93 const cycle_type& get_representative_cycle(const Bar& bar);
94
103 base1.representativeCycles_.swap(base2.representativeCycles_);
104 base1.birthToCycle_.swap(base2.birthToCycle_);
105 }
106
107 private:
108 using ru_matrix = typename Master_matrix::RU_matrix_type;
109
110 std::vector<cycle_type> representativeCycles_;
111 std::vector<index> birthToCycle_;
113 constexpr ru_matrix* _matrix() { return static_cast<ru_matrix*>(this); }
114 constexpr const ru_matrix* _matrix() const { return static_cast<const ru_matrix*>(this); }
115};
116
117template <class Master_matrix>
120
121template <class Master_matrix>
123 const RU_representative_cycles<Master_matrix>& matrixToCopy)
124 : representativeCycles_(matrixToCopy.representativeCycles_), birthToCycle_(matrixToCopy.birthToCycle_)
125{}
126
127template <class Master_matrix>
130 : representativeCycles_(std::move(other.representativeCycles_)), birthToCycle_(std::move(other.birthToCycle_))
131{}
132
133template <class Master_matrix>
135{
136 if constexpr (Master_matrix::Option_list::has_vine_update) {
137 birthToCycle_.clear();
138 birthToCycle_.resize(_matrix()->reducedMatrixR_.get_number_of_columns(), -1);
139 index c = 0;
140 for (index i = 0; i < _matrix()->reducedMatrixR_.get_number_of_columns(); i++) {
141 if (_matrix()->reducedMatrixR_.is_zero_column(i)) {
142 birthToCycle_[i] = c;
143 ++c;
144 }
145 }
146 representativeCycles_.clear();
147 representativeCycles_.resize(c);
148 for (index i = 0; i < _matrix()->mirrorMatrixU_.get_number_of_columns(); i++) {
149 for (const auto& cell : _matrix()->mirrorMatrixU_.get_column(i)) {
150 auto idx = birthToCycle_[cell.get_row_index()];
151 if (idx != static_cast<index>(-1)) {
152 representativeCycles_[idx].push_back(i);
153 }
154 }
155 }
156 } else {
157 birthToCycle_.clear();
158 birthToCycle_.resize(_matrix()->reducedMatrixR_.get_number_of_columns(), -1);
159 for (index i = 0; i < _matrix()->reducedMatrixR_.get_number_of_columns(); i++) {
160 if (_matrix()->reducedMatrixR_.is_zero_column(i)) {
161 representativeCycles_.push_back(cycle_type());
162 for (const auto& cell : _matrix()->mirrorMatrixU_.get_column(i)) {
163 representativeCycles_.back().push_back(cell.get_row_index());
164 }
165 if constexpr (std::is_same_v<typename Master_matrix::Column_type, typename Master_matrix::Heap_column_type> ||
166 std::is_same_v<typename Master_matrix::Column_type,
167 typename Master_matrix::Unordered_set_column_type>)
168 std::sort(representativeCycles_.back().begin(), representativeCycles_.back().end());
169 birthToCycle_[i] = representativeCycles_.size() - 1;
170 }
171 }
172 }
173}
174
175template <class Master_matrix>
176inline const std::vector<typename RU_representative_cycles<Master_matrix>::cycle_type>&
178{
179 if (representativeCycles_.empty()) update_representative_cycles();
180 return representativeCycles_;
181}
182
183template <class Master_matrix>
186{
187 if (representativeCycles_.empty()) update_representative_cycles();
188 return representativeCycles_[birthToCycle_[bar.birth]];
189}
190
191template <class Master_matrix>
194{
195 representativeCycles_.swap(other.representativeCycles_);
196 birthToCycle_.swap(other.birthToCycle_);
197 return *this;
198}
199
200} // namespace persistence_matrix
201} // namespace Gudhi
202
203#endif // PM_RU_REP_CYCLES_H
Class managing the representative cycles for RU_matrix if the option was enabled.
Definition ru_rep_cycles.h:50
RU_representative_cycles()
Default constructor.
Definition ru_rep_cycles.h:118
friend void swap(RU_representative_cycles &base1, RU_representative_cycles &base2)
Swap operator.
Definition ru_rep_cycles.h:102
typename Master_matrix::Bar Bar
Definition ru_rep_cycles.h:53
typename Master_matrix::cycle_type cycle_type
Definition ru_rep_cycles.h:54
const std::vector< cycle_type > & get_representative_cycles()
Returns the current representative cycles. If the matrix is modified later after the first call,...
Definition ru_rep_cycles.h:177
const cycle_type & get_representative_cycle(const Bar &bar)
Returns the representative cycle corresponding to the given bar. If the matrix is modified later afte...
Definition ru_rep_cycles.h:185
void update_representative_cycles()
Computes the current representative cycles of the matrix.
Definition ru_rep_cycles.h:134
typename Master_matrix::index index
Definition ru_rep_cycles.h:52
RU_representative_cycles & operator=(RU_representative_cycles other)
Assign operator.
Definition ru_rep_cycles.h:192
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Empty structure. Inheritated instead of RU_representative_cycles, when the computation of the represe...
Definition ru_rep_cycles.h:34