Skip to content

Commit 02cb463

Browse files
committed
small fixes
1 parent d2a2168 commit 02cb463

File tree

4 files changed

+71
-19
lines changed

4 files changed

+71
-19
lines changed

src/Multi_filtration/include/gudhi/Multi_critical_filtration.h

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ class Multi_critical_filtration {
247247
return multi_filtration_[0];
248248
}
249249

250+
/**
251+
* @brief Casts the object into the type of a generator.
252+
* @pre The filtration value is 1-critical. If there are more than one generator, only the first will be preserved
253+
* and if there is no generator, the method will segfault.
254+
*/
255+
operator const Generator() const {
256+
GUDHI_CHECK(num_generators() == 1, "Casting a " + std::to_string(num_generators()) +
257+
"-critical filtration value into an 1-critical filtration value.");
258+
return multi_filtration_[0];
259+
}
260+
250261
// like numpy
251262
/**
252263
* @brief Returns a copy with entries casted into the type given as template parameter.
@@ -847,14 +858,42 @@ class Multi_critical_filtration {
847858
// no nan values and if there is an inf/-inf, then 'end - curr == 1'
848859
// modifies multi_filtration_ only if true is returned.
849860
bool _generator_can_be_added(const Generator &x, std::size_t curr, std::size_t &end) {
850-
if (x.empty() || x.is_nan() || (x.is_plus_inf() && end - curr != 0)) return false;
861+
if (x.empty() || x.is_nan()) return false;
851862

852-
if (x.is_minus_inf()) {
853-
if (end - curr == 1 && multi_filtration_[curr].is_minus_inf()) return false;
854-
// assumes that everything between curr and end is already simplified
855-
// so, if end - curr != 1, there can be no minus_inf anymore.
856-
end = curr;
857-
return true;
863+
// assumes that everything between curr and end is simplified
864+
// so, only multi_filtration_[curr] can be at inf or -inf.
865+
if constexpr (co) {
866+
if (multi_filtration_[curr].is_plus_inf() || (x.is_minus_inf() && end - curr != 0)) {
867+
return false;
868+
}
869+
if (multi_filtration_[curr].is_minus_inf()) {
870+
if (x.is_minus_inf()) {
871+
return false;
872+
}
873+
end = curr;
874+
return true;
875+
}
876+
if (x.is_plus_inf()) {
877+
if (multi_filtration_[curr].is_plus_inf()) return false;
878+
end = curr;
879+
return true;
880+
}
881+
} else {
882+
if (multi_filtration_[curr].is_minus_inf() || (x.is_plus_inf() && end - curr != 0)) {
883+
return false;
884+
}
885+
if (multi_filtration_[curr].is_plus_inf()) {
886+
if (x.is_plus_inf()) {
887+
return false;
888+
}
889+
end = curr;
890+
return true;
891+
}
892+
if (x.is_minus_inf()) {
893+
if (multi_filtration_[curr].is_minus_inf()) return false;
894+
end = curr;
895+
return true;
896+
}
858897
}
859898

860899
while (curr != end) {

src/Multi_filtration/test/multifiltration_multicritical_unit_test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(multi_critical_filtration_add, T, list_of_tested_v
421421
BOOST_CHECK_EQUAL(f5[0][0], 0);
422422
BOOST_CHECK_EQUAL(f5[0][1], 1);
423423
BOOST_CHECK_EQUAL(f5[0][2], 2);
424+
425+
Multi_critical_filtration<T, true> f6 = Multi_critical_filtration<T, true>::minus_inf();
426+
bool change = f6.add_generator(Multi_critical_filtration<T, true>::inf());
427+
BOOST_CHECK(change);
428+
BOOST_CHECK(f6.is_plus_inf());
424429
}
425430

426431
BOOST_AUTO_TEST_CASE_TEMPLATE(multi_critical_filtration_friends, T, list_of_tested_variants)

src/Multi_persistence/include/gudhi/Multi_persistence/Line.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef LINE_FILTRATION_TRANSLATION_H_INCLUDED
1919
#define LINE_FILTRATION_TRANSLATION_H_INCLUDED
2020

21+
#include <cmath>
2122
#include <cstddef>
2223
#include <stdexcept>
2324
#include <limits>
@@ -85,6 +86,12 @@ class Line {
8586
GUDHI_CHECK(direction_.empty() || direction_.size() == basePoint_.size(),
8687
"Direction and base point do not have the same dimension.");
8788

89+
if constexpr (std::numeric_limits<T>::has_quiet_NaN){ //to avoid windows error
90+
if (std::isnan(t)) return Point::nan();
91+
}
92+
if (t == Point::T_inf) return Point::inf();
93+
if (t == -Point::T_inf) return Point::minus_inf();
94+
8895
Point x(basePoint_.size());
8996

9097
if (direction_.size() > 0) {
@@ -225,22 +232,21 @@ class Line {
225232
}
226233

227234
/**
228-
* @brief Given a box, returns the intersection of this box and the line.
235+
* @brief Given a box, returns "time" parameter of the intersection of this box and the line.
229236
*
230237
* @param box Box to intersect.
231238
* @return A pair representing the two bounding points of the intersection, such that the first element is the
232-
* smallest of the two. If the box and the line do not intersect, returns the pair {inf, inf}.
233-
* If the box is trivial, returns {NaN, NaN}.
239+
* smallest of the two. If the box and the line do not intersect or the box is trivial, returns the pair {inf, -inf}.
234240
*/
235-
std::pair<Point, Point> get_bounds(const Box<T> &box) const {
236-
if (box.is_trivial()) return {Point::nan(), Point::nan()};
241+
std::pair<T, T> get_bounds(const Box<T> &box) const {
242+
if (box.is_trivial()) return {Point::T_inf, -Point::T_inf};
237243

238244
T bottom = compute_forward_intersection(box.get_lower_corner());
239245
T top = compute_backward_intersection(box.get_upper_corner());
240246

241-
if (bottom > top) return {Point::inf(), Point::inf()}; // no intersection
247+
if (bottom > top) return {Point::T_inf, -Point::T_inf}; // no intersection
242248

243-
return {(*this)[bottom], (*this)[top]};
249+
return {bottom, top};
244250
}
245251

246252
private:

src/Multi_persistence/test/multipersistence_line_unit_test.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(line_intersections, T, list_of_tested_variants)
8787
t = l.template compute_backward_intersection<double>(KP({P{2,1,3}, P{2,3,3}}));
8888
BOOST_CHECK_EQUAL(t, 0);
8989

90-
std::pair<P, P> bounds = l.get_bounds({{-10, 0, 10}, {10, 4, 10}});
91-
auto& bottom = bounds.first;
92-
auto& top = bounds.second;
90+
std::pair<T, T> bounds = l.get_bounds({{-10, 0, 10}, {10, 4, 10}});
91+
auto bottom = l[bounds.first];
92+
auto top = l[bounds.second];
9393
BOOST_CHECK_EQUAL(bottom.size(), 3);
9494
BOOST_CHECK_EQUAL(bottom[0], T(5. + 2. / 3.));
9595
BOOST_CHECK_EQUAL(bottom[1], 2);
@@ -100,8 +100,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(line_intersections, T, list_of_tested_variants)
100100
BOOST_CHECK_EQUAL(top[2], T(3. + T(7. / 6.) * 6.));
101101

102102
bounds = l.get_bounds({{-10, 0, 10}, {10, 1, 10}});
103-
BOOST_CHECK(bounds.first.is_plus_inf());
104-
BOOST_CHECK(bounds.second.is_plus_inf());
103+
BOOST_CHECK_EQUAL(bounds.first, P::T_inf);
104+
BOOST_CHECK_EQUAL(bounds.second, -P::T_inf);
105+
BOOST_CHECK(l[bounds.first].is_plus_inf());
106+
BOOST_CHECK(l[bounds.second].is_minus_inf());
105107
}
106108

107109
BOOST_AUTO_TEST_CASE_TEMPLATE(line_other, T, list_of_tested_variants)

0 commit comments

Comments
 (0)