diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-10-13 14:11:28 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-10-15 08:18:59 +0000 |
commit | 08393e9e14635f1c6a6c84650c25023a0db7ed0b (patch) | |
tree | 48aae1605140fc6ff7d571084f345d33a3189c62 /searchlib/src/tests/features | |
parent | 61eaea251e8cacd320ac10754ffd1513d8638043 (diff) |
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
Diffstat (limited to 'searchlib/src/tests/features')
5 files changed, 54 insertions, 57 deletions
diff --git a/searchlib/src/tests/features/constant/constant_test.cpp b/searchlib/src/tests/features/constant/constant_test.cpp index e558839d2cf..e513e20a35c 100644 --- a/searchlib/src/tests/features/constant/constant_test.cpp +++ b/searchlib/src/tests/features/constant/constant_test.cpp @@ -1,14 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> - +#include <iostream> #include <vespa/searchlib/features/setup.h> #include <vespa/searchlib/fef/fef.h> #include <vespa/searchlib/fef/test/ftlib.h> #include <vespa/searchlib/fef/test/indexenvironment.h> #include <vespa/eval/eval/function.h> #include <vespa/eval/eval/tensor_spec.h> -#include <vespa/eval/tensor/tensor.h> -#include <vespa/eval/tensor/default_tensor_engine.h> +#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/value.h> +#include <vespa/eval/eval/test/value_compare.h> using search::feature_t; using namespace search::fef; @@ -20,15 +21,13 @@ using vespalib::eval::Value; using vespalib::eval::DoubleValue; using vespalib::eval::TensorSpec; using vespalib::eval::ValueType; -using vespalib::tensor::DefaultTensorEngine; -using vespalib::tensor::Tensor; +using vespalib::eval::EngineOrFactory; namespace { -Tensor::UP make_tensor(const TensorSpec &spec) { - auto tensor = DefaultTensorEngine::ref().from_spec(spec); - return Tensor::UP(dynamic_cast<Tensor*>(tensor.release())); +Value::UP make_tensor(const TensorSpec &spec) { + return EngineOrFactory::get().from_spec(spec); } } @@ -44,12 +43,12 @@ struct ExecFixture setup_search_features(factory); } bool setup() { return test.setup(); } - const Tensor &extractTensor(uint32_t docid) { + const Value &extractTensor(uint32_t docid) { Value::CREF value = test.resolveObjectFeature(docid); ASSERT_TRUE(value.get().is_tensor()); - return static_cast<const Tensor &>(*value.get().as_tensor()); + return value.get(); } - const Tensor &executeTensor(uint32_t docId = 1) { + const Value &executeTensor(uint32_t docId = 1) { return extractTensor(docId); } double extractDouble(uint32_t docid) { @@ -63,7 +62,7 @@ struct ExecFixture void addTensor(const vespalib::string &name, const TensorSpec &spec) { - Tensor::UP tensor = make_tensor(spec); + Value::UP tensor = make_tensor(spec); ValueType type(tensor->type()); test.getIndexEnv().addConstantValue(name, std::move(type), diff --git a/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp b/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp index 2f710c5d6e1..3a755704c0d 100644 --- a/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp +++ b/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp @@ -6,8 +6,7 @@ #include <vespa/searchlib/fef/test/ftlib.h> #include <vespa/searchlib/fef/test/rankresult.h> #include <vespa/searchlib/fef/test/dummy_dependency_handler.h> -#include <vespa/eval/tensor/tensor.h> -#include <vespa/eval/tensor/serialization/typed_binary_format.h> +#include <vespa/eval/eval/engine_or_factory.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/eval/tensor/dense/dense_tensor.h> @@ -108,9 +107,9 @@ struct ArrayFixture : FixtureBase { } template <typename ExpectedType> - void check_prepare_state_output(const vespalib::tensor::Tensor & tensor, const ExpectedType & expected) { + void check_prepare_state_output(const vespalib::eval::Value & tensor, const ExpectedType & expected) { vespalib::nbostream os; - vespalib::tensor::TypedBinaryFormat::serialize(os, tensor); + vespalib::eval::EngineOrFactory::get().encode(tensor, os); vespalib::string input_vector(os.data(), os.size()); check_prepare_state_output(".tensor", input_vector, expected); } diff --git a/searchlib/src/tests/features/tensor/tensor_test.cpp b/searchlib/src/tests/features/tensor/tensor_test.cpp index 18efd69d0b9..116b4ed2bb5 100644 --- a/searchlib/src/tests/features/tensor/tensor_test.cpp +++ b/searchlib/src/tests/features/tensor/tensor_test.cpp @@ -11,11 +11,11 @@ #include <vespa/searchlib/fef/test/queryenvironment.h> #include <vespa/searchlib/tensor/tensor_attribute.h> #include <vespa/searchlib/tensor/direct_tensor_attribute.h> +#include <vespa/eval/eval/engine_or_factory.h> #include <vespa/eval/eval/function.h> #include <vespa/eval/eval/tensor_spec.h> -#include <vespa/eval/tensor/tensor.h> -#include <vespa/eval/tensor/default_tensor_engine.h> -#include <vespa/eval/tensor/serialization/typed_binary_format.h> +#include <vespa/eval/eval/value.h> +#include <vespa/eval/eval/test/value_compare.h> #include <vespa/eval/tensor/test/test_utils.h> #include <vespa/vespalib/objects/nbostream.h> @@ -28,12 +28,11 @@ using search::AttributeFactory; using search::tensor::TensorAttribute; using search::tensor::DirectTensorAttribute; using search::AttributeVector; +using vespalib::eval::EngineOrFactory; using vespalib::eval::Function; using vespalib::eval::Value; using vespalib::eval::ValueType; using vespalib::eval::TensorSpec; -using vespalib::tensor::DefaultTensorEngine; -using vespalib::tensor::Tensor; using vespalib::tensor::test::makeTensor; using AVC = search::attribute::Config; @@ -46,8 +45,8 @@ using CollectionType = FieldInfo::CollectionType; namespace { -Tensor::UP make_empty(const vespalib::string &type) { - return makeTensor<Tensor>(TensorSpec(type)); +Value::UP make_empty(const vespalib::string &type) { + return EngineOrFactory::get().from_spec(TensorSpec(type)); } } @@ -114,7 +113,7 @@ struct ExecFixture DirectTensorAttribute *directAttr = dynamic_cast<DirectTensorAttribute *>(attrs[1].get()); - auto doc_tensor = makeTensor<Tensor>(TensorSpec("tensor(x{})") + auto doc_tensor = makeTensor<Value>(TensorSpec("tensor(x{})") .add({{"x", "a"}}, 3) .add({{"x", "b"}}, 5) .add({{"x", "c"}}, 7)); @@ -127,10 +126,10 @@ struct ExecFixture } void setQueryTensor(const vespalib::string &tensorName, const vespalib::string &tensorTypeSpec, - std::unique_ptr<Tensor> tensor) + std::unique_ptr<Value> tensor) { vespalib::nbostream stream; - vespalib::tensor::TypedBinaryFormat::serialize(stream, *tensor); + EngineOrFactory::get().encode(*tensor, stream); test.getQueryEnv().getProperties().add(tensorName, vespalib::stringref(stream.peek(), stream.size())); setQueryTensorType(tensorName, tensorTypeSpec); @@ -139,24 +138,24 @@ struct ExecFixture void setupQueryEnvironment() { setQueryTensor("tensorquery", "tensor(q{})", - makeTensor<Tensor>(TensorSpec("tensor(q{})") + makeTensor<Value>(TensorSpec("tensor(q{})") .add({{"q", "d"}}, 11 ) .add({{"q", "e"}}, 13 ) .add({{"q", "f"}}, 17 ))); setQueryTensor("mappedtensorquery", "tensor(x[2])", - makeTensor<Tensor>(TensorSpec("tensor(x{},y{})") + makeTensor<Value>(TensorSpec("tensor(x{},y{})") .add({{"x", "0"},{"y", "0"}}, 11 ) .add({{"x", "0"},{"y", "1"}}, 13 ) .add({{"x", "1"},{"y", "0"}}, 17 ))); setQueryTensorType("null", "tensor(q{})"); } - const Tensor &extractTensor(uint32_t docid) { + const Value &extractTensor(uint32_t docid) { Value::CREF value = test.resolveObjectFeature(docid); ASSERT_TRUE(value.get().is_tensor()); - return static_cast<const Tensor &>(*value.get().as_tensor()); + return value.get(); } - const Tensor &execute(uint32_t docId = 1) { + const Value &execute(uint32_t docId = 1) { return extractTensor(docId); } }; @@ -164,7 +163,7 @@ struct ExecFixture TEST_F("require that tensor attribute can be extracted as tensor in attribute feature", ExecFixture("attribute(tensorattr)")) { - EXPECT_EQUAL(*makeTensor<Tensor>(TensorSpec("tensor(x{})") + EXPECT_EQUAL(*makeTensor<Value>(TensorSpec("tensor(x{})") .add({{"x", "b"}}, 5) .add({{"x", "c"}}, 7) .add({{"x", "a"}}, 3)), f.execute()); @@ -173,7 +172,7 @@ TEST_F("require that tensor attribute can be extracted as tensor in attribute fe TEST_F("require that direct tensor attribute can be extracted in attribute feature", ExecFixture("attribute(directattr)")) { - EXPECT_EQUAL(*makeTensor<Tensor>(TensorSpec("tensor(x{})") + EXPECT_EQUAL(*makeTensor<Value>(TensorSpec("tensor(x{})") .add({{"x", "b"}}, 5) .add({{"x", "c"}}, 7) .add({{"x", "a"}}, 3)), f.execute()); @@ -182,7 +181,7 @@ TEST_F("require that direct tensor attribute can be extracted in attribute featu TEST_F("require that tensor from query can be extracted as tensor in query feature", ExecFixture("query(tensorquery)")) { - EXPECT_EQUAL(*makeTensor<Tensor>(TensorSpec("tensor(q{})") + EXPECT_EQUAL(*makeTensor<Value>(TensorSpec("tensor(q{})") .add({{"q", "f"}}, 17) .add({{"q", "d"}}, 11) .add({{"q", "e"}}, 13)), f.execute()); @@ -218,7 +217,7 @@ TEST_F("require that empty tensor with correct type is returned by direct tensor TEST_F("require that wrong tensor type from query tensor gives empty tensor", ExecFixture("query(mappedtensorquery)")) { - EXPECT_EQUAL(*makeTensor<Tensor>(TensorSpec("tensor(x[2])") + EXPECT_EQUAL(*makeTensor<Value>(TensorSpec("tensor(x[2])") .add({{"x", 0}}, 0) .add({{"x", 1}}, 0)), f.execute()); } diff --git a/searchlib/src/tests/features/tensor_from_labels/tensor_from_labels_test.cpp b/searchlib/src/tests/features/tensor_from_labels/tensor_from_labels_test.cpp index d2fc79f8fa2..6b43f97354f 100644 --- a/searchlib/src/tests/features/tensor_from_labels/tensor_from_labels_test.cpp +++ b/searchlib/src/tests/features/tensor_from_labels/tensor_from_labels_test.cpp @@ -12,9 +12,10 @@ #include <vespa/searchlib/fef/test/indexenvironment.h> #include <vespa/searchlib/fef/test/indexenvironmentbuilder.h> #include <vespa/searchlib/fef/test/queryenvironment.h> +#include <vespa/eval/eval/engine_or_factory.h> #include <vespa/eval/eval/function.h> -#include <vespa/eval/tensor/tensor.h> -#include <vespa/eval/tensor/default_tensor_engine.h> +#include <vespa/eval/eval/value.h> +#include <vespa/eval/eval/test/value_compare.h> using search::feature_t; using namespace search::fef; @@ -26,8 +27,7 @@ using search::StringAttribute; using vespalib::eval::Value; using vespalib::eval::Function; using vespalib::eval::TensorSpec; -using vespalib::tensor::DefaultTensorEngine; -using vespalib::tensor::Tensor; +using vespalib::eval::EngineOrFactory; typedef search::attribute::Config AVC; typedef search::attribute::BasicType AVBT; @@ -35,12 +35,12 @@ typedef search::attribute::CollectionType AVCT; typedef search::AttributeVector::SP AttributePtr; typedef FtTestApp FTA; -Tensor::UP make_tensor(const TensorSpec &spec) { - auto tensor = DefaultTensorEngine::ref().from_spec(spec); - return Tensor::UP(dynamic_cast<Tensor*>(tensor.release())); +Value::UP make_tensor(const TensorSpec &spec) { + auto tensor = EngineOrFactory::get().from_spec(spec); + return tensor; } -Tensor::UP make_empty(const vespalib::string &type) { +Value::UP make_empty(const vespalib::string &type) { return make_tensor(TensorSpec(type)); } @@ -121,12 +121,12 @@ struct ExecFixture test.getQueryEnv().getProperties().add("astr_query", "[d e f e]"); test.getQueryEnv().getProperties().add("aint_query", "[11 13 17]"); } - const Tensor &extractTensor(uint32_t docid) { + const Value &extractTensor(uint32_t docid) { Value::CREF value = test.resolveObjectFeature(docid); ASSERT_TRUE(value.get().is_tensor()); - return static_cast<const Tensor &>(*value.get().as_tensor()); + return value.get(); } - const Tensor &execute() { + const Value &execute() { return extractTensor(1); } }; diff --git a/searchlib/src/tests/features/tensor_from_weighted_set/tensor_from_weighted_set_test.cpp b/searchlib/src/tests/features/tensor_from_weighted_set/tensor_from_weighted_set_test.cpp index e0eee954a53..40a5b8a8cc7 100644 --- a/searchlib/src/tests/features/tensor_from_weighted_set/tensor_from_weighted_set_test.cpp +++ b/searchlib/src/tests/features/tensor_from_weighted_set/tensor_from_weighted_set_test.cpp @@ -12,10 +12,11 @@ #include <vespa/searchlib/fef/test/indexenvironment.h> #include <vespa/searchlib/fef/test/indexenvironmentbuilder.h> #include <vespa/searchlib/fef/test/queryenvironment.h> +#include <vespa/eval/eval/engine_or_factory.h> #include <vespa/eval/eval/function.h> #include <vespa/eval/eval/tensor_spec.h> -#include <vespa/eval/tensor/default_tensor_engine.h> -#include <vespa/eval/tensor/tensor.h> +#include <vespa/eval/eval/value.h> +#include <vespa/eval/eval/test/value_compare.h> using search::feature_t; using namespace search::fef; @@ -27,8 +28,7 @@ using search::StringAttribute; using vespalib::eval::Value; using vespalib::eval::Function; using vespalib::eval::TensorSpec; -using vespalib::tensor::Tensor; -using vespalib::tensor::DefaultTensorEngine; +using vespalib::eval::EngineOrFactory; typedef search::attribute::Config AVC; typedef search::attribute::BasicType AVBT; @@ -36,12 +36,12 @@ typedef search::attribute::CollectionType AVCT; typedef search::AttributeVector::SP AttributePtr; typedef FtTestApp FTA; -Tensor::UP make_tensor(const TensorSpec &spec) { - auto tensor = DefaultTensorEngine::ref().from_spec(spec); - return Tensor::UP(dynamic_cast<Tensor*>(tensor.release())); +Value::UP make_tensor(const TensorSpec &spec) { + auto tensor = EngineOrFactory::get().from_spec(spec); + return tensor; } -Tensor::UP make_empty(const vespalib::string &type) { +Value::UP make_empty(const vespalib::string &type) { return make_tensor(TensorSpec(type)); } @@ -120,12 +120,12 @@ struct ExecFixture void setupQueryEnvironment() { test.getQueryEnv().getProperties().add("wsquery", "{d:11,e:13,f:17}"); } - const Tensor &extractTensor(uint32_t docid) { + const Value &extractTensor(uint32_t docid) { Value::CREF value = test.resolveObjectFeature(docid); ASSERT_TRUE(value.get().is_tensor()); - return static_cast<const Tensor &>(*value.get().as_tensor()); + return value.get(); } - const Tensor &execute() { + const Value &execute() { return extractTensor(1); } }; |