summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnur Nigmetov <a.nigmetov@gmail.com>2018-06-19 22:51:58 +0200
committerArnur Nigmetov <a.nigmetov@gmail.com>2018-06-19 22:51:58 +0200
commite2a2d6cb2eec5a7153d6e895a28c85c49347f644 (patch)
tree86fb2873f0b479a8766aaddd3da5874281e82a66
parent4e3fcd2f8596f39b9bff8cdd8d9789fdffe8a49c (diff)
Template bug fixed
-rw-r--r--geom_bottleneck/include/basic_defs_bt.h7
-rw-r--r--geom_bottleneck/include/bottleneck_detail.hpp12
-rw-r--r--geom_bottleneck/tests/test_hera_bottleneck.cpp28
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<class R>
- friend std::ostream& operator<<(std::ostream& output, const DiagramPoint<R>& 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<class R>
- friend std::ostream& operator<<(std::ostream& output, const DiagramPointSet<R>& 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<Real>::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<Real> 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<size_t>(floor(idxMin + idxMax) / 2.0);
+ idxMid = static_cast<size_t>(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<size_t>(floor(idxMin + idxMax) / 2.0);
+ idxMid = static_cast<size_t>(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<std::pair<double, double>>;
+using PairVectorF = std::vector<std::pair<float, float>>;
std::vector<std::string> 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<double>();
+
+ SECTION("trivial: two empty diagrams") {
+ REQUIRE( 0.0 == hera::bottleneckDistApprox<PairVectorF>(diagram_A, diagram_B, delta));
+ REQUIRE( 0.0 == hera::bottleneckDistExact<PairVectorF>(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<PairVectorF>(diagram_A, diagram_B, delta);
+ float d2 = hera::bottleneckDistApprox<PairVectorF>(diagram_B, diagram_A, delta);
+ float d3 = hera::bottleneckDistExact<PairVectorF>(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")
{