Loading...
Searching...
No Matches
filtration_value_utils.h
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) 2025 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef SIMPLEX_TREE_FILTRATION_VALUE_UTILS_H_
12#define SIMPLEX_TREE_FILTRATION_VALUE_UTILS_H_
13
14#include <cstddef> // std::size_t
15#include <limits> // std::numeric_limits
16#include <cmath> // std::isnan
17
18#include <gudhi/Simplex_tree/serialization_utils.h>
19
20namespace Gudhi {
21
22namespace simplex_tree {
23
29 template <class T> explicit operator T() const { return T(0); }
30} empty_filtration_value;
31
32} // namespace simplex_tree
33
42template <typename Arithmetic_filtration_value>
43bool is_positive_infinity(const Arithmetic_filtration_value& f)
44{
45 if constexpr (std::numeric_limits<Arithmetic_filtration_value>::has_infinity) {
46 return f == std::numeric_limits<Arithmetic_filtration_value>::infinity();
47 } else {
48 return f == std::numeric_limits<Arithmetic_filtration_value>::max();
49 }
50}
51
61template <typename Arithmetic_filtration_value>
62bool unify_lifetimes(Arithmetic_filtration_value& f1, const Arithmetic_filtration_value& f2)
63{
64 if (f2 < f1){
65 f1 = f2;
66 return true;
67 }
68 return false;
69}
70
78template <typename Arithmetic_filtration_value>
79bool intersect_lifetimes(Arithmetic_filtration_value& f1, const Arithmetic_filtration_value& f2)
80{
81 if constexpr (std::numeric_limits<Arithmetic_filtration_value>::has_quiet_NaN) {
82 if (std::isnan(f1)) {
83 f1 = f2;
84 return !std::isnan(f2);
85 }
86
87 // Computes the max while handling NaN as lowest value.
88 if (!(f1 < f2)) return false;
89
90 f1 = f2;
91 return true;
92 } else {
93 // NaN not possible.
94 if (f1 < f2){
95 f1 = f2;
96 return true;
97 }
98 return false;
99 }
100}
101
116template <typename Trivial_filtration_value>
117char* serialize_value_to_char_buffer(Trivial_filtration_value value, char* start) {
118 return Gudhi::simplex_tree::serialize_trivial(value, start);
119}
120
135template <typename Trivial_filtration_value>
136const char* deserialize_value_from_char_buffer(Trivial_filtration_value& value, const char* start) {
137 return Gudhi::simplex_tree::deserialize_trivial(value, start);
138}
139
148template<typename Trivial_filtration_value>
149constexpr std::size_t get_serialization_size_of([[maybe_unused]] Trivial_filtration_value value) {
150 return sizeof(Trivial_filtration_value);
151}
152
153} // namespace Gudhi
154
155#endif // SIMPLEX_TREE_FILTRATION_VALUE_UTILS_H_
bool is_positive_infinity(const Arithmetic_filtration_value &f)
Returns true if and only if the given filtration value is at infinity. This is the overload for when ...
Definition filtration_value_utils.h:43
bool unify_lifetimes(Arithmetic_filtration_value &f1, const Arithmetic_filtration_value &f2)
Given two filtration values at which a simplex exists, stores in the first value the minimal union of...
Definition filtration_value_utils.h:62
bool intersect_lifetimes(Arithmetic_filtration_value &f1, const Arithmetic_filtration_value &f2)
Given two filtration values, stores in the first value the lowest common upper bound of the two value...
Definition filtration_value_utils.h:79
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Returns Filtration_value(0) when converted to Filtration_value.
Definition filtration_value_utils.h:28