From 76798df019eec75c9a2de727be409b4099b1aab3 Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Wed, 15 Jan 2025 11:20:41 -0500 Subject: [PATCH] Add verbose parameter to verifyDBSCAN Default it to false so that we don't have any output in the tests by default. --- .../dbscan/ArborX_DBSCANVerification.hpp | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/benchmarks/dbscan/ArborX_DBSCANVerification.hpp b/benchmarks/dbscan/ArborX_DBSCANVerification.hpp index f45e02b61..dd09c97f8 100644 --- a/benchmarks/dbscan/ArborX_DBSCANVerification.hpp +++ b/benchmarks/dbscan/ArborX_DBSCANVerification.hpp @@ -33,7 +33,7 @@ template = core_min_size); if (self_is_core_point && labels(i) < 0) { - Kokkos::printf("Core point is marked as noise: %d [%d]\n", i, - labels(i)); + if (verbose) + Kokkos::printf("Core point is marked as noise: %d [%d]\n", i, + labels(i)); update++; } }, @@ -59,7 +60,8 @@ template bool verifyConnectedCorePointsShareIndex(ExecutionSpace const &exec_space, IndicesView indices, OffsetView offset, - LabelsView labels, int core_min_size) + LabelsView labels, int core_min_size, + bool verbose) { int n = labels.size(); @@ -79,10 +81,11 @@ bool verifyConnectedCorePointsShareIndex(ExecutionSpace const &exec_space, if (neigh_is_core_point && labels(i) != labels(j)) { - Kokkos::printf( - "Connected cores do not belong to the same cluster: " - "%d [%d] -> %d [%d]\n", - i, labels(i), j, labels(j)); + if (verbose) + Kokkos::printf( + "Connected cores do not belong to the same cluster: " + "%d [%d] -> %d [%d]\n", + i, labels(i), j, labels(j)); update++; } } @@ -98,7 +101,8 @@ template bool verifyBorderAndNoisePoints(ExecutionSpace const &exec_space, IndicesView indices, OffsetView offset, - LabelsView labels, int core_min_size) + LabelsView labels, int core_min_size, + bool verbose) { int n = labels.size(); @@ -132,16 +136,18 @@ bool verifyBorderAndNoisePoints(ExecutionSpace const &exec_space, // Border point must be connected to a core point if (is_border && !have_shared_core) { - Kokkos::printf( - "Border point does not belong to a cluster: %d [%d]\n", i, - labels(i)); + if (verbose) + Kokkos::printf( + "Border point does not belong to a cluster: %d [%d]\n", i, + labels(i)); update++; } // Noise points must have index -1 if (!is_border && labels(i) != -1) { - Kokkos::printf("Noise point does not have index -1: %d [%d]\n", i, - labels(i)); + if (verbose) + Kokkos::printf("Noise point does not have index -1: %d [%d]\n", i, + labels(i)); update++; } } @@ -155,7 +161,7 @@ template bool verifyClustersAreUnique(ExecutionSpace const &exec_space, IndicesView indices, OffsetView offset, - LabelsView labels, int core_min_size) + LabelsView labels, int core_min_size, bool verbose) { int n = labels.size(); @@ -241,12 +247,14 @@ bool verifyClustersAreUnique(ExecutionSpace const &exec_space, } if (cluster_sets.size() != num_unique_cluster_indices) { - std::cerr << "Number of components does not match\n"; + if (verbose) + std::cerr << "Number of components does not match\n"; return false; } if (num_clusters != num_unique_cluster_indices) { - std::cerr << "Cluster IDs are not unique\n"; + if (verbose) + std::cerr << "Cluster IDs are not unique\n"; return false; } @@ -256,7 +264,8 @@ bool verifyClustersAreUnique(ExecutionSpace const &exec_space, template bool verifyClusters(ExecutionSpace const &exec_space, IndicesView indices, - OffsetView offset, LabelsView labels, int core_min_size) + OffsetView offset, LabelsView labels, int core_min_size, + bool verbose) { int n = labels.size(); if ((int)offset.size() != n + 1 || @@ -264,7 +273,7 @@ bool verifyClusters(ExecutionSpace const &exec_space, IndicesView indices, return false; using Verify = bool (*)(ExecutionSpace const &, IndicesView, OffsetView, - LabelsView, int); + LabelsView, int, bool); std::vector verify{ static_cast(verifyCorePointsNonnegativeIndex), @@ -272,7 +281,7 @@ bool verifyClusters(ExecutionSpace const &exec_space, IndicesView indices, static_cast(verifyBorderAndNoisePoints), static_cast(verifyClustersAreUnique)}; return std::all_of(verify.begin(), verify.end(), [&](Verify const &verify) { - return verify(exec_space, indices, offset, labels, core_min_size); + return verify(exec_space, indices, offset, labels, core_min_size, verbose); }); } @@ -288,7 +297,8 @@ struct IndexOnlyCallback template bool verifyDBSCAN(ExecutionSpace exec_space, Primitives const &primitives, - float eps, int core_min_size, LabelsView const &labels) + float eps, int core_min_size, LabelsView const &labels, + bool verbose = false) { Kokkos::Profiling::pushRegion("ArborX::DBSCAN::verify"); @@ -317,7 +327,7 @@ bool verifyDBSCAN(ExecutionSpace exec_space, Primitives const &primitives, IndexOnlyCallback{}, indices, offset); auto passed = Details::verifyClusters(exec_space, indices, offset, labels, - core_min_size); + core_min_size, verbose); Kokkos::Profiling::popRegion(); return passed;