diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-11-27 12:38:34 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-11-27 12:45:30 +0000 |
commit | d6a3e072a0bcfe7999e8369f61287930a3bf1bb0 (patch) | |
tree | 4a571da213dad3305b2ec8fde160541dffabef70 /searchlib/src/tests/features | |
parent | 5f7755b688fedbec191a06ce3c4c3d6cfb685c14 (diff) |
avoid using vespalib::tensor directly
* do not construct DenseTensor instances directly
* instead, use TensorSpec::from_expr to make a spec
* and factory.from_spec() to make a value
* also, use value codec directly to encode a value
Diffstat (limited to 'searchlib/src/tests/features')
-rw-r--r-- | searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
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 3a755704c0d..ec6aa65c6c2 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 @@ -7,8 +7,8 @@ #include <vespa/searchlib/fef/test/rankresult.h> #include <vespa/searchlib/fef/test/dummy_dependency_handler.h> #include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/vespalib/objects/nbostream.h> -#include <vespa/eval/tensor/dense/dense_tensor.h> using namespace search; using namespace search::attribute; @@ -17,6 +17,8 @@ using namespace search::fef; using namespace search::fef::test; using namespace search::index; +using vespalib::eval::TensorSpec; + template <typename T> std::unique_ptr<fef::Anything> create_param(const vespalib::string& param) { Properties props; @@ -109,12 +111,18 @@ struct ArrayFixture : FixtureBase { template <typename ExpectedType> void check_prepare_state_output(const vespalib::eval::Value & tensor, const ExpectedType & expected) { vespalib::nbostream os; - vespalib::eval::EngineOrFactory::get().encode(tensor, os); + encode_value(tensor, os); vespalib::string input_vector(os.data(), os.size()); check_prepare_state_output(".tensor", input_vector, expected); } template <typename ExpectedType> + void check_prepare_state_output(const TensorSpec & spec, const ExpectedType & expected) { + auto value = vespalib::eval::EngineOrFactory::get().from_spec(spec); + check_prepare_state_output(*value, expected); + } + + template <typename ExpectedType> void check_prepare_state_output(const vespalib::string& input_vector, const ExpectedType & expected) { check_prepare_state_output("", input_vector, expected); } @@ -196,25 +204,25 @@ TEST_F("prepareSharedState emits double vector for double imported attribute", A TEST_F("prepareSharedState handles tensor as float from tensor for double imported attribute", ArrayFixture) { f.setup_float_mappings(BasicType::DOUBLE); - vespalib::tensor::DenseTensor<float> tensor(vespalib::eval::ValueType::from_spec("tensor<float>(x[3])"), {10.1, 20.2, 30.3}); + auto tensor = TensorSpec::from_expr("tensor<float>(x[3]):[10.1,20.2,30.3]"); f.template check_prepare_state_output(tensor, dotproduct::ArrayParam<double>({10.1, 20.2, 30.3})); } TEST_F("prepareSharedState handles tensor as double from tensor for double imported attribute", ArrayFixture) { f.setup_float_mappings(BasicType::DOUBLE); - vespalib::tensor::DenseTensor<double> tensor(vespalib::eval::ValueType::from_spec("tensor(x[3])"), {10.1, 20.2, 30.3}); + auto tensor = TensorSpec::from_expr("tensor(x[3]):[10.1,20.2,30.3]"); f.template check_prepare_state_output(tensor, dotproduct::ArrayParam<double>({10.1, 20.2, 30.3})); } TEST_F("prepareSharedState handles tensor as float from tensor for float imported attribute", ArrayFixture) { f.setup_float_mappings(BasicType::FLOAT); - vespalib::tensor::DenseTensor<float> tensor(vespalib::eval::ValueType::from_spec("tensor<float>(x[3])"), {10.1, 20.2, 30.3}); + auto tensor = TensorSpec::from_expr("tensor<float>(x[3]):[10.1,20.2,30.3]"); f.template check_prepare_state_output(tensor, dotproduct::ArrayParam<float>({10.1, 20.2, 30.3})); } TEST_F("prepareSharedState handles tensor as double from tensor for float imported attribute", ArrayFixture) { f.setup_float_mappings(BasicType::FLOAT); - vespalib::tensor::DenseTensor<double> tensor(vespalib::eval::ValueType::from_spec("tensor(x[3])"), {10.1, 20.2, 30.3}); + auto tensor = TensorSpec::from_expr("tensor(x[3]):[10.1,20.2,30.3]"); f.template check_prepare_state_output(tensor, dotproduct::ArrayParam<float>({10.1, 20.2, 30.3})); } |