18#ifndef PM_CHAIN_REP_CYCLES_H
19#define PM_CHAIN_REP_CYCLES_H
24#include <tbb/parallel_for.h>
27#include <gudhi/Debug_utils.h>
54template <
class Master_matrix>
58 using Bar =
typename Master_matrix::Bar;
59 using Cycle =
typename Master_matrix::Cycle;
61 using Index =
typename Master_matrix::Index;
62 using ID_index =
typename Master_matrix::ID_index;
63 using Dimension =
typename Master_matrix::Dimension;
111 base1.representativeCycles_.swap(base2.representativeCycles_);
112 base1.birthToCycle_.swap(base2.birthToCycle_);
119 using Master_chain_matrix =
typename Master_matrix::Master_chain_matrix;
121 std::vector<Cycle> representativeCycles_;
122 std::vector<Index> birthToCycle_;
125 constexpr Master_chain_matrix* _matrix() {
return static_cast<Master_chain_matrix*
>(
this); }
127 constexpr const Master_chain_matrix* _matrix()
const {
return static_cast<const Master_chain_matrix*
>(
this); }
130template <
class Master_matrix>
133 Index nberColumns = _matrix()->get_number_of_columns();
134 auto get_position = [&](
ID_index pivot) {
135 if constexpr (Master_matrix::Option_list::has_vine_update) {
136 if constexpr (Master_matrix::Option_list::has_map_column_container) {
137 return _matrix()->map_.at(pivot);
139 return _matrix()->map_[pivot];
145 Index nullValue = Master_matrix::template get_null_value<Index>();
147 birthToCycle_.clear();
148 birthToCycle_.resize(nberColumns, nullValue);
149 representativeCycles_.clear();
153 for (
Index i = 0; i < nberColumns; i++) {
154 auto& col = _matrix()->get_column(_matrix()->get_column_with_pivot(i));
155 if ((dim == Master_matrix::template get_null_value<Dimension>() || _matrix()->get_column_dimension(i) == dim) &&
156 (!col.is_paired() || get_position(i) < get_position(_matrix()->get_pivot(col.get_paired_chain_index())))) {
157 birthToCycle_[get_position(i)] = c;
162 representativeCycles_.resize(c);
163 tbb::parallel_for(
static_cast<Index>(0), nberColumns, [&](
Index i) {
164 auto idx = get_position(i);
165 if (birthToCycle_[idx] != nullValue) {
166 auto& col = _matrix()->get_column(_matrix()->get_column_with_pivot(i));
167 representativeCycles_[birthToCycle_[idx]] =
168 Master_matrix::build_cycle_from_range(col.get_non_zero_content_range());
172 for (
ID_index i = 0; i < nberColumns; i++) {
173 auto& col = _matrix()->get_column(_matrix()->get_column_with_pivot(i));
174 if ((dim == Master_matrix::template get_null_value<Dimension>() || _matrix()->get_column_dimension(i) == dim) &&
175 (!col.is_paired() || get_position(i) < get_position(_matrix()->get_pivot(col.get_paired_chain_index())))) {
176 representativeCycles_.push_back(Master_matrix::build_cycle_from_range(col.get_non_zero_content_range()));
177 birthToCycle_[get_position(i)] = representativeCycles_.size() - 1;
183template <
class Master_matrix>
186 auto nberColumns = _matrix()->get_number_of_columns();
187 auto get_position = [&](
ID_index pivot) {
188 if constexpr (Master_matrix::Option_list::has_vine_update) {
189 if constexpr (Master_matrix::Option_list::has_map_column_container) {
190 return _matrix()->map_.at(pivot);
192 return _matrix()->map_[pivot];
199 Index nullValue = Master_matrix::template get_null_value<Index>();
201 if (birthToCycle_.size() <= bar.birth) {
202 birthToCycle_.resize(bar.birth + 1, nullValue);
204 if (birthToCycle_[bar.birth] == nullValue) {
205 birthToCycle_[bar.birth] = representativeCycles_.size();
206 representativeCycles_.resize(representativeCycles_.size() + 1);
211 if constexpr (Master_matrix::Option_list::has_vine_update) {
213 while (i < nberColumns && get_position(i) != bar.birth) ++i;
214 GUDHI_CHECK(i < nberColumns, std::invalid_argument(
"Given birth value is not valid."));
219 auto& col = _matrix()->get_column(_matrix()->get_column_with_pivot(pivot));
220 representativeCycles_[birthToCycle_[bar.birth]] =
221 Master_matrix::build_cycle_from_range(col.get_non_zero_content_range());
224template <
class Master_matrix>
225inline const std::vector<typename Chain_representative_cycles<Master_matrix>::Cycle>&
228 return representativeCycles_;
231template <
class Master_matrix>
235 return representativeCycles_[birthToCycle_[bar.birth]];
238template <
class Master_matrix>
239inline void Chain_representative_cycles<Master_matrix>::_reset()
241 representativeCycles_.clear();
242 birthToCycle_.clear();
typename Master_matrix::Bar Bar
Definition chain_rep_cycles.h:58
const Cycle & get_representative_cycle(const Bar &bar) const
Returns the representative cycle corresponding to the given bar. If the matrix was modified since the...
Definition chain_rep_cycles.h:233
typename Master_matrix::Dimension Dimension
Definition chain_rep_cycles.h:63
typename Master_matrix::Cycle Cycle
Definition chain_rep_cycles.h:59
void update_all_representative_cycles(Dimension dim=Master_matrix::template get_null_value< Dimension >())
Computes the current representative cycles of the matrix.
Definition chain_rep_cycles.h:131
typename Master_matrix::Index Index
Definition chain_rep_cycles.h:61
friend void swap(Chain_representative_cycles &base1, Chain_representative_cycles &base2) noexcept
Swap operator.
Definition chain_rep_cycles.h:109
const std::vector< Cycle > & get_all_representative_cycles() const
Returns the current representative cycles. If the matrix was modified since the last call,...
Definition chain_rep_cycles.h:226
Chain_representative_cycles()=default
Default constructor.
void update_representative_cycle(const Bar &bar)
Computes the current representative cycle of the given bar. All other cycles already computed are lef...
Definition chain_rep_cycles.h:184
typename Master_matrix::ID_index ID_index
Definition chain_rep_cycles.h:62
typename Master_matrix::Column_container Column_container
Definition chain_rep_cycles.h:60
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Contains the options for the matrix template.
Empty structure. Inherited instead of Chain_representative_cycles, when the computation of the repres...
Definition chain_rep_cycles.h:40