All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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
18#ifndef PM_RU_REP_CYCLES_H
19#define PM_RU_REP_CYCLES_H
20
21#include <utility> //std::move
22#include <algorithm> //std::sort
23#include <vector>
24
25namespace Gudhi {
26namespace persistence_matrix {
27
36{
37 friend void swap([[maybe_unused]] Dummy_ru_representative_cycles& d1,
38 [[maybe_unused]] Dummy_ru_representative_cycles& d2) {}
39};
40
41// TODO: add coefficients ? Only Z2 token into account for now.
50template <class Master_matrix>
52{
53 public:
54 using Index = typename Master_matrix::Index;
55 using Bar = typename Master_matrix::Bar;
56 using Cycle = typename Master_matrix::Cycle;
74
79
86 const std::vector<Cycle>& get_representative_cycles();
95 const Cycle& get_representative_cycle(const Bar& bar);
96
105 base1.representativeCycles_.swap(base2.representativeCycles_);
106 base1.birthToCycle_.swap(base2.birthToCycle_);
107 }
108
109 private:
110 using Master_RU_matrix = typename Master_matrix::Master_RU_matrix;
111
112 std::vector<Cycle> representativeCycles_;
113 std::vector<Index> birthToCycle_;
115 constexpr Master_RU_matrix* _matrix() { return static_cast<Master_RU_matrix*>(this); }
116 constexpr const Master_RU_matrix* _matrix() const { return static_cast<const Master_RU_matrix*>(this); }
117};
118
119template <class Master_matrix>
121{}
122
123template <class Master_matrix>
125 const RU_representative_cycles<Master_matrix>& matrixToCopy)
126 : representativeCycles_(matrixToCopy.representativeCycles_), birthToCycle_(matrixToCopy.birthToCycle_)
127{}
128
129template <class Master_matrix>
132 : representativeCycles_(std::move(other.representativeCycles_)), birthToCycle_(std::move(other.birthToCycle_))
133{}
134
135template <class Master_matrix>
137{
138 if constexpr (Master_matrix::Option_list::is_z2) {
139 birthToCycle_.clear();
140 birthToCycle_.resize(_matrix()->reducedMatrixR_.get_number_of_columns(), -1);
141 Index c = 0;
142 for (Index i = 0; i < _matrix()->reducedMatrixR_.get_number_of_columns(); i++) {
143 if (_matrix()->reducedMatrixR_.is_zero_column(i)) {
144 birthToCycle_[i] = c;
145 ++c;
146 }
147 }
148 representativeCycles_.clear();
149 representativeCycles_.resize(c);
150 for (Index i = 0; i < _matrix()->mirrorMatrixU_.get_number_of_columns(); i++) {
151 for (const auto& entry : _matrix()->mirrorMatrixU_.get_column(i)) {
152 auto idx = birthToCycle_[entry.get_row_index()];
153 if (idx != Master_matrix::template get_null_value<Index>()) {
154 representativeCycles_[idx].push_back(i);
155 }
156 }
157 }
158 } else {
159 birthToCycle_.clear();
160 birthToCycle_.resize(_matrix()->reducedMatrixR_.get_number_of_columns(), -1);
161 for (Index i = 0; i < _matrix()->reducedMatrixR_.get_number_of_columns(); i++) {
162 if (_matrix()->reducedMatrixR_.is_zero_column(i)) {
163 representativeCycles_.push_back(Cycle());
164 for (const auto& entry : _matrix()->mirrorMatrixU_.get_column(i)) {
165 representativeCycles_.back().push_back(entry.get_row_index());
166 }
167 if constexpr (std::is_same_v<typename Master_matrix::Column, typename Master_matrix::Matrix_heap_column> ||
168 std::is_same_v<typename Master_matrix::Column,
169 typename Master_matrix::Matrix_unordered_set_column>)
170 std::sort(representativeCycles_.back().begin(), representativeCycles_.back().end());
171 birthToCycle_[i] = representativeCycles_.size() - 1;
172 }
173 }
174 }
175}
176
177template <class Master_matrix>
178inline const std::vector<typename RU_representative_cycles<Master_matrix>::Cycle>&
180{
181 if (representativeCycles_.empty()) update_representative_cycles();
182 return representativeCycles_;
183}
184
185template <class Master_matrix>
188{
189 if (representativeCycles_.empty()) update_representative_cycles();
190 return representativeCycles_[birthToCycle_[bar.birth]];
191}
192
193template <class Master_matrix>
196{
197 representativeCycles_.swap(other.representativeCycles_);
198 birthToCycle_.swap(other.birthToCycle_);
199 return *this;
200}
201
202} // namespace persistence_matrix
203} // namespace Gudhi
204
205#endif // PM_RU_REP_CYCLES_H
Class managing the representative cycles for RU_matrix if the option was enabled.
Definition: ru_rep_cycles.h:52
const Cycle & 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:187
typename Master_matrix::Index Index
Definition: ru_rep_cycles.h:54
RU_representative_cycles()
Default constructor.
Definition: ru_rep_cycles.h:120
friend void swap(RU_representative_cycles &base1, RU_representative_cycles &base2)
Swap operator.
Definition: ru_rep_cycles.h:104
typename Master_matrix::Bar Bar
Definition: ru_rep_cycles.h:55
const std::vector< Cycle > & get_representative_cycles()
Returns the current representative cycles. If the matrix is modified later after the first call,...
Definition: ru_rep_cycles.h:179
typename Master_matrix::Cycle Cycle
Definition: ru_rep_cycles.h:56
void update_representative_cycles()
Computes the current representative cycles of the matrix.
Definition: ru_rep_cycles.h:136
RU_representative_cycles & operator=(RU_representative_cycles other)
Assign operator.
Definition: ru_rep_cycles.h:194
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Empty structure. Inherited instead of RU_representative_cycles, when the computation of the represent...
Definition: ru_rep_cycles.h:36