diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-11-02 14:40:32 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-11-02 14:40:32 +0100 |
commit | ca4de023e18d53ac2889a24554536f4ff3d2a798 (patch) | |
tree | 14a1bcf623efeb64a6d1b78b2eb8dab024b57121 /searchlib/src/tests | |
parent | 8bc2757879350c2ebe979aa6602bbebe9872ef91 (diff) |
Pass subspace to DocVectorAccess::get_vector member function.
Diffstat (limited to 'searchlib/src/tests')
5 files changed, 59 insertions, 17 deletions
diff --git a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp index 9127c4b59fc..791ce80f62a 100644 --- a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp +++ b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp @@ -198,7 +198,7 @@ public: size_t memory_usage_cnt() const { return _memory_usage_cnt; } void add_document(uint32_t docid) override { - auto vector = _vectors.get_vector(docid).typify<double>(); + auto vector = _vectors.get_vector(docid, 0).typify<double>(); _adds.emplace_back(docid, DoubleVector(vector.begin(), vector.end())); } std::unique_ptr<PrepareResult> prepare_add_document(uint32_t docid, @@ -214,11 +214,11 @@ public: auto* mock_result = dynamic_cast<MockPrepareResult*>(prepare_result.get()); assert(mock_result); EXPECT_EQUAL(docid, mock_result->docid); - auto vector = _vectors.get_vector(docid).typify<double>(); + auto vector = _vectors.get_vector(docid, 0).typify<double>(); _complete_adds.emplace_back(docid, DoubleVector(vector.begin(), vector.end())); } void remove_document(uint32_t docid) override { - auto vector = _vectors.get_vector(docid).typify<double>(); + auto vector = _vectors.get_vector(docid, 0).typify<double>(); _removes.emplace_back(docid, DoubleVector(vector.begin(), vector.end())); } void assign_generation(generation_t current_gen) override { diff --git a/searchlib/src/tests/tensor/direct_tensor_store/direct_tensor_store_test.cpp b/searchlib/src/tests/tensor/direct_tensor_store/direct_tensor_store_test.cpp index cb9fa8522a8..cf0656fc919 100644 --- a/searchlib/src/tests/tensor/direct_tensor_store/direct_tensor_store_test.cpp +++ b/searchlib/src/tests/tensor/direct_tensor_store/direct_tensor_store_test.cpp @@ -2,22 +2,23 @@ #include <vespa/searchlib/tensor/direct_tensor_store.h> #include <vespa/vespalib/gtest/gtest.h> -#include <vespa/eval/eval/simple_value.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/vespalib/datastore/datastore.hpp> using namespace search::tensor; using vespalib::datastore::EntryRef; -using vespalib::eval::SimpleValue; +using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::TensorSpec; using vespalib::eval::Value; using vespalib::eval::ValueType; using vespalib::eval::TypedCells; using vespalib::MemoryUsage; -vespalib::string tensor_spec("tensor(x{})"); +vespalib::string tensor_type_spec("tensor(x{})"); class MockBigTensor : public Value { @@ -41,21 +42,21 @@ public: Value::UP make_tensor(const TensorSpec& spec) { - auto value = SimpleValue::from_spec(spec); + auto value = value_from_spec(spec, FastValueBuilderFactory::get()); return std::make_unique<MockBigTensor>(std::move(value)); } Value::UP make_tensor(double value) { - return make_tensor(TensorSpec(tensor_spec).add({{"x", "a"}}, value)); + return make_tensor(TensorSpec(tensor_type_spec).add({{"x", "a"}}, value)); } class DirectTensorStoreTest : public ::testing::Test { public: DirectTensorStore store; - DirectTensorStoreTest() : store() {} + DirectTensorStoreTest() : store(ValueType::from_spec(tensor_type_spec)) {} virtual ~DirectTensorStoreTest() { store.reclaim_all_memory(); @@ -124,5 +125,25 @@ TEST_F(DirectTensorStoreTest, move_on_compact_allocates_new_entry_and_leaves_old EXPECT_GT(mem_2.usedBytes(), mem_1.usedBytes() + tensor_mem_usage.allocatedBytes()); } +TEST_F(DirectTensorStoreTest, get_typed_cells) +{ + auto tensor_spec = TensorSpec(tensor_type_spec).add({{"x", "a"}}, 4.5).add({{"x", "b"}}, 5.5).add({{"x", "c"}}, 6.5).add({{"x", "d"}}, 7.5); + auto tensor = value_from_spec(tensor_spec, FastValueBuilderFactory::get()); + auto ref = store.store_tensor(std::move(tensor)); + std::vector<double> values; + for (uint32_t subspace = 0; subspace < 4; ++subspace) { + auto cells = store.get_typed_cells(ref, subspace).typify<double>(); + EXPECT_EQ(1, cells.size()); + values.emplace_back(cells[0]); + } + EXPECT_EQ((std::vector<double>{4.5, 5.5, 6.5, 7.5}), values); + for (auto tref : { ref, EntryRef() }) { + auto subspace = tref.valid() ? 4 : 0; + auto cells = store.get_typed_cells(tref, subspace).typify<double>(); + EXPECT_EQ(1, cells.size()); + EXPECT_EQ(0.0, cells[0]); + } +} + GTEST_MAIN_RUN_ALL_TESTS() 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 3a50601abbd..8d3d389090b 100644 --- a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp +++ b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp @@ -43,7 +43,8 @@ public: _vectors[docid] = vec; return *this; } - vespalib::eval::TypedCells get_vector(uint32_t docid) const override { + vespalib::eval::TypedCells get_vector(uint32_t docid, uint32_t subspace) const override { + (void) subspace; ArrayRef ref(_vectors[docid]); return vespalib::eval::TypedCells(ref); } @@ -138,7 +139,7 @@ public: } void expect_top_3(uint32_t docid, std::vector<uint32_t> exp_hits) { uint32_t k = 3; - auto qv = vectors.get_vector(docid); + auto qv = vectors.get_vector(docid, 0); auto rv = index->top_k_candidates(qv, k, global_filter->ptr_if_active()).peek(); std::sort(rv.begin(), rv.end(), LesserDistance()); size_t idx = 0; @@ -158,7 +159,7 @@ public: check_with_distance_threshold(docid); } void check_with_distance_threshold(uint32_t docid) { - auto qv = vectors.get_vector(docid); + auto qv = vectors.get_vector(docid, 0); uint32_t k = 3; auto rv = index->top_k_candidates(qv, k, global_filter->ptr_if_active()).peek(); std::sort(rv.begin(), rv.end(), LesserDistance()); @@ -712,7 +713,7 @@ public: UP prepare_add(uint32_t docid, uint32_t max_level = 0) { level_generator->level = max_level; vespalib::GenerationHandler::Guard dummy; - auto vector = vectors.get_vector(docid); + auto vector = vectors.get_vector(docid, 0); return index->prepare_add_document(docid, vector, dummy); } void complete_add(uint32_t docid, UP up) { 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 81b56909d57..c5c88d2eeff 100644 --- a/searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp +++ b/searchlib/src/tests/tensor/hnsw_index/stress_hnsw_mt.cpp @@ -110,8 +110,9 @@ public: memcpy(&_vectors[docid], vec.cbegin(), sizeof(MallocPointVector)); return *this; } - vespalib::eval::TypedCells get_vector(uint32_t docid) const override { + vespalib::eval::TypedCells get_vector(uint32_t docid, uint32_t subspace) const override { assert(docid < NUM_POSSIBLE_DOCS); + (void) subspace; ConstVectorRef ref(_vectors[docid]); return vespalib::eval::TypedCells(ref); } diff --git a/searchlib/src/tests/tensor/tensor_buffer_store/tensor_buffer_store_test.cpp b/searchlib/src/tests/tensor/tensor_buffer_store/tensor_buffer_store_test.cpp index 3bbb6cd334e..05e40200167 100644 --- a/searchlib/src/tests/tensor/tensor_buffer_store/tensor_buffer_store_test.cpp +++ b/searchlib/src/tests/tensor/tensor_buffer_store/tensor_buffer_store_test.cpp @@ -1,14 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/searchlib/tensor/tensor_buffer_store.h> -#include <vespa/eval/eval/simple_value.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/vespalib/gtest/gtest.h> using search::tensor::TensorBufferStore; using vespalib::datastore::EntryRef; -using vespalib::eval::SimpleValue; +using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::TensorSpec; using vespalib::eval::Value; using vespalib::eval::ValueType; @@ -52,7 +53,7 @@ TensorBufferStoreTest::store_tensor(const Value& tensor) EntryRef TensorBufferStoreTest::store_tensor(const TensorSpec& spec) { - auto tensor = SimpleValue::from_spec(spec); + auto tensor = value_from_spec(spec, FastValueBuilderFactory::get()); return store_tensor(*tensor); } @@ -161,4 +162,22 @@ TEST_F(TensorBufferStoreTest, stored_tensor_can_be_encoded_and_stored_as_encoded } } +TEST_F(TensorBufferStoreTest, get_typed_cells) +{ + auto ref = store_tensor(tensor_specs.back()); + std::vector<double> values; + for (uint32_t subspace = 0; subspace < 4; ++subspace) { + auto cells = _store.get_typed_cells(ref, subspace).typify<double>(); + EXPECT_EQ(1, cells.size()); + values.emplace_back(cells[0]); + } + EXPECT_EQ((std::vector<double>{4.5, 5.5, 6.5, 7.5}), values); + for (auto tref : { ref, EntryRef() }) { + auto subspace = tref.valid() ? 4 : 0; + auto cells = _store.get_typed_cells(tref, subspace).typify<double>(); + EXPECT_EQ(1, cells.size()); + EXPECT_EQ(0.0, cells[0]); + } +} + GTEST_MAIN_RUN_ALL_TESTS() |