From 0b61062f68f5dde2e56e50f266a3f364ac39e86f Mon Sep 17 00:00:00 2001 From: Hind-M Date: Thu, 30 Jun 2022 09:59:23 +0200 Subject: Assign to sh same key as face in cech --- src/Cech_complex/include/gudhi/Cech_complex_blocker.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index 1bb205b3..68a9f726 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -54,6 +54,7 @@ class Cech_blocker { using Simplex_handle = typename SimplicialComplexForCech::Simplex_handle; using Filtration_value = typename SimplicialComplexForCech::Filtration_value; + using Simplex_key = typename SimplicialComplexForCech::Simplex_key; template Sphere get_sphere(PointIterator begin, PointIterator end) const { @@ -78,8 +79,10 @@ class Cech_blocker { for (auto face_opposite_vertex : sc_ptr_->boundary_opposite_vertex_simplex_range(sh)) { Sphere sph; auto k = sc_ptr_->key(face_opposite_vertex.first); + Simplex_key sph_key; if(k != sc_ptr_->null_key()) { sph = cc_ptr_->get_cache().at(k); + sph_key = k; } else { Point_cloud face_points; @@ -92,6 +95,7 @@ class Cech_blocker { sph = get_sphere(face_points.cbegin(), face_points.cend()); // Put edge sphere in cache sc_ptr_->assign_key(face_opposite_vertex.first, cc_ptr_->get_cache().size()); + sph_key = cc_ptr_->get_cache().size(); cc_ptr_->get_cache().push_back(sph); // Clear face_points face_points.clear(); @@ -106,8 +110,7 @@ class Cech_blocker { if(exact_) CGAL::exact(sph.second); #endif radius = std::sqrt(cast_to_fv(sph.second)); - sc_ptr_->assign_key(sh, cc_ptr_->get_cache().size()); - cc_ptr_->get_cache().push_back(sph); + sc_ptr_->assign_key(sh, sph_key); break; } } -- cgit v1.2.3 From e854e1b2292de95ecdec021559926a1fba14659d Mon Sep 17 00:00:00 2001 From: Hind-M Date: Tue, 5 Jul 2022 17:23:06 +0200 Subject: No need for a sph copy anymore --- src/Cech_complex/include/gudhi/Cech_complex_blocker.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index 68a9f726..47b6c5e3 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -77,11 +77,9 @@ class Cech_blocker { // for each face of simplex sh, test outsider point is indeed inside enclosing ball, if yes, take it and exit loop, otherwise, new sphere is circumsphere of all vertices for (auto face_opposite_vertex : sc_ptr_->boundary_opposite_vertex_simplex_range(sh)) { - Sphere sph; auto k = sc_ptr_->key(face_opposite_vertex.first); Simplex_key sph_key; if(k != sc_ptr_->null_key()) { - sph = cc_ptr_->get_cache().at(k); sph_key = k; } else { @@ -92,24 +90,23 @@ class Cech_blocker { std::clog << "#(" << vertex << ")#"; #endif // DEBUG_TRACES } - sph = get_sphere(face_points.cbegin(), face_points.cend()); // Put edge sphere in cache sc_ptr_->assign_key(face_opposite_vertex.first, cc_ptr_->get_cache().size()); sph_key = cc_ptr_->get_cache().size(); - cc_ptr_->get_cache().push_back(sph); + cc_ptr_->get_cache().push_back(get_sphere(face_points.cbegin(), face_points.cend())); // Clear face_points face_points.clear(); } // Check if the minimal enclosing ball of current face contains the extra point/opposite vertex - if (kernel_.squared_distance_d_object()(sph.first, cc_ptr_->get_point(face_opposite_vertex.second)) <= sph.second) { + if (kernel_.squared_distance_d_object()(cc_ptr_->get_cache()[sph_key].first, cc_ptr_->get_point(face_opposite_vertex.second)) <= cc_ptr_->get_cache()[sph_key].second) { #ifdef DEBUG_TRACES - std::clog << "center: " << sph.first << ", radius: " << radius << std::endl; + std::clog << "center: " << cc_ptr_->get_cache()[sph_key].first << ", radius: " << radius << std::endl; #endif // DEBUG_TRACES is_min_enclos_ball = true; #if CGAL_VERSION_NR >= 1050000000 - if(exact_) CGAL::exact(sph.second); + if(exact_) CGAL::exact(cc_ptr_->get_cache()[sph_key].second); #endif - radius = std::sqrt(cast_to_fv(sph.second)); + radius = std::sqrt(cast_to_fv(cc_ptr_->get_cache()[sph_key].second)); sc_ptr_->assign_key(sh, sph_key); break; } -- cgit v1.2.3 From 7b4772c00c834bcc6693b48ce0b8431461ba8a53 Mon Sep 17 00:00:00 2001 From: Hind-M Date: Wed, 6 Jul 2022 10:55:54 +0200 Subject: Use reference to sph for a better readability --- src/Cech_complex/include/gudhi/Cech_complex_blocker.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index 543f677e..c6f02857 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -99,15 +99,16 @@ class Cech_blocker { points.clear(); } // Check if the minimal enclosing ball of current face contains the extra point/opposite vertex - if (kernel_.squared_distance_d_object()(cc_ptr_->get_cache()[sph_key].first, cc_ptr_->get_point(face_opposite_vertex.second)) <= cc_ptr_->get_cache()[sph_key].second) { + Sphere const& sph = cc_ptr_->get_cache()[sph_key]; + if (kernel_.squared_distance_d_object()(sph.first, cc_ptr_->get_point(face_opposite_vertex.second)) <= sph.second) { #ifdef DEBUG_TRACES - std::clog << "center: " << cc_ptr_->get_cache()[sph_key].first << ", radius: " << radius << std::endl; + std::clog << "center: " << sph.first << ", radius: " << radius << std::endl; #endif // DEBUG_TRACES is_min_enclos_ball = true; #if CGAL_VERSION_NR >= 1050000000 - if(exact_) CGAL::exact(cc_ptr_->get_cache()[sph_key].second); + if(exact_) CGAL::exact(sph.second); #endif - radius = std::sqrt(cast_to_fv(cc_ptr_->get_cache()[sph_key].second)); + radius = std::sqrt(cast_to_fv(sph.second)); sc_ptr_->assign_key(sh, sph_key); break; } -- cgit v1.2.3 From 51f599d16a43e2c8e831284c6320b73324873c17 Mon Sep 17 00:00:00 2001 From: Hind-M Date: Wed, 6 Jul 2022 11:24:29 +0200 Subject: Switch lines to use intermediate variable --- src/Cech_complex/include/gudhi/Cech_complex_blocker.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index c6f02857..fc92e8fa 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -92,8 +92,8 @@ class Cech_blocker { #endif // DEBUG_TRACES } // Put edge sphere in cache - sc_ptr_->assign_key(face_opposite_vertex.first, cc_ptr_->get_cache().size()); sph_key = cc_ptr_->get_cache().size(); + sc_ptr_->assign_key(face_opposite_vertex.first, sph_key); cc_ptr_->get_cache().push_back(get_sphere(points.cbegin(), points.cend())); // Clear face points points.clear(); -- cgit v1.2.3 From 2559b78a16cc0f7af9ea3b78d6b388c629b2a4ae Mon Sep 17 00:00:00 2001 From: Hind-M Date: Wed, 6 Jul 2022 15:34:46 +0200 Subject: Move clog of radius after its assignment --- src/Cech_complex/include/gudhi/Cech_complex_blocker.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index fc92e8fa..22b99c5c 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -101,15 +101,15 @@ class Cech_blocker { // Check if the minimal enclosing ball of current face contains the extra point/opposite vertex Sphere const& sph = cc_ptr_->get_cache()[sph_key]; if (kernel_.squared_distance_d_object()(sph.first, cc_ptr_->get_point(face_opposite_vertex.second)) <= sph.second) { -#ifdef DEBUG_TRACES - std::clog << "center: " << sph.first << ", radius: " << radius << std::endl; -#endif // DEBUG_TRACES is_min_enclos_ball = true; + sc_ptr_->assign_key(sh, sph_key); #if CGAL_VERSION_NR >= 1050000000 if(exact_) CGAL::exact(sph.second); #endif radius = std::sqrt(cast_to_fv(sph.second)); - sc_ptr_->assign_key(sh, sph_key); +#ifdef DEBUG_TRACES + std::clog << "center: " << sph.first << ", radius: " << radius << std::endl; +#endif // DEBUG_TRACES break; } } -- cgit v1.2.3 From eb0ab20bdbf624e6b20896fb2cca1af71af7d4a5 Mon Sep 17 00:00:00 2001 From: Hind-M Date: Wed, 27 Jul 2022 11:36:56 +0200 Subject: Enable keops dtm warnings --- src/python/doc/installation.rst | 2 +- src/python/test/test_dtm.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/python/doc/installation.rst b/src/python/doc/installation.rst index dd476054..4eefd415 100644 --- a/src/python/doc/installation.rst +++ b/src/python/doc/installation.rst @@ -175,7 +175,7 @@ A complete configuration would be : Scikit-learn version 1.0.1 POT version 0.8.0 HNSWlib found - PyKeOps version [pyKeOps]: 1.5 + PyKeOps version [pyKeOps]: 2.1 EagerPy version 0.30.0 TensorFlow version 2.7.0 Sphinx version 4.3.0 diff --git a/src/python/test/test_dtm.py b/src/python/test/test_dtm.py index e46d616c..21cff055 100755 --- a/src/python/test/test_dtm.py +++ b/src/python/test/test_dtm.py @@ -91,11 +91,12 @@ def test_density(): def test_dtm_overflow_warnings(): pts = numpy.array([[10., 100000000000000000000000000000.], [1000., 100000000000000000000000000.]]) - + impl_warn = ["keops", "hnsw"] with warnings.catch_warnings(record=True) as w: - # TODO Test "keops" implementation as well when next version of pykeops (current is 1.5) is released (should fix the problem (cf. issue #543)) - dtm = DistanceToMeasure(2, implementation="hnsw") - r = dtm.fit_transform(pts) - assert len(w) == 1 - assert issubclass(w[0].category, RuntimeWarning) - assert "Overflow" in str(w[0].message) + for impl in impl_warn: + dtm = DistanceToMeasure(2, implementation=impl) + r = dtm.fit_transform(pts) + assert len(w) == 2 + for i in range(len(w)): + assert issubclass(w[i].category, RuntimeWarning) + assert "Overflow" in str(w[i].message) -- cgit v1.2.3 From 2a4f60b822b15c34058220beffd311f46f11d3b3 Mon Sep 17 00:00:00 2001 From: Hind-M Date: Tue, 2 Aug 2022 12:04:08 +0200 Subject: Get filtration from face when it's the same as simplex --- src/Cech_complex/include/gudhi/Cech_complex_blocker.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index 22b99c5c..6f082494 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -106,7 +106,10 @@ class Cech_blocker { #if CGAL_VERSION_NR >= 1050000000 if(exact_) CGAL::exact(sph.second); #endif - radius = std::sqrt(cast_to_fv(sph.second)); + if(k != sc_ptr_->null_key()) + radius = sc_ptr_->filtration(face_opposite_vertex.first); + else + radius = std::sqrt(cast_to_fv(sph.second)); #ifdef DEBUG_TRACES std::clog << "center: " << sph.first << ", radius: " << radius << std::endl; #endif // DEBUG_TRACES -- cgit v1.2.3 From 1c5c80fb53075706ba74751468d748960fae9dd9 Mon Sep 17 00:00:00 2001 From: Hind-M Date: Tue, 2 Aug 2022 14:56:51 +0200 Subject: Pull out the for loop in test --- src/python/test/test_dtm.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/python/test/test_dtm.py b/src/python/test/test_dtm.py index 21cff055..b276f041 100755 --- a/src/python/test/test_dtm.py +++ b/src/python/test/test_dtm.py @@ -92,11 +92,10 @@ def test_density(): def test_dtm_overflow_warnings(): pts = numpy.array([[10., 100000000000000000000000000000.], [1000., 100000000000000000000000000.]]) impl_warn = ["keops", "hnsw"] - with warnings.catch_warnings(record=True) as w: - for impl in impl_warn: + for impl in impl_warn: + with warnings.catch_warnings(record=True) as w: dtm = DistanceToMeasure(2, implementation=impl) r = dtm.fit_transform(pts) - assert len(w) == 2 - for i in range(len(w)): - assert issubclass(w[i].category, RuntimeWarning) - assert "Overflow" in str(w[i].message) + assert len(w) == 1 + assert issubclass(w[0].category, RuntimeWarning) + assert "Overflow" in str(w[0].message) -- cgit v1.2.3 From 6b28e9daa5480dadd0fa3a75d610f98e0c8a0ff5 Mon Sep 17 00:00:00 2001 From: Hind-M Date: Tue, 2 Aug 2022 18:28:07 +0200 Subject: Get filtration from face regardless of key value --- src/Cech_complex/include/gudhi/Cech_complex_blocker.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index 6f082494..18516e70 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -71,7 +71,6 @@ class Cech_blocker { * \return true if the simplex radius is greater than the Cech_complex max_radius*/ bool operator()(Simplex_handle sh) { using Point_cloud = std::vector; - CGAL::NT_converter cast_to_fv; Filtration_value radius = 0; bool is_min_enclos_ball = false; Point_cloud points; @@ -106,10 +105,7 @@ class Cech_blocker { #if CGAL_VERSION_NR >= 1050000000 if(exact_) CGAL::exact(sph.second); #endif - if(k != sc_ptr_->null_key()) - radius = sc_ptr_->filtration(face_opposite_vertex.first); - else - radius = std::sqrt(cast_to_fv(sph.second)); + radius = sc_ptr_->filtration(face_opposite_vertex.first); #ifdef DEBUG_TRACES std::clog << "center: " << sph.first << ", radius: " << radius << std::endl; #endif // DEBUG_TRACES @@ -125,6 +121,7 @@ class Cech_blocker { #if CGAL_VERSION_NR >= 1050000000 if(exact_) CGAL::exact(sph.second); #endif + CGAL::NT_converter cast_to_fv; radius = std::sqrt(cast_to_fv(sph.second)); sc_ptr_->assign_key(sh, cc_ptr_->get_cache().size()); -- cgit v1.2.3 From ac8e64471466b19aae3e525a6e6b384adf654f28 Mon Sep 17 00:00:00 2001 From: Hind-M Date: Wed, 3 Aug 2022 15:31:18 +0200 Subject: Remove useless exact option when getting filtration from face --- src/Cech_complex/include/gudhi/Cech_complex_blocker.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index 18516e70..7dcbe9b4 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -102,9 +102,6 @@ class Cech_blocker { if (kernel_.squared_distance_d_object()(sph.first, cc_ptr_->get_point(face_opposite_vertex.second)) <= sph.second) { is_min_enclos_ball = true; sc_ptr_->assign_key(sh, sph_key); -#if CGAL_VERSION_NR >= 1050000000 - if(exact_) CGAL::exact(sph.second); -#endif radius = sc_ptr_->filtration(face_opposite_vertex.first); #ifdef DEBUG_TRACES std::clog << "center: " << sph.first << ", radius: " << radius << std::endl; -- cgit v1.2.3