From e2a2d6cb2eec5a7153d6e895a28c85c49347f644 Mon Sep 17 00:00:00 2001 From: Arnur Nigmetov Date: Tue, 19 Jun 2018 22:51:58 +0200 Subject: Template bug fixed --- geom_bottleneck/include/basic_defs_bt.h | 7 +++---- geom_bottleneck/include/bottleneck_detail.hpp | 12 +++++------ geom_bottleneck/tests/test_hera_bottleneck.cpp | 28 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/geom_bottleneck/include/basic_defs_bt.h b/geom_bottleneck/include/basic_defs_bt.h index a26d9a5..6124dbe 100644 --- a/geom_bottleneck/include/basic_defs_bt.h +++ b/geom_bottleneck/include/basic_defs_bt.h @@ -206,8 +206,7 @@ namespace hera { #ifndef FOR_R_TDA - template - friend std::ostream& operator<<(std::ostream& output, const DiagramPoint& p) + friend std::ostream& operator<<(std::ostream& output, const DiagramPoint& p) { if (p.isDiagonal()) { output << "(" << p.x << ", " << p.y << ", " << 0.5 * (p.x + p.y) << ", " << p.id << " DIAG )"; @@ -245,6 +244,7 @@ namespace hera { return 0.0; } // otherwise distance is a usual l-inf distance + // Real dx = (a.getRealX() == b.getRealX()) ? 0.0 : fabs(a.getRealX() - b.getRealX()); Real dy = (a.getRealY() == b.getRealY()) ? 0.0 : fabs(a.getRealY() - b.getRealY()); Real result = std::max(dx, dy); @@ -406,8 +406,7 @@ namespace hera { #ifndef FOR_R_TDA - template - friend std::ostream& operator<<(std::ostream& output, const DiagramPointSet& ps) + friend std::ostream& operator<<(std::ostream& output, const DiagramPointSet& ps) { output << "{ "; for (auto pit = ps.cbegin(); pit != ps.cend(); ++pit) { diff --git a/geom_bottleneck/include/bottleneck_detail.hpp b/geom_bottleneck/include/bottleneck_detail.hpp index 8ec9c68..8f51d07 100644 --- a/geom_bottleneck/include/bottleneck_detail.hpp +++ b/geom_bottleneck/include/bottleneck_detail.hpp @@ -468,7 +468,7 @@ namespace hera { Real distEpsilon = std::numeric_limits::max(); Real diffThreshold = 0.1; for (int k = 0; k < decPrecision; ++k) { - diffThreshold /= 10.0; + diffThreshold /= 10; } for (size_t k = 0; k < pairwiseDist.size() - 2; ++k) { auto diff = pairwiseDist[k + 1] - pairwiseDist[k]; @@ -476,7 +476,7 @@ namespace hera { distEpsilon = diff; } } - distEpsilon = std::min(diffThreshold, distEpsilon / 3.0); + distEpsilon = std::min(diffThreshold, distEpsilon / 3); BoundMatchOracle oracle(A, B, distEpsilon, useRangeSearch); // binary search @@ -484,19 +484,19 @@ namespace hera { size_t idxMin { 0 }, idxMax { pairwiseDist.size() - 1 }; size_t idxMid; while (idxMax > idxMin) { - idxMid = static_cast(floor(idxMin + idxMax) / 2.0); + idxMid = static_cast(floor(idxMin + idxMax) / 2); iterNum++; // not A[imid] < dist <=> A[imid] >= dist <=> A[imid[ >= dist + eps - if (oracle.isMatchLess(pairwiseDist[idxMid] + distEpsilon / 2.0)) { + if (oracle.isMatchLess(pairwiseDist[idxMid] + distEpsilon / 2)) { idxMax = idxMid; } else { idxMin = idxMid + 1; } } - idxMid = static_cast(floor(idxMin + idxMax) / 2.0); + idxMid = static_cast(floor(idxMin + idxMax) / 2); Real result = pairwiseDist[idxMid]; if (compute_longest_edge) { - oracle.isMatchLess(result + distEpsilon / 2.0); + oracle.isMatchLess(result + distEpsilon / 2); longest_edge = oracle.get_longest_edge(); } return result; diff --git a/geom_bottleneck/tests/test_hera_bottleneck.cpp b/geom_bottleneck/tests/test_hera_bottleneck.cpp index 922a4b0..f22e415 100644 --- a/geom_bottleneck/tests/test_hera_bottleneck.cpp +++ b/geom_bottleneck/tests/test_hera_bottleneck.cpp @@ -6,6 +6,7 @@ #include "bottleneck.h" using PairVector = std::vector>; +using PairVectorF = std::vector>; std::vector split_on_delim(const std::string& s, char delim) { @@ -113,6 +114,33 @@ TEST_CASE("simple cases", "bottleneckDistApprox") } +TEST_CASE("float version", "check_template") +{ + PairVectorF diagram_A, diagram_B; + float delta = 0.01; + //float internal_p = hera::get_infinity(); + + SECTION("trivial: two empty diagrams") { + REQUIRE( 0.0 == hera::bottleneckDistApprox(diagram_A, diagram_B, delta)); + REQUIRE( 0.0 == hera::bottleneckDistExact(diagram_A, diagram_B)); + } + + SECTION("trivial: two single-point diagrams-2") { + + diagram_A.emplace_back(10, 20); // (5, 5) + diagram_B.emplace_back(130, 138); // (4, 4) + + float d1 = hera::bottleneckDistApprox(diagram_A, diagram_B, delta); + float d2 = hera::bottleneckDistApprox(diagram_B, diagram_A, delta); + float d3 = hera::bottleneckDistExact(diagram_B, diagram_A); + float correct_answer = 5; + REQUIRE( fabs(d1 - correct_answer) <= delta * correct_answer ); + REQUIRE( fabs(d2 - correct_answer) <= delta * correct_answer ); + + } + +} + TEST_CASE("infinity points", "bottleneckDistApprox") { -- cgit v1.2.3