Loading...
Searching...
No Matches
chain_pairing.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 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
17
18#ifndef PM_CHAIN_PAIRING_H
19#define PM_CHAIN_PAIRING_H
20
21namespace Gudhi {
22namespace persistence_matrix {
23
24template <typename Master_matrix>
26
35 friend void swap([[maybe_unused]] Dummy_chain_pairing& d1, [[maybe_unused]] Dummy_chain_pairing& d2) noexcept {}
36};
37
46template <class Master_matrix>
48{
49 public:
50 using Barcode = typename Master_matrix::Barcode;
51 using Dimension = typename Master_matrix::Dimension;
52
56 Chain_pairing() = default;
57
63 const Barcode& get_current_barcode() const;
64
68 friend void swap(Chain_pairing& pairing1, Chain_pairing& pairing2) noexcept
69 {
70 pairing1.barcode_.swap(pairing2.barcode_);
71 pairing1.indexToBar_.swap(pairing2.indexToBar_);
72 }
73
74 protected:
75 using Pos_index = typename Master_matrix::Pos_index;
76 using Index = typename Master_matrix::Index;
77
78 void _update_barcode(Pos_index birth, Pos_index death);
79 void _add_bar(Dimension dim, Pos_index birth);
80 void _erase_bar(Pos_index event);
81 Pos_index _death(Index index) const;
82 Pos_index _birth(Index index) const;
83 void _reset();
84
85 private:
86 using Dictionary = typename Master_matrix::Bar_dictionary;
87
88 // could also just mark everything as protected as Chain_barcode_swap inherits from Chain_pairing
89 // but this way, it marks a better difference between "class using this mixin" with "class extending this mixin"
91
92 Barcode barcode_;
93 Dictionary indexToBar_;
94};
95
96template <class Master_matrix>
98{
99 return barcode_;
100}
101
102template <class Master_matrix>
103inline void Chain_pairing<Master_matrix>::_update_barcode(Pos_index birth, Pos_index death)
104{
105 if constexpr (Master_matrix::Option_list::has_removable_columns) {
106 auto& barIt = indexToBar_.at(birth);
107 barIt->death = death;
108 indexToBar_.try_emplace(death, barIt); // list so iterators are stable
109 } else {
110 barcode_[indexToBar_[birth]].death = death;
111 indexToBar_.push_back(indexToBar_[birth]);
112 }
113}
114
115template <class Master_matrix>
116inline void Chain_pairing<Master_matrix>::_add_bar(Dimension dim, Pos_index birth)
117{
118 barcode_.emplace_back(birth, Master_matrix::template get_null_value<Pos_index>(), dim);
119 if constexpr (Master_matrix::Option_list::has_removable_columns) {
120 indexToBar_.try_emplace(birth, --barcode_.end());
121 } else {
122 indexToBar_.push_back(barcode_.size() - 1);
123 }
124}
125
126template <class Master_matrix>
127inline void Chain_pairing<Master_matrix>::_erase_bar(Pos_index event)
128{
129 auto it = indexToBar_.find(event);
130 typename Barcode::iterator bar = it->second;
131
132 if (bar->death == Master_matrix::template get_null_value<Pos_index>())
133 barcode_.erase(bar);
134 else
135 bar->death = Master_matrix::template get_null_value<Pos_index>();
136
137 indexToBar_.erase(it);
138}
139
140template <class Master_matrix>
141inline typename Chain_pairing<Master_matrix>::Pos_index Chain_pairing<Master_matrix>::_death(Index index) const
142{
143 if constexpr (Master_matrix::Option_list::has_removable_columns) {
144 return indexToBar_.at(index)->death;
145 } else {
146 return barcode_.at(indexToBar_.at(index)).death;
147 }
148}
149
150template <class Master_matrix>
151inline typename Chain_pairing<Master_matrix>::Pos_index Chain_pairing<Master_matrix>::_birth(Index index) const
152{
153 if constexpr (Master_matrix::Option_list::has_removable_columns) {
154 return indexToBar_.at(index)->birth;
155 } else {
156 return barcode_.at(indexToBar_.at(index)).birth;
157 }
158}
159
160template <class Master_matrix>
161inline void Chain_pairing<Master_matrix>::_reset()
162{
163 barcode_.clear();
164 indexToBar_.clear();
165}
166
167} // namespace persistence_matrix
168} // namespace Gudhi
169
170#endif // PM_CHAIN_PAIRING_H
Class managing the barcode for Chain_vine_swap.
Definition chain_vine_swap.h:89
friend void swap(Chain_pairing &pairing1, Chain_pairing &pairing2) noexcept
Swap operator.
Definition chain_pairing.h:68
const Barcode & get_current_barcode() const
Returns the current barcode which is maintained at any insertion, removal or vine swap.
Definition chain_pairing.h:97
typename Master_matrix::Dimension Dimension
Definition chain_pairing.h:51
Chain_pairing()=default
Default constructor.
typename Master_matrix::Barcode Barcode
Definition chain_pairing.h:50
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Empty structure. Inherited instead of Chain_pairing, when the computation of the barcode was not enab...
Definition chain_pairing.h:34