summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-04-16 14:43:23 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2024-04-16 21:19:19 +0000
commit1862d47ff95d80fbd01ad77d3a79e3283f58603f (patch)
tree76034222fcc4da75b924b3ed7703aeeac6b02268 /searchlib/src/tests
parent302b8f03d28baef770719f8b73315d78fc6da950 (diff)
- Optimize distance calculation for tensors with single dense subspace.
- Let EmptySubspace be invalid. - Add noexcept to get_tensor(s).
Diffstat (limited to 'searchlib/src/tests')
-rw-r--r--searchlib/src/tests/attribute/extendattributes/extendattribute_test.cpp2
-rw-r--r--searchlib/src/tests/tensor/distance_calculator/distance_calculator_test.cpp4
-rw-r--r--searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp11
-rw-r--r--searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp22
4 files changed, 21 insertions, 18 deletions
diff --git a/searchlib/src/tests/attribute/extendattributes/extendattribute_test.cpp b/searchlib/src/tests/attribute/extendattributes/extendattribute_test.cpp
index 48270694394..d67757a3811 100644
--- a/searchlib/src/tests/attribute/extendattributes/extendattribute_test.cpp
+++ b/searchlib/src/tests/attribute/extendattributes/extendattribute_test.cpp
@@ -224,7 +224,7 @@ void ExtendAttributeTest::testExtendRaw(AttributeVector& attr)
void ExtendAttributeTest::testExtendTensor(AttributeVector& attr)
{
- std::vector<double> empty_cells{0.0, 0.0};
+ std::vector<double> empty_cells{};
std::vector<double> spec0_dense_cells{1.0, 2.0};
std::vector<double> spec0_mixed_cells0{3.0, 4.0};
std::vector<double> spec0_mixed_cells1{5.0, 6.0};
diff --git a/searchlib/src/tests/tensor/distance_calculator/distance_calculator_test.cpp b/searchlib/src/tests/tensor/distance_calculator/distance_calculator_test.cpp
index b7702398857..dab335675d8 100644
--- a/searchlib/src/tests/tensor/distance_calculator/distance_calculator_test.cpp
+++ b/searchlib/src/tests/tensor/distance_calculator/distance_calculator_test.cpp
@@ -44,7 +44,9 @@ public:
double calc_distance(uint32_t docid, const vespalib::string& query_tensor) {
auto qt = make_tensor(query_tensor);
auto calc = DistanceCalculator::make_with_validation(*attr, *qt);
- return calc->calc_with_limit(docid, std::numeric_limits<double>::max());
+ return calc->has_single_subspace()
+ ? calc->calc_with_limit<true>(docid, std::numeric_limits<double>::max())
+ : calc->calc_with_limit<false>(docid, std::numeric_limits<double>::max());
}
double calc_rawscore(uint32_t docid, const vespalib::string& query_tensor) {
auto qt = make_tensor(query_tensor);
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 c01fc33767a..b697effeab4 100644
--- a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
+++ b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
@@ -62,14 +62,14 @@ public:
_vectors[docid] = vec;
return *this;
}
- vespalib::eval::TypedCells get_vector(uint32_t docid, uint32_t subspace) const override {
+ vespalib::eval::TypedCells get_vector(uint32_t docid, uint32_t subspace) const noexcept override {
return get_vectors(docid).cells(subspace);
}
- VectorBundle get_vectors(uint32_t docid) const override {
+ VectorBundle get_vectors(uint32_t docid) const noexcept override {
ArrayRef ref(_vectors[docid]);
assert((ref.size() % _subspace_type.size()) == 0);
uint32_t subspaces = ref.size() / _subspace_type.size();
- return VectorBundle(ref.data(), subspaces, _subspace_type);
+ return {ref.data(), subspaces, _subspace_type};
}
void clear() { _vectors.clear(); }
@@ -106,7 +106,7 @@ public:
.set(7, {3, 5}).set(8, {0, 3}).set(9, {4, 5});
}
- ~HnswIndexTest() override {}
+ ~HnswIndexTest() override;
auto dff() {
return search::tensor::make_distance_function_factory(
@@ -280,6 +280,9 @@ public:
static constexpr bool is_single = std::is_same_v<IndexType, HnswIndex<HnswIndexType::SINGLE>>;
};
+template <typename IndexType>
+HnswIndexTest<IndexType>::~HnswIndexTest() = default;
+
using HnswIndexTestTypes = ::testing::Types<HnswIndex<HnswIndexType::SINGLE>, HnswIndex<HnswIndexType::MULTI>>;
TYPED_TEST_SUITE(HnswIndexTest, HnswIndexTestTypes);
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 1feb968fbb4..dce09a87fb8 100644
--- a/searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp
+++ b/searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp
@@ -1,13 +1,5 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <fcntl.h>
-#include <cstdio>
-#include <unistd.h>
-#include <chrono>
-#include <cstdlib>
-#include <future>
-#include <vector>
-
#include <vespa/eval/eval/typed_cells.h>
#include <vespa/eval/eval/value_type.h>
#include <vespa/searchlib/common/bitvector.h>
@@ -25,6 +17,9 @@
#include <vespa/vespalib/util/lambdatask.h>
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/vespalib/data/simple_buffer.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <future>
#include <vespa/log/log.h>
LOG_SETUP("stress_hnsw_mt");
@@ -119,17 +114,17 @@ public:
memcpy(&_vectors[docid], vec.cbegin(), sizeof(MallocPointVector));
return *this;
}
- vespalib::eval::TypedCells get_vector(uint32_t docid, uint32_t subspace) const override {
+ vespalib::eval::TypedCells get_vector(uint32_t docid, uint32_t subspace) const noexcept override {
assert(docid < NUM_POSSIBLE_DOCS);
(void) subspace;
ConstVectorRef ref(_vectors[docid]);
return vespalib::eval::TypedCells(ref);
}
- VectorBundle get_vectors(uint32_t docid) const override {
+ VectorBundle get_vectors(uint32_t docid) const noexcept override {
assert(docid < NUM_POSSIBLE_DOCS);
ConstVectorRef ref(_vectors[docid]);
assert(subspace_type.size() == ref.size());
- return VectorBundle(ref.data(), 1, subspace_type);
+ return {ref.data(), 1, subspace_type};
}
};
@@ -257,7 +252,7 @@ public:
loaded_vectors.load();
}
- ~Stressor() {}
+ ~Stressor() override;
auto dff() {
return search::tensor::make_distance_function_factory(
@@ -352,6 +347,9 @@ public:
}
};
+template <typename IndexType>
+Stressor<IndexType>::~Stressor() = default;
+
using StressorTypes = ::testing::Types<HnswIndex<HnswIndexType::SINGLE>>;
TYPED_TEST_SUITE(Stressor, StressorTypes);