Loading...
Searching...
No Matches
persistence_interval.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) 2024 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#ifndef PM_INTERVAL_INCLUDED
#define PM_INTERVAL_INCLUDED
#include <ostream> //std::ostream
#include <limits> //std::numeric_limits
#include <tuple>
#include <utility> //std::move
namespace Gudhi {
namespace persistence_matrix {
template <typename Dimension, typename Event_value>
struct Persistence_interval {
static constexpr Event_value inf = std::numeric_limits<Event_value>::has_infinity
? std::numeric_limits<Event_value>::infinity()
: static_cast<Event_value>(-1);
Persistence_interval(Event_value birth = inf, Event_value death = inf, Dimension dim = -1)
: dim(dim), birth(birth), death(death) {}
Dimension dim;
Event_value birth;
Event_value death;
inline friend std::ostream& operator<<(std::ostream& stream, const Persistence_interval& interval) {
stream << "[" << interval.dim << "] ";
if constexpr (std::numeric_limits<Event_value>::has_infinity) {
stream << interval.birth << " - " << interval.death;
} else {
if (interval.birth == inf)
stream << "inf";
else
stream << interval.birth;
stream << " - ";
if (interval.death == inf)
stream << "inf";
else
stream << interval.death;
}
return stream;
}
template <std::size_t I>
constexpr auto& get() & noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
if constexpr (I == 0) return birth;
if constexpr (I == 1) return death;
if constexpr (I == 2) return dim;
}
template <std::size_t I>
constexpr const auto& get() const& noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
if constexpr (I == 0) return birth;
if constexpr (I == 1) return death;
if constexpr (I == 2) return dim;
}
template <std::size_t I>
constexpr auto&& get() && noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
if constexpr (I == 0) return std::move(birth);
if constexpr (I == 1) return std::move(death);
if constexpr (I == 2) return std::move(dim);
}
template <std::size_t I>
constexpr const auto&& get() const&& noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
if constexpr (I == 0) return std::move(birth);
if constexpr (I == 1) return std::move(death);
if constexpr (I == 2) return std::move(dim);
}
};
} // namespace persistence_matrix
} // namespace Gudhi
namespace std {
template <typename Dimension, typename Event_value>
struct tuple_size<Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value> >
: integral_constant<size_t, 3> {};
template <size_t I, typename Dimension, typename Event_value>
struct tuple_element<I, Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value> > {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
using type = typename conditional <I < 2, Event_value, Dimension>::type;
};
template <size_t I, typename Dimension, typename Event_value>
constexpr auto& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
return i.template get<I>();
}
template <size_t I, typename Dimension, typename Event_value>
constexpr const auto& get(const Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
return i.template get<I>();
}
template <size_t I, typename Dimension, typename Event_value>
constexpr auto&& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>&& i) noexcept {
return std::move(i).template get<I>();
}
template <size_t I, typename Dimension, typename Event_value>
constexpr const auto&& get(const Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>&& i) noexcept {
return std::move(i).template get<I>();
}
} // namespace std
#endif // PM_INTERVAL_INCLUDED
std::get
constexpr auto & get(Gudhi::persistence_matrix::Persistence_interval< Dimension, Event_value > &i) noexcept
Partial specialization of get for Gudhi::persistence_matrix::Persistence_interval.
Definition persistence_interval.h:199
Gudhi::persistence_matrix
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
std
STL namespace.
Gudhi::persistence_matrix::Persistence_interval
Type for an interval in a persistent diagram or barcode. Stores the birth, death and dimension of the...
Definition persistence_interval.h:40
Gudhi::persistence_matrix::Persistence_interval::get
constexpr const auto && get() const &&noexcept
Specialization of get for Gudhi::persistence_matrix::Persistence_interval.
Definition persistence_interval.h:144
Gudhi::persistence_matrix::Persistence_interval< Dimension, Internal_key >::dim
Dimension dim
Definition persistence_interval.h:64
Gudhi::persistence_matrix::Persistence_interval< Dimension, Internal_key >::inf
static constexpr Internal_key inf
Definition persistence_interval.h:50
Gudhi::persistence_matrix::Persistence_interval::get
constexpr auto && get() &&noexcept
Specialization of get for Gudhi::persistence_matrix::Persistence_interval.
Definition persistence_interval.h:129
Gudhi::persistence_matrix::Persistence_interval< Dimension, Internal_key >::death
Internal_key death
Definition persistence_interval.h:66
Gudhi::persistence_matrix::Persistence_interval::get
constexpr auto & get() &noexcept
Specialization of get for Gudhi::persistence_matrix::Persistence_interval.
Definition persistence_interval.h:99
Gudhi::persistence_matrix::Persistence_interval::get
constexpr const auto & get() const &noexcept
Specialization of get for Gudhi::persistence_matrix::Persistence_interval.
Definition persistence_interval.h:114
Gudhi::persistence_matrix::Persistence_interval< Dimension, Internal_key >::birth
Internal_key birth
Definition persistence_interval.h:65
Gudhi::persistence_matrix::Persistence_interval::operator<<
friend std::ostream & operator<<(std::ostream &stream, const Persistence_interval &interval)
operator<<
Definition persistence_interval.h:74
Gudhi::persistence_matrix::Persistence_interval::Persistence_interval
Persistence_interval(Event_value birth=inf, Event_value death=inf, Dimension dim=-1)
Constructor.
Definition persistence_interval.h:61