From 08393e9e14635f1c6a6c84650c25023a0db7ed0b Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Tue, 13 Oct 2020 14:11:28 +0000 Subject: handle both engine- and factory-based tensors * use EngineOrFactory::get() instead of DefaultTensorEngine::ref() * avoid direct use of DenseTensorView etc where possible * use eval::Value instead of tensor::Tensor where possible --- searchcore/src/tests/proton/matching/matching_test.cpp | 5 +++-- .../matching/request_context/request_context_test.cpp | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'searchcore/src/tests/proton/matching') diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp index 30f83273bd7..11ea6e87233 100644 --- a/searchcore/src/tests/proton/matching/matching_test.cpp +++ b/searchcore/src/tests/proton/matching/matching_test.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -59,7 +60,7 @@ using search::fef::indexproperties::hitcollector::HeapSize; using vespalib::nbostream; using vespalib::eval::TensorSpec; -using vespalib::tensor::DefaultTensorEngine; +using vespalib::eval::EngineOrFactory; void inject_match_phase_limiting(Properties &setup, const vespalib::string &attribute, size_t max_hits, bool descending) { @@ -666,7 +667,7 @@ TEST("require that summary features are filled") { EXPECT_TRUE(!f[2].is_double()); EXPECT_TRUE(f[2].is_data()); { - auto &engine = DefaultTensorEngine::ref(); + auto engine = EngineOrFactory::get(); nbostream buf(f[2].as_data().data, f[2].as_data().size); auto actual = engine.to_spec(*engine.decode(buf)); auto expect = TensorSpec("tensor(x[3])").add({{"x", 0}}, 0).add({{"x", 1}}, 1).add({{"x", 2}}, 2); diff --git a/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp b/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp index 3b54768f223..90a6e173129 100644 --- a/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp +++ b/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp @@ -1,6 +1,7 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include +#include #include #include #include @@ -13,9 +14,9 @@ using search::attribute::IAttributeContext; using search::attribute::IAttributeFunctor; using search::attribute::IAttributeVector; using search::fef::Properties; +using vespalib::eval::EngineOrFactory; using vespalib::eval::TensorSpec; using vespalib::eval::Value; -using vespalib::tensor::DefaultTensorEngine; using namespace proton; class MyAttributeContext : public search::attribute::IAttributeContext { @@ -37,7 +38,7 @@ private: void insert_tensor_in_properties(const vespalib::string& tensor_name, const Value& tensor_value) { vespalib::nbostream stream; - DefaultTensorEngine::ref().encode(tensor_value, stream); + EngineOrFactory::get().encode(tensor_value, stream); _props.add(tensor_name, vespalib::stringref(stream.data(), stream.size())); } @@ -48,13 +49,15 @@ public: _attr_ctx(), _props(), _request_ctx(_doom, _attr_ctx, _props, AttributeBlueprintParams()), - _query_tensor(DefaultTensorEngine::ref().from_spec(TensorSpec("tensor(x[2])") + _query_tensor(EngineOrFactory::get().from_spec(TensorSpec("tensor(x[2])") .add({{"x", 0}}, 3).add({{"x", 1}}, 5))) { insert_tensor_in_properties("my_tensor", *_query_tensor); _props.add("my_string", "foo bar"); } - TensorSpec expected_query_tensor() const { return DefaultTensorEngine::ref().to_spec(*_query_tensor); } + TensorSpec expected_query_tensor() const { + return EngineOrFactory::get().to_spec(*_query_tensor); + } Value::UP get_query_tensor(const vespalib::string& tensor_name) const { return _request_ctx.get_query_tensor(tensor_name); } @@ -65,7 +68,7 @@ TEST_F(RequestContextTest, query_tensor_can_be_retrieved) auto tensor = get_query_tensor("my_tensor"); ASSERT_TRUE(tensor); EXPECT_TRUE(tensor->is_tensor()); - EXPECT_EQ(expected_query_tensor(), DefaultTensorEngine::ref().to_spec(*tensor)); + EXPECT_EQ(expected_query_tensor(), EngineOrFactory::get().to_spec(*tensor)); } TEST_F(RequestContextTest, non_existing_query_tensor_returns_nullptr) -- cgit v1.2.3