17 #ifndef PM_BASE_PAIRING_H
18 #define PM_BASE_PAIRING_H
21 #include <unordered_map>
26 namespace persistence_matrix {
47 template <
class Master_matrix>
51 using Bar =
typename Master_matrix::Bar;
53 using matrix_type =
typename Master_matrix::column_container_type;
54 using index =
typename Master_matrix::index;
93 pairing1.barcode_.swap(pairing2.barcode_);
94 pairing1.deathToBar_.swap(pairing2.deathToBar_);
95 std::swap(pairing1.isReduced_, pairing2.isReduced_);
99 using pos_index =
typename Master_matrix::pos_index;
100 using dictionnary_type =
typename Master_matrix::bar_dictionnary_type;
101 using base_matrix =
typename Master_matrix::Boundary_matrix_type;
104 dictionnary_type deathToBar_;
108 void _remove_last(pos_index columnIndex);
111 constexpr base_matrix* _matrix() {
return static_cast<base_matrix*
>(
this); }
112 constexpr
const base_matrix* _matrix()
const {
return static_cast<const base_matrix*
>(
this); }
115 template <
class Master_matrix>
119 template <
class Master_matrix>
121 : barcode_(matrixToCopy.barcode_), deathToBar_(matrixToCopy.deathToBar_), isReduced_(matrixToCopy.isReduced_)
124 template <
class Master_matrix>
126 : barcode_(std::move(other.barcode_)),
127 deathToBar_(std::move(other.deathToBar_)),
128 isReduced_(std::move(other.isReduced_))
131 template <
class Master_matrix>
134 if (!isReduced_) _reduce();
138 template <
class Master_matrix>
141 using id_index =
typename Master_matrix::index;
142 std::unordered_map<id_index, index> pivotsToColumn(_matrix()->get_number_of_columns());
144 auto dim = _matrix()->get_max_dimension();
145 std::vector<std::vector<index> > columnsByDim(dim + 1);
146 for (
unsigned int i = 0; i < _matrix()->get_number_of_columns(); i++) {
147 columnsByDim[dim - _matrix()->get_column_dimension(i)].push_back(i);
150 for (
const auto& cols : columnsByDim) {
151 for (index i : cols) {
152 auto& curr = _matrix()->get_column(i);
153 if (curr.is_empty()) {
154 if (pivotsToColumn.find(i) == pivotsToColumn.end()) {
155 barcode_.emplace_back(dim, i, -1);
158 id_index pivot = curr.get_pivot();
160 while (pivot !=
static_cast<id_index
>(-1) && pivotsToColumn.find(pivot) != pivotsToColumn.end()) {
161 if constexpr (Master_matrix::Option_list::is_z2) {
162 curr += _matrix()->get_column(pivotsToColumn.at(pivot));
164 auto& toadd = _matrix()->get_column(pivotsToColumn.at(pivot));
165 typename Master_matrix::element_type coef = toadd.get_pivot_value();
166 auto& operators = _matrix()->colSettings_->operators;
167 coef = operators.get_inverse(coef);
168 operators.multiply_inplace(coef, operators.get_characteristic() - curr.get_pivot_value());
169 curr.multiply_source_and_add(toadd, coef);
172 pivot = curr.get_pivot();
175 if (pivot !=
static_cast<id_index
>(-1)) {
176 pivotsToColumn.emplace(pivot, i);
177 _matrix()->get_column(pivot).clear();
178 barcode_.emplace_back(dim - 1, pivot, i);
181 barcode_.emplace_back(dim, i, -1);
188 if constexpr (Master_matrix::Option_list::has_removable_columns) {
190 std::sort(barcode_.begin(), barcode_.end(), [](
const Bar& b1,
const Bar& b2) { return b1.birth < b2.birth; });
192 for (index i = 0; i < barcode_.size(); ++i) {
193 auto d = barcode_[i].death;
194 if (d !=
static_cast<pos_index
>(-1)) {
195 deathToBar_.emplace(d, i);
203 template <
class Master_matrix>
204 inline void Base_pairing<Master_matrix>::_remove_last(pos_index columnIndex)
206 static_assert(Master_matrix::Option_list::has_removable_columns,
"remove_last not available.");
209 auto it = deathToBar_.find(columnIndex);
211 if (it == deathToBar_.end()) {
214 barcode_[it->second].death = -1;
215 deathToBar_.erase(it);
220 template <
class Master_matrix>
223 barcode_.
swap(other.barcode_);
224 deathToBar_.swap(other.deathToBar_);
225 std::swap(isReduced_, other.isReduced_);
Class managing the barcode for Boundary_matrix if the option was enabled.
Definition: base_pairing.h:49
typename Master_matrix::barcode_type barcode_type
Definition: base_pairing.h:52
typename Master_matrix::Bar Bar
Definition: base_pairing.h:51
typename Master_matrix::index index
Definition: base_pairing.h:54
friend void swap(Base_pairing &pairing1, Base_pairing &pairing2)
Swap operator.
Definition: base_pairing.h:92
Base_pairing & operator=(Base_pairing other)
Assign operator.
Definition: base_pairing.h:221
typename Master_matrix::column_container_type matrix_type
Definition: base_pairing.h:53
typename Master_matrix::dimension_type dimension_type
Definition: base_pairing.h:55
const barcode_type & get_current_barcode()
Reduces the matrix stored in Boundary_matrix and computes the corresponding barcode.
Definition: base_pairing.h:132
Base_pairing()
Default constructor.
Definition: base_pairing.h:116
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Empty structure. Inheritated instead of Base_pairing, when the computation of the barcode was not ena...
Definition: base_pairing.h:35