diff options
-rw-r--r-- | Dockerfile_for_circleci_image | 2 | ||||
-rw-r--r-- | src/Alpha_complex/include/gudhi/Alpha_complex.h | 18 | ||||
-rw-r--r-- | src/Alpha_complex/test/Alpha_complex_unit_test.cpp | 60 | ||||
-rw-r--r-- | src/Bottleneck_distance/test/bottleneck_unit_test.cpp | 37 | ||||
-rw-r--r-- | src/Persistence_representations/include/gudhi/Persistence_intervals.h | 5 | ||||
-rw-r--r-- | src/Persistence_representations/test/persistence_intervals_test.cpp | 211 | ||||
-rw-r--r-- | src/common/include/gudhi/Unitary_tests_utils.h | 11 | ||||
-rw-r--r-- | src/python/CMakeLists.txt | 21 | ||||
-rw-r--r-- | src/python/gudhi/alpha_complex.pyx | 4 | ||||
-rw-r--r-- | src/python/include/Alpha_complex_interface.h | 5 | ||||
-rwxr-xr-x | src/python/test/test_alpha_complex.py | 29 |
11 files changed, 173 insertions, 230 deletions
diff --git a/Dockerfile_for_circleci_image b/Dockerfile_for_circleci_image index f0c73d76..ff4e6018 100644 --- a/Dockerfile_for_circleci_image +++ b/Dockerfile_for_circleci_image @@ -25,6 +25,7 @@ ENV LC_ALL en_US.UTF-8 # Required for Gudhi compilation RUN apt-get install -y make \ + git \ g++ \ cmake \ graphviz \ @@ -43,6 +44,7 @@ RUN apt-get install -y make \ python3-pip \ python3-pytest \ python3-tk \ + python3-pybind11 \ libfreetype6-dev \ pkg-config diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 6b4d8463..f2a05e95 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -121,8 +121,8 @@ class Alpha_complex { // size_type type from CGAL. typedef typename Delaunay_triangulation::size_type size_type; - // Map type to switch from simplex tree vertex handle to CGAL vertex iterator. - typedef typename std::map< std::size_t, CGAL_vertex_iterator > Vector_vertex_iterator; + // Structure to switch from simplex tree vertex handle to CGAL vertex iterator. + typedef typename std::vector< CGAL_vertex_iterator > Vector_vertex_iterator; private: /** \brief Vertex iterator vector to switch from simplex tree vertex handle to CGAL vertex iterator. @@ -191,14 +191,6 @@ class Alpha_complex { return vertex_handle_to_iterator_.at(vertex)->point(); } - /** \brief number_of_vertices returns the number of vertices (same as the number of points). - * - * @return The number of vertices. - */ - std::size_t number_of_vertices() const { - return vertex_handle_to_iterator_.size(); - } - private: template<typename InputPointRange > void init_from_range(const InputPointRange& points) { @@ -238,14 +230,16 @@ class Alpha_complex { hint = pos->full_cell(); } // -------------------------------------------------------------------------------------------- - // double map to retrieve simplex tree vertex handles from CGAL vertex iterator and vice versa + // structure to retrieve CGAL points from vertex handle - one vertex handle per point. + // Needs to be constructed before as vertex handles arrives in no particular order. + vertex_handle_to_iterator_.resize(point_cloud.size()); // Loop on triangulation vertices list for (CGAL_vertex_iterator vit = triangulation_->vertices_begin(); vit != triangulation_->vertices_end(); ++vit) { if (!triangulation_->is_infinite(*vit)) { #ifdef DEBUG_TRACES std::cout << "Vertex insertion - " << vit->data() << " -> " << vit->point() << std::endl; #endif // DEBUG_TRACES - vertex_handle_to_iterator_.emplace(vit->data(), vit); + vertex_handle_to_iterator_[vit->data()] = vit; } } // -------------------------------------------------------------------------------------------- diff --git a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp index 40b3fe09..27b671dd 100644 --- a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp @@ -53,20 +53,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_OFF_file, TestedKernel, list_of Gudhi::alpha_complex::Alpha_complex<TestedKernel> alpha_complex_from_file(off_file_name); - std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_file.number_of_vertices() - << std::endl; - BOOST_CHECK(alpha_complex_from_file.number_of_vertices() == 7); - Gudhi::Simplex_tree<> simplex_tree_60; BOOST_CHECK(alpha_complex_from_file.create_complex(simplex_tree_60, max_alpha_square_value)); std::cout << "simplex_tree_60.dimension()=" << simplex_tree_60.dimension() << std::endl; BOOST_CHECK(simplex_tree_60.dimension() == 2); - std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_file.number_of_vertices() - << std::endl; - BOOST_CHECK(alpha_complex_from_file.number_of_vertices() == 7); - std::cout << "simplex_tree_60.num_vertices()=" << simplex_tree_60.num_vertices() << std::endl; BOOST_CHECK(simplex_tree_60.num_vertices() == 7); @@ -128,10 +120,6 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) { Gudhi::Simplex_tree<> simplex_tree; BOOST_CHECK(alpha_complex_from_points.create_complex(simplex_tree)); - std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_points.number_of_vertices() - << std::endl; - BOOST_CHECK(alpha_complex_from_points.number_of_vertices() == points.size()); - // Another way to check num_simplices std::cout << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; int num_simplices = 0; @@ -151,7 +139,7 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) { std::cout << "simplex_tree.dimension()=" << simplex_tree.dimension() << std::endl; BOOST_CHECK(simplex_tree.dimension() == 3); std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices() << std::endl; - BOOST_CHECK(simplex_tree.num_vertices() == 4); + BOOST_CHECK(simplex_tree.num_vertices() == points.size()); for (auto f_simplex : simplex_tree.filtration_simplex_range()) { switch (simplex_tree.dimension(f_simplex)) { @@ -261,10 +249,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_empty_points, TestedKernel, lis Gudhi::Simplex_tree<> simplex_tree; BOOST_CHECK(!alpha_complex_from_points.create_complex(simplex_tree)); - std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_points.number_of_vertices() - << std::endl; - BOOST_CHECK(alpha_complex_from_points.number_of_vertices() == points.size()); - std::cout << "simplex_tree.num_simplices()=" << simplex_tree.num_simplices() << std::endl; BOOST_CHECK(simplex_tree.num_simplices() == 0); @@ -272,5 +256,45 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_empty_points, TestedKernel, lis BOOST_CHECK(simplex_tree.dimension() == -1); std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices() << std::endl; - BOOST_CHECK(simplex_tree.num_vertices() == 0); + BOOST_CHECK(simplex_tree.num_vertices() == points.size()); +} + +using Inexact_kernel_2 = CGAL::Epick_d< CGAL::Dimension_tag<2> >; +using Exact_kernel_2 = CGAL::Epeck_d< CGAL::Dimension_tag<2> >; +using list_of_kernel_2_variants = boost::mpl::list<Inexact_kernel_2, Exact_kernel_2>; + +BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_with_duplicated_points, TestedKernel, list_of_kernel_2_variants) { + std::cout << "========== Alpha_complex_with_duplicated_points ==========" << std::endl; + + using Point = typename TestedKernel::Point_d; + using Vector_of_points = std::vector<Point>; + + // ---------------------------------------------------------------------------- + // Init of a list of points + // ---------------------------------------------------------------------------- + Vector_of_points points; + points.push_back(Point(1.0, 1.0)); + points.push_back(Point(7.0, 0.0)); + points.push_back(Point(4.0, 6.0)); + points.push_back(Point(9.0, 6.0)); + points.push_back(Point(0.0, 14.0)); + points.push_back(Point(2.0, 19.0)); + points.push_back(Point(9.0, 17.0)); + // duplicated points + points.push_back(Point(1.0, 1.0)); + points.push_back(Point(7.0, 0.0)); + + // ---------------------------------------------------------------------------- + // Init of an alpha complex from the list of points + // ---------------------------------------------------------------------------- + std::cout << "Init" << std::endl; + Gudhi::alpha_complex::Alpha_complex<TestedKernel> alpha_complex_from_points(points); + + Gudhi::Simplex_tree<> simplex_tree; + std::cout << "create_complex" << std::endl; + BOOST_CHECK(alpha_complex_from_points.create_complex(simplex_tree)); + + std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices() + << std::endl; + BOOST_CHECK(simplex_tree.num_vertices() < points.size()); } diff --git a/src/Bottleneck_distance/test/bottleneck_unit_test.cpp b/src/Bottleneck_distance/test/bottleneck_unit_test.cpp index 3fc6fc7b..2c520045 100644 --- a/src/Bottleneck_distance/test/bottleneck_unit_test.cpp +++ b/src/Bottleneck_distance/test/bottleneck_unit_test.cpp @@ -15,6 +15,7 @@ #include <random> #include <gudhi/Bottleneck.h> +#include <gudhi/Unitary_tests_utils.h> using namespace Gudhi::persistence_diagram; @@ -59,24 +60,24 @@ BOOST_AUTO_TEST_CASE(persistence_graph) { BOOST_CHECK(g.size() == (n1 + n2)); // BOOST_CHECK((int) d.size() == (n1 + n2)*(n1 + n2) + n1 + n2 + 1); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, 0)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, n1 - 1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, n1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, n2 - 1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, n2)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, (n1 + n2) - 1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, 0)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, n1 - 1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, n1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, n2 - 1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, n2)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, (n1 + n2) - 1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, 0)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, n1 - 1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, n1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, n2 - 1)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, n2)) > 0); - BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, (n1 + n2) - 1)) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, 0))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, n1 - 1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, n1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, n2 - 1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, n2))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, (n1 + n2) - 1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, 0))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, n1 - 1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, n1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, n2 - 1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, n2))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, (n1 + n2) - 1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, 0))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, n1 - 1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, n1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, n2 - 1))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, n2))) > 0); + BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, (n1 + n2) - 1))) > 0); } BOOST_AUTO_TEST_CASE(neighbors_finder) { diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals.h b/src/Persistence_representations/include/gudhi/Persistence_intervals.h index e2db4572..ea4220ea 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals.h @@ -6,6 +6,8 @@ * * Modification(s): * - YYYY/MM Author: Description of the modification + * - 2019/12 Vincent Rouvreau: Fix #118 - Make histogram_of_lengths and cumulative_histogram_of_lengths + * return the exact number_of_bins (was failing on x86) */ #ifndef PERSISTENCE_INTERVALS_H_ @@ -335,6 +337,9 @@ std::vector<size_t> Persistence_intervals::histogram_of_lengths(size_t number_of getchar(); } } + // we want number of bins equals to number_of_bins (some unexpected results on x86) + result[number_of_bins-1]+=result[number_of_bins]; + result.resize(number_of_bins); if (dbg) { for (size_t i = 0; i != result.size(); ++i) std::cerr << result[i] << std::endl; diff --git a/src/Persistence_representations/test/persistence_intervals_test.cpp b/src/Persistence_representations/test/persistence_intervals_test.cpp index 3b7a2049..02ea8edb 100644 --- a/src/Persistence_representations/test/persistence_intervals_test.cpp +++ b/src/Persistence_representations/test/persistence_intervals_test.cpp @@ -6,6 +6,8 @@ * * Modification(s): * - YYYY/MM Author: Description of the modification + * - 2019/12 Vincent Rouvreau: Fix #118 - Make histogram_of_lengths and cumulative_histogram_of_lengths + * return the exact number_of_bins (was failing on x86) */ #define BOOST_TEST_DYN_LINK @@ -32,17 +34,8 @@ BOOST_AUTO_TEST_CASE(check_min_max_function) { BOOST_AUTO_TEST_CASE(check_length_of_dominant_intervals) { Persistence_intervals p("data/file_with_diagram"); std::vector<double> dominant_ten_intervals_length = p.length_of_dominant_intervals(10); - std::vector<double> dominant_intervals_length; - dominant_intervals_length.push_back(0.862625); - dominant_intervals_length.push_back(0.800893); - dominant_intervals_length.push_back(0.762061); - dominant_intervals_length.push_back(0.756501); - dominant_intervals_length.push_back(0.729367); - dominant_intervals_length.push_back(0.718177); - dominant_intervals_length.push_back(0.708395); - dominant_intervals_length.push_back(0.702844); - dominant_intervals_length.push_back(0.700468); - dominant_intervals_length.push_back(0.622177); + std::vector<double> dominant_intervals_length{0.862625, 0.800893, 0.762061, 0.756501, 0.729367, + 0.718177, 0.708395, 0.702844, 0.700468, 0.622177}; for (size_t i = 0; i != dominant_ten_intervals_length.size(); ++i) { GUDHI_TEST_FLOAT_EQUALITY_CHECK(dominant_ten_intervals_length[i], dominant_intervals_length[i], Gudhi::Persistence_representations::epsi); @@ -52,17 +45,11 @@ BOOST_AUTO_TEST_CASE(check_dominant_intervals) { Persistence_intervals p("data/file_with_diagram"); std::vector<std::pair<double, double> > ten_dominant_intervals = p.dominant_intervals(10); - std::vector<std::pair<double, double> > templ; - templ.push_back(std::pair<double, double>(0.114718, 0.977343)); - templ.push_back(std::pair<double, double>(0.133638, 0.93453)); - templ.push_back(std::pair<double, double>(0.104599, 0.866659)); - templ.push_back(std::pair<double, double>(0.149798, 0.906299)); - templ.push_back(std::pair<double, double>(0.247352, 0.976719)); - templ.push_back(std::pair<double, double>(0.192675, 0.910852)); - templ.push_back(std::pair<double, double>(0.191836, 0.900231)); - templ.push_back(std::pair<double, double>(0.284998, 0.987842)); - templ.push_back(std::pair<double, double>(0.294069, 0.994537)); - templ.push_back(std::pair<double, double>(0.267421, 0.889597)); + std::vector<std::pair<double, double> > templ{ {0.114718, 0.977343}, {0.133638, 0.93453}, + {0.104599, 0.866659}, {0.149798, 0.906299}, + {0.247352, 0.976719}, {0.192675, 0.910852}, + {0.191836, 0.900231}, {0.284998, 0.987842}, + {0.294069, 0.994537}, {0.267421, 0.889597} }; for (size_t i = 0; i != ten_dominant_intervals.size(); ++i) { GUDHI_TEST_FLOAT_EQUALITY_CHECK(ten_dominant_intervals[i].first, templ[i].first, @@ -75,18 +62,7 @@ BOOST_AUTO_TEST_CASE(check_dominant_intervals) { BOOST_AUTO_TEST_CASE(check_histogram_of_lengths) { Persistence_intervals p("data/file_with_diagram"); std::vector<size_t> histogram = p.histogram_of_lengths(10); - std::vector<size_t> template_histogram; - template_histogram.push_back(10); - template_histogram.push_back(5); - template_histogram.push_back(3); - template_histogram.push_back(4); - template_histogram.push_back(4); - template_histogram.push_back(3); - template_histogram.push_back(6); - template_histogram.push_back(1); - template_histogram.push_back(7); - template_histogram.push_back(1); - template_histogram.push_back(1); + std::vector<size_t> template_histogram{10, 5, 3, 4, 4, 3, 6, 1, 7, 2}; for (size_t i = 0; i != histogram.size(); ++i) { BOOST_CHECK(histogram[i] == template_histogram[i]); } @@ -95,18 +71,7 @@ BOOST_AUTO_TEST_CASE(check_histogram_of_lengths) { BOOST_AUTO_TEST_CASE(check_cumulative_histograms_of_lengths) { Persistence_intervals p("data/file_with_diagram"); std::vector<size_t> cumulative_histogram = p.cumulative_histogram_of_lengths(10); - std::vector<size_t> template_cumulative_histogram; - template_cumulative_histogram.push_back(10); - template_cumulative_histogram.push_back(15); - template_cumulative_histogram.push_back(18); - template_cumulative_histogram.push_back(22); - template_cumulative_histogram.push_back(26); - template_cumulative_histogram.push_back(29); - template_cumulative_histogram.push_back(35); - template_cumulative_histogram.push_back(36); - template_cumulative_histogram.push_back(43); - template_cumulative_histogram.push_back(44); - template_cumulative_histogram.push_back(45); + std::vector<size_t> template_cumulative_histogram{10, 15, 18, 22, 26, 29, 35, 36, 43, 45}; for (size_t i = 0; i != cumulative_histogram.size(); ++i) { BOOST_CHECK(cumulative_histogram[i] == template_cumulative_histogram[i]); @@ -116,17 +81,8 @@ BOOST_AUTO_TEST_CASE(check_characteristic_function_of_diagram) { Persistence_intervals p("data/file_with_diagram"); std::pair<double, double> min_max_ = p.get_x_range(); std::vector<double> char_funct_diag = p.characteristic_function_of_diagram(min_max_.first, min_max_.second); - std::vector<double> template_char_funct_diag; - template_char_funct_diag.push_back(0.370665); - template_char_funct_diag.push_back(0.84058); - template_char_funct_diag.push_back(1.24649); - template_char_funct_diag.push_back(1.3664); - template_char_funct_diag.push_back(1.34032); - template_char_funct_diag.push_back(1.31904); - template_char_funct_diag.push_back(1.14076); - template_char_funct_diag.push_back(0.991259); - template_char_funct_diag.push_back(0.800714); - template_char_funct_diag.push_back(0.0676303); + std::vector<double> template_char_funct_diag{0.370665, 0.84058, 1.24649, 1.3664, 1.34032, + 1.31904, 1.14076, 0.991259, 0.800714, 0.0676303}; for (size_t i = 0; i != char_funct_diag.size(); ++i) { GUDHI_TEST_FLOAT_EQUALITY_CHECK(char_funct_diag[i], template_char_funct_diag[i], @@ -139,18 +95,8 @@ BOOST_AUTO_TEST_CASE(check_cumulative_characteristic_function_of_diagram) { std::pair<double, double> min_max_ = p.get_x_range(); std::vector<double> cumul_char_funct_diag = p.cumulative_characteristic_function_of_diagram(min_max_.first, min_max_.second); - std::vector<double> template_char_funct_diag_cumul; - - template_char_funct_diag_cumul.push_back(0.370665); - template_char_funct_diag_cumul.push_back(1.21125); - template_char_funct_diag_cumul.push_back(2.45774); - template_char_funct_diag_cumul.push_back(3.82414); - template_char_funct_diag_cumul.push_back(5.16446); - template_char_funct_diag_cumul.push_back(6.4835); - template_char_funct_diag_cumul.push_back(7.62426); - template_char_funct_diag_cumul.push_back(8.61552); - template_char_funct_diag_cumul.push_back(9.41623); - template_char_funct_diag_cumul.push_back(9.48386); + std::vector<double> template_char_funct_diag_cumul{0.370665, 1.21125, 2.45774, 3.82414, 5.16446, + 6.4835, 7.62426, 8.61552, 9.41623, 9.48386}; for (size_t i = 0; i != cumul_char_funct_diag.size(); ++i) { GUDHI_TEST_FLOAT_EQUALITY_CHECK(cumul_char_funct_diag[i], template_char_funct_diag_cumul[i], @@ -160,97 +106,29 @@ BOOST_AUTO_TEST_CASE(check_cumulative_characteristic_function_of_diagram) { BOOST_AUTO_TEST_CASE(check_compute_persistent_betti_numbers) { Persistence_intervals p("data/file_with_diagram"); - std::vector<std::pair<double, size_t> > pbns; - pbns.push_back(std::pair<double, size_t>(0.0290362, 1)); - pbns.push_back(std::pair<double, size_t>(0.0307676, 2)); - pbns.push_back(std::pair<double, size_t>(0.0366312, 3)); - pbns.push_back(std::pair<double, size_t>(0.0544614, 4)); - pbns.push_back(std::pair<double, size_t>(0.0920033, 5)); - pbns.push_back(std::pair<double, size_t>(0.104599, 6)); - pbns.push_back(std::pair<double, size_t>(0.114718, 7)); - pbns.push_back(std::pair<double, size_t>(0.117379, 8)); - pbns.push_back(std::pair<double, size_t>(0.123493, 9)); - pbns.push_back(std::pair<double, size_t>(0.133638, 10)); - pbns.push_back(std::pair<double, size_t>(0.137798, 9)); - pbns.push_back(std::pair<double, size_t>(0.149798, 10)); - pbns.push_back(std::pair<double, size_t>(0.155421, 11)); - pbns.push_back(std::pair<double, size_t>(0.158443, 12)); - pbns.push_back(std::pair<double, size_t>(0.176956, 13)); - pbns.push_back(std::pair<double, size_t>(0.183234, 12)); - pbns.push_back(std::pair<double, size_t>(0.191069, 13)); - pbns.push_back(std::pair<double, size_t>(0.191333, 14)); - pbns.push_back(std::pair<double, size_t>(0.191836, 15)); - pbns.push_back(std::pair<double, size_t>(0.192675, 16)); - pbns.push_back(std::pair<double, size_t>(0.208564, 17)); - pbns.push_back(std::pair<double, size_t>(0.218425, 18)); - pbns.push_back(std::pair<double, size_t>(0.219902, 17)); - pbns.push_back(std::pair<double, size_t>(0.23233, 16)); - pbns.push_back(std::pair<double, size_t>(0.234558, 17)); - pbns.push_back(std::pair<double, size_t>(0.237166, 16)); - pbns.push_back(std::pair<double, size_t>(0.247352, 17)); - pbns.push_back(std::pair<double, size_t>(0.267421, 18)); - pbns.push_back(std::pair<double, size_t>(0.268093, 19)); - pbns.push_back(std::pair<double, size_t>(0.278734, 18)); - pbns.push_back(std::pair<double, size_t>(0.284722, 19)); - pbns.push_back(std::pair<double, size_t>(0.284998, 20)); - pbns.push_back(std::pair<double, size_t>(0.294069, 21)); - pbns.push_back(std::pair<double, size_t>(0.306293, 22)); - pbns.push_back(std::pair<double, size_t>(0.322361, 21)); - pbns.push_back(std::pair<double, size_t>(0.323152, 22)); - pbns.push_back(std::pair<double, size_t>(0.371021, 23)); - pbns.push_back(std::pair<double, size_t>(0.372395, 24)); - pbns.push_back(std::pair<double, size_t>(0.387744, 25)); - pbns.push_back(std::pair<double, size_t>(0.435537, 26)); - pbns.push_back(std::pair<double, size_t>(0.462911, 25)); - pbns.push_back(std::pair<double, size_t>(0.483569, 26)); - pbns.push_back(std::pair<double, size_t>(0.489209, 25)); - pbns.push_back(std::pair<double, size_t>(0.517115, 24)); - pbns.push_back(std::pair<double, size_t>(0.522197, 23)); - pbns.push_back(std::pair<double, size_t>(0.532665, 22)); - pbns.push_back(std::pair<double, size_t>(0.545262, 23)); - pbns.push_back(std::pair<double, size_t>(0.587227, 22)); - pbns.push_back(std::pair<double, size_t>(0.593036, 23)); - pbns.push_back(std::pair<double, size_t>(0.602647, 24)); - pbns.push_back(std::pair<double, size_t>(0.605044, 25)); - pbns.push_back(std::pair<double, size_t>(0.621962, 24)); - pbns.push_back(std::pair<double, size_t>(0.629449, 23)); - pbns.push_back(std::pair<double, size_t>(0.636719, 22)); - pbns.push_back(std::pair<double, size_t>(0.64957, 21)); - pbns.push_back(std::pair<double, size_t>(0.650781, 22)); - pbns.push_back(std::pair<double, size_t>(0.654951, 23)); - pbns.push_back(std::pair<double, size_t>(0.683489, 24)); - pbns.push_back(std::pair<double, size_t>(0.687172, 23)); - pbns.push_back(std::pair<double, size_t>(0.69703, 22)); - pbns.push_back(std::pair<double, size_t>(0.701174, 21)); - pbns.push_back(std::pair<double, size_t>(0.717623, 22)); - pbns.push_back(std::pair<double, size_t>(0.722023, 21)); - pbns.push_back(std::pair<double, size_t>(0.722298, 20)); - pbns.push_back(std::pair<double, size_t>(0.725347, 19)); - pbns.push_back(std::pair<double, size_t>(0.73071, 18)); - pbns.push_back(std::pair<double, size_t>(0.758355, 17)); - pbns.push_back(std::pair<double, size_t>(0.770913, 18)); - pbns.push_back(std::pair<double, size_t>(0.790833, 17)); - pbns.push_back(std::pair<double, size_t>(0.821211, 16)); - pbns.push_back(std::pair<double, size_t>(0.849305, 17)); - pbns.push_back(std::pair<double, size_t>(0.853669, 16)); - pbns.push_back(std::pair<double, size_t>(0.866659, 15)); - pbns.push_back(std::pair<double, size_t>(0.872896, 16)); - pbns.push_back(std::pair<double, size_t>(0.889597, 15)); - pbns.push_back(std::pair<double, size_t>(0.900231, 14)); - pbns.push_back(std::pair<double, size_t>(0.903847, 13)); - pbns.push_back(std::pair<double, size_t>(0.906299, 12)); - pbns.push_back(std::pair<double, size_t>(0.910852, 11)); - pbns.push_back(std::pair<double, size_t>(0.93453, 10)); - pbns.push_back(std::pair<double, size_t>(0.944757, 9)); - pbns.push_back(std::pair<double, size_t>(0.947812, 8)); - pbns.push_back(std::pair<double, size_t>(0.959154, 7)); - pbns.push_back(std::pair<double, size_t>(0.975654, 6)); - pbns.push_back(std::pair<double, size_t>(0.976719, 5)); - pbns.push_back(std::pair<double, size_t>(0.977343, 4)); - pbns.push_back(std::pair<double, size_t>(0.980129, 3)); - pbns.push_back(std::pair<double, size_t>(0.987842, 2)); - pbns.push_back(std::pair<double, size_t>(0.990127, 1)); - pbns.push_back(std::pair<double, size_t>(0.994537, 0)); + std::vector<std::pair<double, size_t> > pbns{ {0.0290362, 1}, {0.0307676, 2}, {0.0366312, 3}, {0.0544614, 4}, + {0.0920033, 5}, {0.104599, 6}, {0.114718, 7}, {0.117379, 8}, + {0.123493, 9}, {0.133638, 10}, {0.137798, 9}, {0.149798, 10}, + {0.155421, 11}, {0.158443, 12}, {0.176956, 13}, {0.183234, 12}, + {0.191069, 13}, {0.191333, 14}, {0.191836, 15}, {0.192675, 16}, + {0.208564, 17}, {0.218425, 18}, {0.219902, 17}, {0.23233, 16}, + {0.234558, 17}, {0.237166, 16}, {0.247352, 17}, {0.267421, 18}, + {0.268093, 19}, {0.278734, 18}, {0.284722, 19}, {0.284998, 20}, + {0.294069, 21}, {0.306293, 22}, {0.322361, 21}, {0.323152, 22}, + {0.371021, 23}, {0.372395, 24}, {0.387744, 25}, {0.435537, 26}, + {0.462911, 25}, {0.483569, 26}, {0.489209, 25}, {0.517115, 24}, + {0.522197, 23}, {0.532665, 22}, {0.545262, 23}, {0.587227, 22}, + {0.593036, 23}, {0.602647, 24}, {0.605044, 25}, {0.621962, 24}, + {0.629449, 23}, {0.636719, 22}, {0.64957, 21}, {0.650781, 22}, + {0.654951, 23}, {0.683489, 24}, {0.687172, 23}, {0.69703, 22}, + {0.701174, 21}, {0.717623, 22}, {0.722023, 21}, {0.722298, 20}, + {0.725347, 19}, {0.73071, 18}, {0.758355, 17}, {0.770913, 18}, + {0.790833, 17}, {0.821211, 16}, {0.849305, 17}, {0.853669, 16}, + {0.866659, 15}, {0.872896, 16}, {0.889597, 15}, {0.900231, 14}, + {0.903847, 13}, {0.906299, 12}, {0.910852, 11}, {0.93453, 10}, + {0.944757, 9}, {0.947812, 8}, {0.959154, 7}, {0.975654, 6}, + {0.976719, 5}, {0.977343, 4}, {0.980129, 3}, {0.987842, 2}, + {0.990127, 1}, {0.994537, 0} }; std::vector<std::pair<double, size_t> > pbns_new = p.compute_persistent_betti_numbers(); for (size_t i = 0; i != pbns.size(); ++i) { @@ -262,17 +140,8 @@ BOOST_AUTO_TEST_CASE(check_compute_persistent_betti_numbers) { BOOST_AUTO_TEST_CASE(check_k_n_n) { Persistence_intervals p("data/file_with_diagram"); std::vector<double> knn = p.k_n_n(5); - std::vector<double> knn_template; - knn_template.push_back(1.04208); - knn_template.push_back(1.00344); - knn_template.push_back(0.979395); - knn_template.push_back(0.890643); - knn_template.push_back(0.874769); - knn_template.push_back(0.845787); - knn_template.push_back(0.819713); - knn_template.push_back(0.803984); - knn_template.push_back(0.799864); - knn_template.push_back(0.786945); + std::vector<double> knn_template{1.04208, 1.00344, 0.979395, 0.890643, 0.874769, + 0.845787, 0.819713, 0.803984, 0.799864, 0.786945}; for (size_t i = 0; i != knn.size(); ++i) { GUDHI_TEST_FLOAT_EQUALITY_CHECK(knn[i], knn_template[i], Gudhi::Persistence_representations::epsi); diff --git a/src/common/include/gudhi/Unitary_tests_utils.h b/src/common/include/gudhi/Unitary_tests_utils.h index 7d039304..9b86460a 100644 --- a/src/common/include/gudhi/Unitary_tests_utils.h +++ b/src/common/include/gudhi/Unitary_tests_utils.h @@ -26,4 +26,15 @@ void GUDHI_TEST_FLOAT_EQUALITY_CHECK(FloatingType a, FloatingType b, BOOST_CHECK(std::fabs(a - b) <= epsilon); } +// That's the usual x86 issue where a+b==a+b can return false (without any NaN) because one of them was stored in +// memory (and thus rounded to 64 bits) while the other is still in a register (80 bits). +template<typename FloatingType > +FloatingType GUDHI_PROTECT_FLOAT(FloatingType value) { + volatile FloatingType protected_value = value; +#ifdef DEBUG_TRACES + std::cout << "GUDHI_PROTECT_FLOAT - " << protected_value << std::endl; +#endif + return protected_value; +} + #endif // UNITARY_TESTS_UTILS_H_ diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 9af85eac..b558d4c4 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -114,9 +114,9 @@ if(PYTHONINTERP_FOUND) set(GUDHI_PYTHON_MODULES_TO_COMPILE "${GUDHI_PYTHON_MODULES_TO_COMPILE}'nerve_gic', ") endif () if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) + set(GUDHI_PYTHON_MODULES_TO_COMPILE "${GUDHI_PYTHON_MODULES_TO_COMPILE}'alpha_complex', ") set(GUDHI_PYTHON_MODULES_TO_COMPILE "${GUDHI_PYTHON_MODULES_TO_COMPILE}'subsampling', ") set(GUDHI_PYTHON_MODULES_TO_COMPILE "${GUDHI_PYTHON_MODULES_TO_COMPILE}'tangential_complex', ") - set(GUDHI_PYTHON_MODULES_TO_COMPILE "${GUDHI_PYTHON_MODULES_TO_COMPILE}'alpha_complex', ") set(GUDHI_PYTHON_MODULES_TO_COMPILE "${GUDHI_PYTHON_MODULES_TO_COMPILE}'euclidean_witness_complex', ") set(GUDHI_PYTHON_MODULES_TO_COMPILE "${GUDHI_PYTHON_MODULES_TO_COMPILE}'euclidean_strong_witness_complex', ") endif () @@ -162,10 +162,21 @@ if(PYTHONINTERP_FOUND) set(GUDHI_PYTHON_EXTRA_COMPILE_ARGS "${GUDHI_PYTHON_EXTRA_COMPILE_ARGS}'-DCGAL_USE_GMPXX', ") add_GUDHI_PYTHON_lib("${GMPXX_LIBRARIES}") set(GUDHI_PYTHON_LIBRARY_DIRS "${GUDHI_PYTHON_LIBRARY_DIRS}'${GMPXX_LIBRARIES_DIR}', ") - message("** Add gmpxx ${GMPXX_LIBRARIES_DIR}") + message("** Add gmpxx ${GMPXX_LIBRARIES_DIR}") endif(GMPXX_FOUND) endif(GMP_FOUND) - endif(CGAL_FOUND) + if(MPFR_FOUND) + add_gudhi_debug_info("MPFR_LIBRARIES = ${MPFR_LIBRARIES}") + set(GUDHI_PYTHON_EXTRA_COMPILE_ARGS "${GUDHI_PYTHON_EXTRA_COMPILE_ARGS}'-DCGAL_USE_MPFR', ") + add_GUDHI_PYTHON_lib("${MPFR_LIBRARIES}") + # In case CGAL is not header only, all MPFR variables are set except MPFR_LIBRARIES_DIR - Just set it + if(NOT MPFR_LIBRARIES_DIR) + get_filename_component(MPFR_LIBRARIES_DIR ${MPFR_LIBRARIES} PATH) + endif(NOT MPFR_LIBRARIES_DIR) + set(GUDHI_PYTHON_LIBRARY_DIRS "${GUDHI_PYTHON_LIBRARY_DIRS}'${MPFR_LIBRARIES_DIR}', ") + message("** Add mpfr ${MPFR_LIBRARIES}") + endif(MPFR_FOUND) +endif(CGAL_FOUND) # Specific for Mac if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") @@ -229,7 +240,6 @@ if(PYTHONINTERP_FOUND) COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_rips_persistence_bottleneck_distance.py" -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -t 0.15 -d 3) - if(MATPLOTLIB_FOUND AND NUMPY_FOUND) # Tangential add_test(NAME tangential_complex_plain_homology_from_off_file_example_py_test @@ -305,7 +315,6 @@ if(PYTHONINTERP_FOUND) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_complex_from_points_example.py") - if(MATPLOTLIB_FOUND AND NUMPY_FOUND) add_test(NAME alpha_complex_diagram_persistence_from_off_file_example_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} @@ -313,9 +322,7 @@ if(PYTHONINTERP_FOUND) ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_complex_diagram_persistence_from_off_file_example.py" --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 0.6) endif() - add_gudhi_py_test(test_alpha_complex) - endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) diff --git a/src/python/gudhi/alpha_complex.pyx b/src/python/gudhi/alpha_complex.pyx index 8f2c98d5..24e36bea 100644 --- a/src/python/gudhi/alpha_complex.pyx +++ b/src/python/gudhi/alpha_complex.pyx @@ -66,7 +66,7 @@ cdef class AlphaComplex: """ # The real cython constructor - def __cinit__(self, points=None, off_file=''): + def __cinit__(self, points = None, off_file = ''): if off_file: if os.path.isfile(off_file): self.thisptr = new Alpha_complex_interface(str.encode(off_file), True) @@ -99,7 +99,7 @@ cdef class AlphaComplex: cdef vector[double] point = self.thisptr.get_point(vertex) return point - def create_simplex_tree(self, max_alpha_square=float('inf')): + def create_simplex_tree(self, max_alpha_square = float('inf')): """ :param max_alpha_square: The maximum alpha square threshold the simplices shall not exceed. Default is set to infinity, and diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h index 96353cc4..e9bbadb0 100644 --- a/src/python/include/Alpha_complex_interface.h +++ b/src/python/include/Alpha_complex_interface.h @@ -13,6 +13,7 @@ #include <gudhi/Simplex_tree.h> #include <gudhi/Alpha_complex.h> +#include <CGAL/Epeck_d.h> #include <CGAL/Epick_d.h> #include <boost/range/adaptor/transformed.hpp> @@ -28,7 +29,7 @@ namespace Gudhi { namespace alpha_complex { class Alpha_complex_interface { - using Dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; + using Dynamic_kernel = CGAL::Epeck_d< CGAL::Dynamic_dimension_tag >; using Point_d = Dynamic_kernel::Point_d; public: @@ -51,7 +52,7 @@ class Alpha_complex_interface { std::vector<double> vd; try { Point_d const& ph = alpha_complex_->get_point(vh); - for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++) + for (auto coord = ph.cartesian_begin(); coord != ph.cartesian_end(); coord++) vd.push_back(CGAL::to_double(*coord)); } catch (std::out_of_range const&) { // std::out_of_range is thrown in case not found. Other exceptions must be re-thrown diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py index 24f8bf53..9b27fff2 100755 --- a/src/python/test/test_alpha_complex.py +++ b/src/python/test/test_alpha_complex.py @@ -1,4 +1,8 @@ from gudhi import AlphaComplex, SimplexTree +import math +import numpy as np +import itertools +import pytest """ 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. @@ -88,3 +92,28 @@ def test_filtered_alpha(): ] assert simplex_tree.get_star([0]) == [([0], 0.0), ([0, 1], 0.25), ([0, 2], 0.25)] assert simplex_tree.get_cofaces([0], 1) == [([0, 1], 0.25), ([0, 2], 0.25)] + +def test_safe_alpha_persistence_comparison(): + #generate periodic signal + time = np.arange(0, 10, 1) + signal = [math.sin(x) for x in time] + delta = math.pi + delayed = [math.sin(x + delta) for x in time] + + #construct embedding + embedding1 = [[signal[i], -signal[i]] for i in range(len(time))] + embedding2 = [[signal[i], delayed[i]] for i in range(len(time))] + + #build alpha complex and simplex tree + alpha_complex1 = AlphaComplex(points=embedding1) + simplex_tree1 = alpha_complex1.create_simplex_tree() + + alpha_complex2 = AlphaComplex(points=embedding2) + simplex_tree2 = alpha_complex2.create_simplex_tree() + + diag1 = simplex_tree1.persistence() + diag2 = simplex_tree2.persistence() + + for (first_p, second_p) in itertools.zip_longest(diag1, diag2): + assert first_p[0] == pytest.approx(second_p[0]) + assert first_p[1] == pytest.approx(second_p[1]) |