Loading...
Searching...
No Matches
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
17#ifndef PM_CHAIN_REP_CYCLES_H
18#define PM_CHAIN_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_chain_representative_cycles& d1,
36 [[maybe_unused]] Dummy_chain_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 Bar = typename Master_matrix::Bar;
53 using cycle_type = typename Master_matrix::cycle_type;
54 using matrix_type = typename Master_matrix::column_container_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 chain_matrix = typename Master_matrix::Chain_matrix_type;
109
110 std::vector<cycle_type> representativeCycles_;
111 std::vector<typename Master_matrix::index> birthToCycle_;
113 //access to inheritating Chain_matrix class
114 constexpr chain_matrix* _matrix() { return static_cast<chain_matrix*>(this); }
115 constexpr const chain_matrix* _matrix() const { return static_cast<const chain_matrix*>(this); }
116};
117
118template <class Master_matrix>
121
122template <class Master_matrix>
125 : representativeCycles_(matrixToCopy.representativeCycles_), birthToCycle_(matrixToCopy.birthToCycle_)
126{}
127
128template <class Master_matrix>
131 : representativeCycles_(std::move(other.representativeCycles_)), birthToCycle_(std::move(other.birthToCycle_))
132{}
133
134template <class Master_matrix>
136{
137 birthToCycle_.clear();
138 birthToCycle_.resize(_matrix()->get_number_of_columns(), -1);
139 representativeCycles_.clear();
140
141 // for birthToCycle_, assumes that @ref PosIdx == @ref IDIdx, ie pivot == birth index... which is not true with vineyards
142 // TODO: with vineyard, there is a @ref IDIdx --> @ref PosIdx map stored. somehow get access to it here
143 for (typename Master_matrix::id_index i = 0; i < _matrix()->get_number_of_columns(); i++) {
144 auto& col = _matrix()->get_column(_matrix()->get_column_with_pivot(i));
145 if (!col.is_paired() || i < col.get_paired_chain_index()) {
146 cycle_type cycle;
147 for (auto& c : col) {
148 cycle.push_back(c.get_row_index());
149 }
150 if constexpr (std::is_same_v<typename Master_matrix::Column_type, typename Master_matrix::Heap_column_type> ||
151 std::is_same_v<typename Master_matrix::Column_type,
152 typename Master_matrix::Unordered_set_column_type>)
153 std::sort(cycle.begin(), cycle.end());
154 representativeCycles_.push_back(cycle);
155 birthToCycle_[i] = representativeCycles_.size() - 1;
156 }
157 }
158}
159
160template <class Master_matrix>
161inline const std::vector<typename Chain_representative_cycles<Master_matrix>::cycle_type>&
163{
164 if (representativeCycles_.empty()) update_representative_cycles();
165 return representativeCycles_;
166}
167
168template <class Master_matrix>
171{
172 if (representativeCycles_.empty()) update_representative_cycles();
173 return representativeCycles_[birthToCycle_[bar.birth]];
174}
175
176template <class Master_matrix>
179{
180 representativeCycles_.swap(other.representativeCycles_);
181 birthToCycle_.swap(other.birthToCycle_);
182 return *this;
183}
184
185} // namespace persistence_matrix
186} // namespace Gudhi
187
188#endif // PM_CHAIN_REP_CYCLES_H
Class managing the representative cycles for Chain_matrix if the option was enabled.
Definition chain_rep_cycles.h:50
typename Master_matrix::Bar Bar
Definition chain_rep_cycles.h:52
Chain_representative_cycles & operator=(Chain_representative_cycles other)
Assign operator.
Definition chain_rep_cycles.h:177
const std::vector< cycle_type > & get_representative_cycles()
Returns the current representative cycles. If the matrix is modified later after the first call,...
Definition chain_rep_cycles.h:162
typename Master_matrix::cycle_type cycle_type
Definition chain_rep_cycles.h:53
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 chain_rep_cycles.h:170
void update_representative_cycles()
Computes the current representative cycles of the matrix.
Definition chain_rep_cycles.h:135
friend void swap(Chain_representative_cycles &base1, Chain_representative_cycles &base2)
Swap operator.
Definition chain_rep_cycles.h:102
Chain_representative_cycles()
Default constructor.
Definition chain_rep_cycles.h:119
typename Master_matrix::column_container_type matrix_type
Definition chain_rep_cycles.h:54
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Empty structure. Inheritated instead of Chain_representative_cycles, when the computation of the repr...
Definition chain_rep_cycles.h:34