Loading...
Searching...
No Matches
ru_rep_cycles.h
Go to the documentation of this file.
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Hannah Schreiber
*
* Copyright (C) 2022-24 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#ifndef PM_RU_REP_CYCLES_H
#define PM_RU_REP_CYCLES_H
#include <utility> //std::move
#include <algorithm> //std::sort
#include <vector>
namespace Gudhi {
namespace persistence_matrix {
struct Dummy_ru_representative_cycles
{
friend void swap([[maybe_unused]] Dummy_ru_representative_cycles& d1,
[[maybe_unused]] Dummy_ru_representative_cycles& d2) {}
};
// TODO: add coefficients ? Only Z2 token into account for now.
template <class Master_matrix>
class RU_representative_cycles
{
public:
using Index = typename Master_matrix::Index;
using Bar = typename Master_matrix::Bar;
using Cycle = typename Master_matrix::Cycle;
RU_representative_cycles();
RU_representative_cycles(const RU_representative_cycles& matrixToCopy);
RU_representative_cycles(RU_representative_cycles&& other) noexcept;
void update_representative_cycles();
const std::vector<Cycle>& get_representative_cycles();
const Cycle& get_representative_cycle(const Bar& bar);
RU_representative_cycles& operator=(RU_representative_cycles other);
friend void swap(RU_representative_cycles& base1, RU_representative_cycles& base2) {
base1.representativeCycles_.swap(base2.representativeCycles_);
base1.birthToCycle_.swap(base2.birthToCycle_);
}
private:
using Master_RU_matrix = typename Master_matrix::Master_RU_matrix;
std::vector<Cycle> representativeCycles_;
std::vector<Index> birthToCycle_;
constexpr Master_RU_matrix* _matrix() { return static_cast<Master_RU_matrix*>(this); }
constexpr const Master_RU_matrix* _matrix() const { return static_cast<const Master_RU_matrix*>(this); }
};
template <class Master_matrix>
inline RU_representative_cycles<Master_matrix>::RU_representative_cycles()
{}
template <class Master_matrix>
inline RU_representative_cycles<Master_matrix>::RU_representative_cycles(
const RU_representative_cycles<Master_matrix>& matrixToCopy)
: representativeCycles_(matrixToCopy.representativeCycles_), birthToCycle_(matrixToCopy.birthToCycle_)
{}
template <class Master_matrix>
inline RU_representative_cycles<Master_matrix>::RU_representative_cycles(
RU_representative_cycles<Master_matrix>&& other) noexcept
: representativeCycles_(std::move(other.representativeCycles_)), birthToCycle_(std::move(other.birthToCycle_))
{}
template <class Master_matrix>
inline void RU_representative_cycles<Master_matrix>::update_representative_cycles()
{
if constexpr (Master_matrix::Option_list::is_z2) {
birthToCycle_.clear();
birthToCycle_.resize(_matrix()->reducedMatrixR_.get_number_of_columns(), -1);
Index c = 0;
for (Index i = 0; i < _matrix()->reducedMatrixR_.get_number_of_columns(); i++) {
if (_matrix()->reducedMatrixR_.is_zero_column(i)) {
birthToCycle_[i] = c;
++c;
}
}
representativeCycles_.clear();
representativeCycles_.resize(c);
for (Index i = 0; i < _matrix()->mirrorMatrixU_.get_number_of_columns(); i++) {
for (const auto& entry : _matrix()->mirrorMatrixU_.get_column(i)) {
auto idx = birthToCycle_[entry.get_row_index()];
if (idx != Master_matrix::template get_null_value<Index>()) {
representativeCycles_[idx].push_back(i);
}
}
}
} else {
birthToCycle_.clear();
birthToCycle_.resize(_matrix()->reducedMatrixR_.get_number_of_columns(), -1);
for (Index i = 0; i < _matrix()->reducedMatrixR_.get_number_of_columns(); i++) {
if (_matrix()->reducedMatrixR_.is_zero_column(i)) {
representativeCycles_.push_back(Cycle());
for (const auto& entry : _matrix()->mirrorMatrixU_.get_column(i)) {
representativeCycles_.back().push_back(entry.get_row_index());
}
if constexpr (std::is_same_v<typename Master_matrix::Column, typename Master_matrix::Matrix_heap_column> ||
std::is_same_v<typename Master_matrix::Column,
typename Master_matrix::Matrix_unordered_set_column>)
std::sort(representativeCycles_.back().begin(), representativeCycles_.back().end());
birthToCycle_[i] = representativeCycles_.size() - 1;
}
}
}
}
template <class Master_matrix>
inline const std::vector<typename RU_representative_cycles<Master_matrix>::Cycle>&
RU_representative_cycles<Master_matrix>::get_representative_cycles()
{
if (representativeCycles_.empty()) update_representative_cycles();
return representativeCycles_;
}
template <class Master_matrix>
inline const typename RU_representative_cycles<Master_matrix>::Cycle&
RU_representative_cycles<Master_matrix>::get_representative_cycle(const Bar& bar)
{
if (representativeCycles_.empty()) update_representative_cycles();
return representativeCycles_[birthToCycle_[bar.birth]];
}
template <class Master_matrix>
inline RU_representative_cycles<Master_matrix>& RU_representative_cycles<Master_matrix>::operator=(
RU_representative_cycles<Master_matrix> other)
{
representativeCycles_.swap(other.representativeCycles_);
birthToCycle_.swap(other.birthToCycle_);
return *this;
}
} // namespace persistence_matrix
} // namespace Gudhi
#endif // PM_RU_REP_CYCLES_H
Gudhi::persistence_matrix::RU_representative_cycles::get_representative_cycle
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 ru_rep_cycles.h:187
Gudhi::persistence_matrix::RU_representative_cycles::Index
typename Master_matrix::Index Index
Definition ru_rep_cycles.h:54
Gudhi::persistence_matrix::RU_representative_cycles::RU_representative_cycles
RU_representative_cycles()
Default constructor.
Definition ru_rep_cycles.h:120
Gudhi::persistence_matrix::RU_representative_cycles::swap
friend void swap(RU_representative_cycles &base1, RU_representative_cycles &base2)
Swap operator.
Definition ru_rep_cycles.h:104
Gudhi::persistence_matrix::RU_representative_cycles::Bar
typename Master_matrix::Bar Bar
Definition ru_rep_cycles.h:55
Gudhi::persistence_matrix::RU_representative_cycles::get_representative_cycles
const std::vector< Cycle > & get_representative_cycles()
Returns the current representative cycles. If the matrix is modified later after the first call,...
Definition ru_rep_cycles.h:179
Gudhi::persistence_matrix::RU_representative_cycles::Cycle
typename Master_matrix::Cycle Cycle
Definition ru_rep_cycles.h:56
Gudhi::persistence_matrix::RU_representative_cycles::update_representative_cycles
void update_representative_cycles()
Computes the current representative cycles of the matrix.
Definition ru_rep_cycles.h:136
Gudhi::persistence_matrix::RU_representative_cycles::operator=
RU_representative_cycles & operator=(RU_representative_cycles other)
Assign operator.
Definition ru_rep_cycles.h:194
Gudhi::persistence_matrix
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Gudhi::persistence_matrix::Dummy_ru_representative_cycles
Empty structure. Inherited instead of RU_representative_cycles, when the computation of the represent...
Definition ru_rep_cycles.h:36