From 05391413632841596bd0cd8e40389a185461a0af Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Mon, 12 Apr 2021 11:22:25 +0000 Subject: fix NNS distance for new cell types This reverts commit f167fe4362c5e4e20a7605b99205cfbee77c569a. --- .../src/tests/tensor/distance_functions/distance_functions_test.cpp | 6 ++++++ searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp | 3 +-- searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'searchlib/src/tests/tensor') diff --git a/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp b/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp index ee0a2aff80e..6f8c9b4c885 100644 --- a/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp +++ b/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp @@ -10,6 +10,7 @@ LOG_SETUP("distance_function_test"); using namespace search::tensor; +using vespalib::eval::Int8Float; using vespalib::eval::TypedCells; using search::attribute::DistanceMetric; @@ -212,6 +213,11 @@ TEST(DistanceFunctionsTest, hamming_gives_expected_score) EXPECT_DOUBLE_EQ(threshold, 0.5); threshold = hamming->convert_threshold(1.0); EXPECT_DOUBLE_EQ(threshold, 1.0); + + std::vector bytes_a = { 0, 1, 2, 4, 8, 16, 32, 64, -128, 0, 1, 2, 4, 8, 16, 32, 64, -128, 0, 1, 2 }; + std::vector bytes_b = { 1, 2, 2, 4, 8, 16, 32, 65, -128, 0, 1, 0, 4, 8, 16, 32, 64, -128, 0, 1, -1 }; + // expect diff: 1 2 1 1 7 + EXPECT_EQ(hamming->calc(TypedCells(bytes_a), TypedCells(bytes_b)), 12.0); } TEST(GeoDegreesTest, gives_expected_score) diff --git a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp index 20dc55df329..6ffe118aa65 100644 --- a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp +++ b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp @@ -51,7 +51,6 @@ struct LevelGenerator : public RandomLevelGenerator { }; using FloatVectors = MyDocVectorAccess; -using FloatSqEuclideanDistance = SquaredEuclideanDistance; using HnswIndexUP = std::unique_ptr; class HnswIndexTest : public ::testing::Test { @@ -79,7 +78,7 @@ public: void init(bool heuristic_select_neighbors) { auto generator = std::make_unique(); level_generator = generator.get(); - index = std::make_unique(vectors, std::make_unique(), + index = std::make_unique(vectors, std::make_unique(), std::move(generator), HnswIndex::Config(5, 2, 10, 0, heuristic_select_neighbors)); } diff --git a/searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp b/searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp index 8e3bb95a776..7acdb4df983 100644 --- a/searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp +++ b/searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp @@ -117,7 +117,6 @@ public: } }; -using FloatSqEuclideanDistance = SquaredEuclideanDistance; using HnswIndexUP = std::unique_ptr; class Stressor : public ::testing::Test { @@ -232,7 +231,7 @@ public: void init() { uint32_t m = 16; - index = std::make_unique(vectors, std::make_unique(), + index = std::make_unique(vectors, std::make_unique(), std::make_unique(m), HnswIndex::Config(2*m, m, 200, 10, true)); } -- cgit v1.2.3