chain_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_CHAIN_REP_CYCLES_H
19#define PM_CHAIN_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_chain_representative_cycles& d1,
38 [[maybe_unused]] Dummy_chain_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 Bar = typename Master_matrix::Bar;
55 using Cycle = typename Master_matrix::Cycle;
56 using Column_container = typename Master_matrix::Column_container;
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_chain_matrix = typename Master_matrix::Master_chain_matrix;
111
112 std::vector<Cycle> representativeCycles_;
113 std::vector<typename Master_matrix::Index> birthToCycle_;
115 //access to inheriting Chain_matrix class
116 constexpr Master_chain_matrix* _matrix() { return static_cast<Master_chain_matrix*>(this); }
117 constexpr const Master_chain_matrix* _matrix() const { return static_cast<const Master_chain_matrix*>(this); }
118};
119
120template <class Master_matrix>
122{}
123
124template <class Master_matrix>
127 : representativeCycles_(matrixToCopy.representativeCycles_), birthToCycle_(matrixToCopy.birthToCycle_)
128{}
129
130template <class Master_matrix>
133 : representativeCycles_(std::move(other.representativeCycles_)), birthToCycle_(std::move(other.birthToCycle_))
134{}
135
136template <class Master_matrix>
138{
139 birthToCycle_.clear();
140 birthToCycle_.resize(_matrix()->get_number_of_columns(), -1);
141 representativeCycles_.clear();
142
143 // for birthToCycle_, assumes that @ref PosIdx == @ref IDIdx, ie pivot == birth index... which is not true with
144 // vineyards
145 // TODO: with vineyard, there is a @ref IDIdx --> @ref PosIdx map stored. somehow get access to it here
146 for (typename Master_matrix::ID_index i = 0; i < _matrix()->get_number_of_columns(); i++) {
147 auto& col = _matrix()->get_column(_matrix()->get_column_with_pivot(i));
148 if (!col.is_paired() || i < col.get_paired_chain_index()) {
149 Cycle cycle;
150 for (auto& c : col) {
151 cycle.push_back(c.get_row_index());
152 }
153 if constexpr (std::is_same_v<typename Master_matrix::Column, typename Master_matrix::Matrix_heap_column> ||
154 std::is_same_v<typename Master_matrix::Column, typename Master_matrix::Matrix_unordered_set_column>)
155 std::sort(cycle.begin(), cycle.end());
156 representativeCycles_.push_back(cycle);
157 birthToCycle_[i] = representativeCycles_.size() - 1;
158 }
159 }
160}
161
162template <class Master_matrix>
163inline const std::vector<typename Chain_representative_cycles<Master_matrix>::Cycle>&
165{
166 if (representativeCycles_.empty()) update_representative_cycles();
167 return representativeCycles_;
168}
169
170template <class Master_matrix>
173{
174 if (representativeCycles_.empty()) update_representative_cycles();
175 return representativeCycles_[birthToCycle_[bar.birth]];
176}
177
178template <class Master_matrix>
181{
182 representativeCycles_.swap(other.representativeCycles_);
183 birthToCycle_.swap(other.birthToCycle_);
184 return *this;
185}
186
187} // namespace persistence_matrix
188} // namespace Gudhi
189
190#endif // PM_CHAIN_REP_CYCLES_H
Class managing the representative cycles for Chain_matrix if the option was enabled.
Definition: chain_rep_cycles.h:52
typename Master_matrix::Bar Bar
Definition: chain_rep_cycles.h:54
Chain_representative_cycles & operator=(Chain_representative_cycles other)
Assign operator.
Definition: chain_rep_cycles.h:179
typename Master_matrix::Cycle Cycle
Definition: chain_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: chain_rep_cycles.h:164
void update_representative_cycles()
Computes the current representative cycles of the matrix.
Definition: chain_rep_cycles.h:137
friend void swap(Chain_representative_cycles &base1, Chain_representative_cycles &base2)
Swap operator.
Definition: chain_rep_cycles.h:104
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: chain_rep_cycles.h:172
Chain_representative_cycles()
Default constructor.
Definition: chain_rep_cycles.h:121
typename Master_matrix::Column_container Column_container
Definition: chain_rep_cycles.h:56
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Empty structure. Inherited instead of Chain_representative_cycles, when the computation of the repres...
Definition: chain_rep_cycles.h:36