Skip to content

Commit ebe5bf0

Browse files
committed
fix(test): use FloatSpace::get_data_size and fix groundtruth call
- Replace invalid static_cast on Metric struct in test_helpers with feature_space.get_data_size() - Fix undefined compute_gt call in deglib_groundtruth.cpp to compute_knn_groundtruth
1 parent 61d6240 commit ebe5bf0

2 files changed

Lines changed: 7 additions & 21 deletions

File tree

cpp/benchmark/src/deglib_groundtruth.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int main() {
148148
const auto query_repository = deglib::load_static_repository(query_file_uint8.c_str());
149149

150150
const auto start = std::chrono::system_clock::now();
151-
const auto topLists = compute_gt(base_repository, query_repository, deglib::Metric::L2_Uint8, k_target);
151+
const auto topLists = compute_knn_groundtruth(base_repository, query_repository, deglib::Metric::L2_Uint8, k_target);
152152
auto duration = uint32_t(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - start).count());
153153
fmt::print("Computing {:5} top lists of a {:8} base took {:5}s \n", query_repository.size(), base_repository.size(), duration);
154154
topListsUint8 = topLists;
@@ -165,7 +165,7 @@ int main() {
165165
const auto query_repository = deglib::load_static_repository(query_file.c_str());
166166

167167
const auto start = std::chrono::system_clock::now();
168-
const auto topLists = compute_gt(base_repository, query_repository, deglib::Metric::L2, k_target);
168+
const auto topLists = compute_knn_groundtruth(base_repository, query_repository, deglib::Metric::L2, k_target);
169169
auto duration = uint32_t(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - start).count());
170170
fmt::print("Computing {:5} top lists of a {:8} base took {:5}s \n", query_repository.size(), base_repository.size(), duration);
171171
topListsFloat = topLists;

cpp/test/src/common/test_helpers.h

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -454,20 +454,13 @@ inline static void run_integration_test(const char* name, deglib::Metric metric,
454454
const uint32_t additional_swap_tries = 0;
455455
const uint32_t thread_count = 1;
456456

457-
// Compute byte size per vector based on metric type
458-
size_t feature_bytes;
459-
if (metric == deglib::Metric::FP16InnerProduct)
460-
feature_bytes = dim * sizeof(uint16_t);
461-
else if (metric == deglib::Metric::EVPInnerProduct)
462-
feature_bytes = 2 * (dim / 8);
463-
else
464-
feature_bytes = (static_cast<int>(metric) & 0x10) ? dim * sizeof(uint8_t) : dim * sizeof(float);
465-
466457
// Build DEG Graph using the specified metric feature space
467458
const deglib::FloatSpace feature_space = dist_variant.has_value()
468459
? deglib::FloatSpace(dim, metric, dist_variant.value())
469460
: deglib::FloatSpace(dim, metric);
470461

462+
const size_t feature_bytes = feature_space.get_data_size();
463+
471464
deglib::graph::SizeBoundedGraph graph(static_cast<uint32_t>(base_count), edges_per_vertex,
472465
std::move(feature_space));
473466

@@ -587,7 +580,7 @@ inline static void run_builder_integration_test(const char* name, deglib::Metric
587580
std::optional<deglib::DistanceVariant> dist_variant,
588581
deglib::builder::OptimizationTarget optimization_target)
589582
{
590-
if (static_cast<int>(metric) & 0x10)
583+
if (metric.get_data_type() == deglib::MetricDataType::Uint8)
591584
{
592585
// uint8 metric
593586
std::vector<uint8_t> base_data;
@@ -678,20 +671,13 @@ inline static void run_regression_test(const char* name, deglib::Metric metric,
678671
const uint32_t additional_swap_tries = 0;
679672
const uint32_t thread_count = 1;
680673

681-
// Compute byte size per vector based on metric type
682-
size_t feature_bytes;
683-
if (metric == deglib::Metric::FP16InnerProduct)
684-
feature_bytes = dim * sizeof(uint16_t);
685-
else if (metric == deglib::Metric::EVPInnerProduct)
686-
feature_bytes = 2 * (dim / 8);
687-
else
688-
feature_bytes = (static_cast<int>(metric) & 0x10) ? dim * sizeof(uint8_t) : dim * sizeof(float);
689-
690674
// Build DEG Graph using the specified metric feature space
691675
const deglib::FloatSpace feature_space = dist_variant.has_value()
692676
? deglib::FloatSpace(dim, metric, dist_variant.value())
693677
: deglib::FloatSpace(dim, metric);
694678

679+
const size_t feature_bytes = feature_space.get_data_size();
680+
695681
deglib::graph::SizeBoundedGraph graph(static_cast<uint32_t>(base_count), edges_per_vertex,
696682
std::move(feature_space));
697683

0 commit comments

Comments
 (0)