Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from gudhi #20

Merged
merged 10 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions multipers/gudhi/gudhi/Multi_persistence/Line.h
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef LINE_FILTRATION_TRANSLATION_H_INCLUDED
#define LINE_FILTRATION_TRANSLATION_H_INCLUDED

#include <cmath>
#include <cstddef>
#include <stdexcept>
#include <limits>
Expand Down Expand Up @@ -82,6 +83,15 @@ class Line {
* the number of coordinates.
*/
Point operator[](T t) const {
GUDHI_CHECK(direction_.empty() || direction_.size() == basePoint_.size(),
"Direction and base point do not have the same dimension.");

if constexpr (std::numeric_limits<T>::has_quiet_NaN){ //to avoid windows error
if (std::isnan(t)) return Point::nan();
}
if (t == Point::T_inf) return Point::inf();
if (t == -Point::T_inf) return Point::minus_inf();

Point x(basePoint_.size());

if (direction_.size() > 0) {
Expand Down Expand Up @@ -222,21 +232,21 @@ class Line {
}

/**
* @brief Given a box, returns the intersection of this box and the line.
* @brief Given a box, returns "time" parameter of the intersection of this box and the line.
*
* @param box Box to intersect.
* @return A pair representing the two bounding points of the intersection, such that the first element is the
* smallest of the two. If the box and the line do not intersect, returns the pair {inf, inf}.
* smallest of the two. If the box and the line do not intersect or the box is trivial, returns the pair {inf, -inf}.
*/
std::pair<Point, Point> get_bounds(const Box<T> &box) const {
if (box.is_trivial()) return {Point::inf(), Point::inf()};
std::pair<T, T> get_bounds(const Box<T> &box) const {
if (box.is_trivial()) return {Point::T_inf, -Point::T_inf};

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

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

return {(*this)[bottom], (*this)[top]};
return {bottom, top};
}

private:
Expand Down
24 changes: 10 additions & 14 deletions multipers/gudhi/truc.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class Truc {
}
}
template <class SubFiltration, bool original_order = true>
inline void push_to_least_common_upper_bound(const SubFiltration &f) {
inline void push_to(const SubFiltration &f) {
this->push_to_out<SubFiltration, original_order>(
f, this->filtration_container, this->generator_order);
}
Expand Down Expand Up @@ -735,7 +735,7 @@ class Truc {
truc_ptr->coarsen_on_grid_inplace(grid, coordinate);
}
template <typename Subfiltration>
inline void push_to_least_common_upper_bound(const Subfiltration &f) {
inline void push_to(const Subfiltration &f) {
truc_ptr->push_to_out(f, this->filtration_container,
this->generator_order);
}
Expand Down Expand Up @@ -808,11 +808,11 @@ class Truc {
std::vector<split_barcode> out(args.size());

if constexpr (PersBackend::is_vine) {
this->push_to_least_common_upper_bound(f(args[0]));
this->push_to(f(args[0]));
this->compute_persistence();
out[0] = this->get_barcode();
for (auto i = 1u; i < args.size(); ++i) {
this->push_to_least_common_upper_bound(f(args[i]));
this->push_to(f(args[i]));
this->vineyard_update();
out[i] = this->get_barcode();
}
Expand All @@ -823,7 +823,7 @@ class Truc {
tbb::parallel_for(static_cast<std::size_t>(0), args.size(),
[&](const std::size_t &i) {
ThreadSafe &s = thread_locals.local();
s.push_to_least_common_upper_bound(f(args[i]));
s.push_to(f(args[i]));
s.compute_persistence();
out[i] = s.get_barcode();
});
Expand All @@ -832,20 +832,16 @@ class Truc {
}
// FOR Python interface, but I'm not fan. Todo: do the lambda function in
// cython?
inline std::vector<split_barcode>
persistence_on_lines(const std::vector<std::vector<value_type>> &basepoints) {
inline std::vector<split_barcode> persistence_on_lines(const std::vector<std::vector<value_type>> &basepoints) {
return barcodes(
[](const std::vector<value_type> &basepoint) {
return Gudhi::multi_persistence::Line<value_type>(basepoint);
},
[](const std::vector<value_type> &basepoint) { return Gudhi::multi_persistence::Line<value_type>(basepoint); },
basepoints);
}

inline std::vector<split_barcode> persistence_on_lines(
const std::vector<std::pair<std::vector<value_type>,
std::vector<value_type>>> &bp_dirs) {
const std::vector<std::pair<std::vector<value_type>, std::vector<value_type>>> &bp_dirs) {
return barcodes(
[](const std::pair<std::vector<value_type>, std::vector<value_type>>
&bpdir) {
[](const std::pair<std::vector<value_type>, std::vector<value_type>> &bpdir) {
return Gudhi::multi_persistence::Line<value_type>(bpdir.first, bpdir.second);
},
bp_dirs);
Expand Down
Loading
Loading