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 /searchcore | |
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 'searchcore')
16 files changed, 97 insertions, 83 deletions
diff --git a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp index 533e8881d27..bea93f82c2d 100644 --- a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp +++ b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp @@ -11,6 +11,7 @@ #include <vespa/config/common/exceptions.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value_cache/constant_value.h> +#include <vespa/eval/eval/engine_or_factory.h> #include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/searchcommon/common/schemaconfigurer.h> #include <vespa/searchcore/config/config-ranking-constants.h> @@ -39,12 +40,13 @@ using vespa::config::search::RankProfilesConfig; using vespa::config::search::core::RankingConstantsConfig; using vespa::config::search::core::OnnxModelsConfig; using vespa::config::search::core::VerifyRanksetupConfig; +using vespalib::eval::BadConstantValue; using vespalib::eval::ConstantValue; +using vespalib::eval::EngineOrFactory; +using vespalib::eval::SimpleConstantValue; using vespalib::eval::TensorSpec; +using vespalib::eval::Value; using vespalib::eval::ValueType; -using vespalib::tensor::DefaultTensorEngine; -using vespalib::eval::SimpleConstantValue; -using vespalib::eval::BadConstantValue; std::optional<vespalib::string> get_file(const vespalib::string &ref, const VerifyRanksetupConfig &myCfg) { for (const auto &entry: myCfg.file) { @@ -94,9 +96,8 @@ struct DummyConstantValueRepo : IConstantValueRepo { virtual vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &name) const override { for (const auto &entry: cfg.constant) { if (entry.name == name) { - const auto &engine = DefaultTensorEngine::ref(); try { - auto tensor = engine.from_spec(TensorSpec(entry.type)); + auto tensor = EngineOrFactory::get().from_spec(TensorSpec(entry.type)); return std::make_unique<SimpleConstantValue>(std::move(tensor)); } catch (std::exception &) { return std::make_unique<BadConstantValue>(); diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp index a647085e3d1..00153402fc9 100644 --- a/searchcore/src/tests/proton/attribute/attribute_test.cpp +++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp @@ -7,8 +7,9 @@ #include <vespa/document/update/arithmeticvalueupdate.h> #include <vespa/document/update/assignvalueupdate.h> #include <vespa/document/update/documentupdate.h> -#include <vespa/eval/tensor/default_tensor_engine.h> -#include <vespa/eval/tensor/tensor.h> +#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/value.h> +#include <vespa/eval/eval/test/value_compare.h> #include <vespa/searchcommon/attribute/attributecontent.h> #include <vespa/searchcommon/attribute/iattributevector.h> #include <vespa/searchcore/proton/attribute/attribute_collection_spec_factory.h> @@ -81,10 +82,10 @@ using std::string; using vespalib::ForegroundTaskExecutor; using vespalib::ForegroundThreadExecutor; using vespalib::SequencedTaskExecutorObserver; +using vespalib::eval::EngineOrFactory; using vespalib::eval::TensorSpec; +using vespalib::eval::Value; using vespalib::eval::ValueType; -using vespalib::tensor::DefaultTensorEngine; -using vespalib::tensor::Tensor; using AVBasicType = search::attribute::BasicType; using AVCollectionType = search::attribute::CollectionType; @@ -639,9 +640,9 @@ TEST_F(FilterAttributeManagerTest, readable_attribute_vector_filters_attributes) 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) { + auto tensor = EngineOrFactory::get().from_spec(spec); + return tensor; } const vespalib::string sparse_tensor = "tensor(x{},y{})"; @@ -662,10 +663,10 @@ createTensorSchema(const vespalib::string& tensor_spec = sparse_tensor) { } Document::UP -createTensorPutDoc(DocBuilder &builder, const Tensor &tensor) { +createTensorPutDoc(DocBuilder &builder, const Value &tensor) { return builder.startDocument("id:ns:searchdocument::1"). startAttributeField("a1"). - addTensor(tensor.clone()).endField().endDocument(); + addTensor(EngineOrFactory::get().copy(tensor)).endField().endDocument(); } } @@ -684,7 +685,7 @@ TEST_F(AttributeWriterTest, can_write_to_tensor_attribute) EXPECT_TRUE(tensorAttribute != nullptr); auto tensor2 = tensorAttribute->getTensor(1); EXPECT_TRUE(static_cast<bool>(tensor2)); - EXPECT_TRUE(tensor->equals(*tensor2)); + EXPECT_EQ(*tensor, *tensor2); } TEST_F(AttributeWriterTest, handles_tensor_assign_update) @@ -701,7 +702,7 @@ TEST_F(AttributeWriterTest, handles_tensor_assign_update) EXPECT_TRUE(tensorAttribute != nullptr); auto tensor2 = tensorAttribute->getTensor(1); EXPECT_TRUE(static_cast<bool>(tensor2)); - EXPECT_TRUE(tensor->equals(*tensor2)); + EXPECT_EQ(*tensor, *tensor2); const document::DocumentType &dt(builder.getDocumentType()); DocumentUpdate upd(*builder.getDocumentTypeRepo(), dt, DocumentId("id:ns:searchdocument::1")); @@ -709,7 +710,7 @@ TEST_F(AttributeWriterTest, handles_tensor_assign_update) .add({{"x", "8"}, {"y", "9"}}, 11)); TensorDataType xySparseTensorDataType(vespalib::eval::ValueType::from_spec(sparse_tensor)); TensorFieldValue new_value(xySparseTensorDataType); - new_value = new_tensor->clone(); + new_value = EngineOrFactory::get().copy(*new_tensor); upd.addUpdate(FieldUpdate(upd.getType().getField("a1")) .addUpdate(AssignValueUpdate(new_value))); bool immediateCommit = true; @@ -719,8 +720,8 @@ TEST_F(AttributeWriterTest, handles_tensor_assign_update) EXPECT_TRUE(tensorAttribute != nullptr); tensor2 = tensorAttribute->getTensor(1); EXPECT_TRUE(static_cast<bool>(tensor2)); - EXPECT_TRUE(!tensor->equals(*tensor2)); - EXPECT_TRUE(new_tensor->equals(*tensor2)); + EXPECT_FALSE(*tensor == *tensor2); + EXPECT_EQ(*new_tensor, *tensor2); } namespace { @@ -792,8 +793,8 @@ TEST_F(AttributeWriterTest, spreads_write_over_3_write_contexts) struct MockPrepareResult : public PrepareResult { uint32_t docid; - const Tensor& tensor; - MockPrepareResult(uint32_t docid_in, const Tensor& tensor_in) : docid(docid_in), tensor(tensor_in) {} + const Value& tensor; + MockPrepareResult(uint32_t docid_in, const Value& tensor_in) : docid(docid_in), tensor(tensor_in) {} }; class MockDenseTensorAttribute : public DenseTensorAttribute { @@ -812,12 +813,12 @@ public: ++clear_doc_cnt; return DenseTensorAttribute::clearDoc(docid); } - std::unique_ptr<PrepareResult> prepare_set_tensor(uint32_t docid, const Tensor& tensor) const override { + std::unique_ptr<PrepareResult> prepare_set_tensor(uint32_t docid, const Value& tensor) const override { ++prepare_set_tensor_cnt; return std::make_unique<MockPrepareResult>(docid, tensor); } - void complete_set_tensor(DocId docid, const Tensor& tensor, std::unique_ptr<PrepareResult> prepare_result) override { + void complete_set_tensor(DocId docid, const Value& tensor, std::unique_ptr<PrepareResult> prepare_result) override { ++complete_set_tensor_cnt; assert(prepare_result); auto* mock_result = dynamic_cast<MockPrepareResult*>(prepare_result.get()); @@ -872,7 +873,7 @@ public: Schema schema; DocBuilder builder; std::shared_ptr<MockDenseTensorAttribute> attr; - std::unique_ptr<Tensor> tensor; + std::unique_ptr<Value> tensor; TwoPhasePutTest() : AttributeWriterTest(), @@ -904,7 +905,7 @@ public: Document::UP make_no_tensor_doc() { return builder.startDocument("id:ns:searchdocument::1"). startAttributeField("a1"). - addTensor(std::unique_ptr<vespalib::tensor::Tensor>()).endField().endDocument(); + addTensor(std::unique_ptr<vespalib::eval::Value>()).endField().endDocument(); } void expect_shared_executor_tasks(size_t exp_accepted_tasks) { auto stats = _shared.getStats(); diff --git a/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp b/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp index 59c046dee46..61b5f9cb847 100644 --- a/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp +++ b/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp @@ -22,8 +22,8 @@ #include <vespa/document/update/tensor_add_update.h> #include <vespa/document/update/tensor_modify_update.h> #include <vespa/document/update/tensor_remove_update.h> -#include <vespa/eval/tensor/default_tensor_engine.h> -#include <vespa/eval/tensor/tensor.h> +#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/value.h> #include <vespa/searchcore/proton/common/attribute_updater.h> #include <vespa/searchlib/attribute/attributefactory.h> #include <vespa/searchlib/attribute/reference_attribute.h> @@ -50,10 +50,10 @@ using search::tensor::ITensorAttribute; using search::tensor::DenseTensorAttribute; using search::tensor::SerializedTensorAttribute; using search::tensor::TensorAttribute; +using vespalib::eval::EngineOrFactory; +using vespalib::eval::Value; using vespalib::eval::ValueType; using vespalib::eval::TensorSpec; -using vespalib::tensor::DefaultTensorEngine; -using vespalib::tensor::Tensor; namespace search { @@ -408,11 +408,11 @@ getTensorDataType(const vespalib::string &spec) return *insres.first->second; } -std::unique_ptr<Tensor> +std::unique_ptr<Value> makeTensor(const TensorSpec &spec) { - auto result = DefaultTensorEngine::ref().from_spec(spec); - return std::unique_ptr<Tensor>(dynamic_cast<Tensor*>(result.release())); + auto result = EngineOrFactory::get().from_spec(spec); + return result; } std::unique_ptr<TensorFieldValue> @@ -442,7 +442,9 @@ struct TensorFixture : public Fixture { } void assertTensor(const TensorSpec &expSpec) { - EXPECT_EQUAL(expSpec, attribute->getTensor(1)->toSpec()); + auto engine = EngineOrFactory::get(); + auto actual = engine.to_spec(*attribute->getTensor(1)); + EXPECT_EQUAL(expSpec, actual); } }; diff --git a/searchcore/src/tests/proton/docsummary/docsummary.cpp b/searchcore/src/tests/proton/docsummary/docsummary.cpp index 07f023982c9..7e220cd0165 100644 --- a/searchcore/src/tests/proton/docsummary/docsummary.cpp +++ b/searchcore/src/tests/proton/docsummary/docsummary.cpp @@ -2,9 +2,9 @@ #include <tests/proton/common/dummydbowner.h> #include <vespa/config/helper/configgetter.hpp> -#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/engine_or_factory.h> +#include <vespa/eval/eval/value.h> +#include <vespa/eval/eval/test/value_compare.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/test/make_bucket_space.h> #include <vespa/searchcore/proton/attribute/attribute_writer.h> @@ -59,8 +59,7 @@ using storage::spi::Timestamp; using vespa::config::search::core::ProtonConfig; using vespa::config::content::core::BucketspacesConfig; using vespalib::eval::TensorSpec; -using vespalib::tensor::Tensor; -using vespalib::tensor::DefaultTensorEngine; +using vespalib::eval::EngineOrFactory; using namespace vespalib::slime; typedef std::unique_ptr<GeneralResult> GeneralResultPtr; @@ -139,9 +138,9 @@ getDocTypeName() return "searchdocument"; } -Tensor::UP make_tensor(const TensorSpec &spec) { - auto tensor = DefaultTensorEngine::ref().from_spec(spec); - return Tensor::UP(dynamic_cast<Tensor*>(tensor.release())); +vespalib::eval::Value::UP make_tensor(const TensorSpec &spec) { + auto tensor = EngineOrFactory::get().from_spec(spec); + return tensor; } vespalib::string asVstring(vespalib::Memory str) { @@ -316,7 +315,7 @@ assertString(const std::string & exp, const std::string & fieldName, } void -assertTensor(const Tensor::UP & exp, const std::string & fieldName, +assertTensor(const vespalib::eval::Value::UP & exp, const std::string & fieldName, const DocsumReply & reply, uint32_t id, uint32_t) { const DocsumReply::Docsum & docsum = reply.docsums[id]; @@ -335,7 +334,7 @@ assertTensor(const Tensor::UP & exp, const std::string & fieldName, EXPECT_EQUAL(exp.get() == nullptr, data.size == 0u); if (exp) { vespalib::nbostream x(data.data, data.size); - Tensor::UP tensor = vespalib::tensor::TypedBinaryFormat::deserialize(x); + vespalib::eval::Value::UP tensor = EngineOrFactory::get().decode(x); EXPECT_TRUE(tensor.get() != nullptr); EXPECT_EQUAL(*exp, *tensor); } @@ -741,7 +740,7 @@ TEST("requireThatAttributesAreUsed") // empty doc EXPECT_TRUE(assertSlime("{}", *rep, 1, false)); - TEST_DO(assertTensor(Tensor::UP(), "bj", *rep, 1, rclass)); + TEST_DO(assertTensor(vespalib::eval::Value::UP(), "bj", *rep, 1, rclass)); proton::IAttributeManager::SP attributeManager = dc._ddb->getReadySubDB()->getAttributeManager(); vespalib::ISequencedTaskExecutor &attributeFieldWriter = attributeManager->getAttributeFieldWriter(); diff --git a/searchcore/src/tests/proton/docsummary/summaryfieldconverter_test.cpp b/searchcore/src/tests/proton/docsummary/summaryfieldconverter_test.cpp index 5f8f7a63dd0..6309f96b747 100644 --- a/searchcore/src/tests/proton/docsummary/summaryfieldconverter_test.cpp +++ b/searchcore/src/tests/proton/docsummary/summaryfieldconverter_test.cpp @@ -45,9 +45,10 @@ #include <vespa/vespalib/data/slime/json_format.h> #include <vespa/vespalib/data/slime/binary_format.h> #include <vespa/searchlib/util/slime_output_raw_buf_adapter.h> -#include <vespa/eval/tensor/tensor.h> +#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/value.h> +#include <vespa/eval/eval/test/value_compare.h> #include <vespa/eval/tensor/types.h> -#include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/vespalib/data/slime/slime.h> using document::Annotation; @@ -93,13 +94,13 @@ using search::linguistics::TERM; using vespa::config::search::SummarymapConfig; using vespa::config::search::SummarymapConfigBuilder; using vespalib::Slime; +using vespalib::eval::Value; using vespalib::eval::ValueType; using vespalib::eval::TensorSpec; +using vespalib::eval::EngineOrFactory; using vespalib::geo::ZCurve; using vespalib::slime::Cursor; using vespalib::string; -using vespalib::tensor::Tensor; -using vespalib::tensor::DefaultTensorEngine; using namespace search::docsummary; @@ -165,7 +166,7 @@ class Test : public vespalib::TestApp { void checkString(const string &str, const FieldValue *value); void checkStringForAllConversions(const string& expected, const FieldValue* fv); void checkData(const search::RawBuf &data, const FieldValue *value); - void checkTensor(const Tensor::UP &tensor, const FieldValue *value); + void checkTensor(const Value::UP &tensor, const FieldValue *value); template <unsigned int N> void checkArray(const char *(&str)[N], const FieldValue *value); void setSummaryField(const string &name); @@ -464,7 +465,7 @@ void Test::checkData(const search::RawBuf &buf, const FieldValue *value) { EXPECT_TRUE(memcmp(buf.GetDrainPos(), got.first, got.second) == 0); } -void Test::checkTensor(const Tensor::UP &tensor, const FieldValue *value) { +void Test::checkTensor(const Value::UP &tensor, const FieldValue *value) { ASSERT_TRUE(value); const TensorFieldValue *s = dynamic_cast<const TensorFieldValue *>(value); ASSERT_TRUE(s); @@ -675,9 +676,9 @@ Test::requireThatPredicateIsPrinted() SFC::convertSummaryField(false, *doc.getValue("predicate")).get()); } -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; } void @@ -697,7 +698,7 @@ Test::requireThatTensorIsNotConverted() *doc.getValue("tensor")).get())); doc.setValue("tensor", TensorFieldValue()); - TEST_CALL(checkTensor(Tensor::UP(), + TEST_CALL(checkTensor(Value::UP(), SFC::convertSummaryField(false, *doc.getValue("tensor")).get())); } diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp index 72592cca681..01a35f6017e 100644 --- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp @@ -5,7 +5,7 @@ #include <vespa/document/update/assignvalueupdate.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/update/documentupdate.h> -#include <vespa/eval/tensor/tensor.h> +#include <vespa/eval/eval/value.h> #include <vespa/eval/tensor/test/test_utils.h> #include <vespa/searchcore/proton/bucketdb/bucketdbhandler.h> #include <vespa/searchcore/proton/test/bucketfactory.h> @@ -59,9 +59,9 @@ using vespalib::ThreadStackExecutor; using vespalib::ThreadStackExecutorBase; using vespalib::makeClosure; using vespalib::eval::TensorSpec; +using vespalib::eval::Value; using vespalib::eval::ValueType; using vespalib::tensor::test::makeTensor; -using vespalib::tensor::Tensor; using namespace proton; using namespace search::index; @@ -330,12 +330,12 @@ struct UpdateContext { auto fieldValue = field.createValue(); if (fieldName == "tensor") { dynamic_cast<TensorFieldValue &>(*fieldValue) = - makeTensor<Tensor>(TensorSpec("tensor(x{},y{})"). + makeTensor<Value>(TensorSpec("tensor(x{},y{})"). add({{"x","8"},{"y","9"}}, 11)); } else if (fieldName == "tensor2") { auto tensorFieldValue = std::make_unique<TensorFieldValue>(tensor1DType); *tensorFieldValue = - makeTensor<Tensor>(TensorSpec("tensor(x{})"). + makeTensor<Value>(TensorSpec("tensor(x{})"). add({{"x","8"}}, 11)); fieldValue = std::move(tensorFieldValue); } else { 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 <vespa/searchcore/proton/matching/match_tools.h> #include <vespa/searchcore/proton/matching/match_context.h> #include <vespa/eval/eval/tensor_spec.h> +#include <vespa/eval/eval/engine_or_factory.h> #include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/vespalib/objects/nbostream.h> @@ -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 <vespa/eval/eval/tensor_spec.h> +#include <vespa/eval/eval/engine_or_factory.h> #include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/searchcore/proton/matching/requestcontext.h> #include <vespa/searchlib/attribute/attribute_blueprint_params.h> @@ -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) diff --git a/searchcore/src/tests/proton/server/documentretriever_test.cpp b/searchcore/src/tests/proton/server/documentretriever_test.cpp index 314e1adcc14..b4ae15be17e 100644 --- a/searchcore/src/tests/proton/server/documentretriever_test.cpp +++ b/searchcore/src/tests/proton/server/documentretriever_test.cpp @@ -20,7 +20,9 @@ #include <vespa/document/fieldset/fieldsets.h> #include <vespa/document/repo/configbuilder.h> #include <vespa/document/repo/documenttyperepo.h> -#include <vespa/eval/tensor/tensor.h> +#include <vespa/eval/eval/engine_or_factory.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/persistence/spi/bucket.h> #include <vespa/persistence/spi/test.h> @@ -88,10 +90,11 @@ using storage::spi::Timestamp; using storage::spi::test::makeSpiBucket; using vespalib::make_string; using vespalib::string; +using vespalib::eval::EngineOrFactory; using vespalib::eval::TensorSpec; using vespalib::eval::ValueType; +using vespalib::eval::Value; using vespalib::tensor::test::makeTensor; -using vespalib::tensor::Tensor; using namespace document::config_builder; using namespace search::index; @@ -110,8 +113,8 @@ const char dyn_field_nas[] = "dynamic null attr string field"; // in document, n const char position_field[] = "position_field"; vespalib::string dyn_field_tensor("dynamic_tensor_field"); vespalib::string tensor_spec("tensor(x{})"); -std::unique_ptr<Tensor> static_tensor = makeTensor<Tensor>(TensorSpec(tensor_spec).add({{"x", "1"}}, 1.5)); -std::unique_ptr<Tensor> dynamic_tensor = makeTensor<Tensor>(TensorSpec(tensor_spec).add({{"x", "2"}}, 3.5)); +std::unique_ptr<Value> static_tensor = makeTensor<Value>(TensorSpec(tensor_spec).add({{"x", "1"}}, 1.5)); +std::unique_ptr<Value> dynamic_tensor = makeTensor<Value>(TensorSpec(tensor_spec).add({{"x", "2"}}, 3.5)); const char zcurve_field[] = "position_field_zcurve"; const char position_array_field[] = "position_array"; const char zcurve_array_field[] = "position_array_zcurve"; @@ -167,7 +170,7 @@ struct MyDocumentStore : proton::test::DummyDocumentStore { doc->set(zcurve_field, static_zcurve_value); doc->setValue(dyn_field_p, static_value_p); TensorFieldValue tensorFieldValue(tensorDataType); - tensorFieldValue = static_tensor->clone(); + tensorFieldValue = EngineOrFactory::get().copy(*static_tensor); doc->setValue(dyn_field_tensor, tensorFieldValue); if (_set_position_struct_field) { FieldValue::UP fv = PositionDataType::getInstance().createFieldValue(); @@ -307,7 +310,7 @@ struct Fixture { } attr->commit(); } - void addTensorAttribute(const char *name, const Tensor &val) { + void addTensorAttribute(const char *name, const Value &val) { auto * attr = addAttribute<TensorAttribute>(name, schema::DataType::TENSOR, schema::CollectionType::SINGLE); attr->setTensor(lid, val); attr->commit(); @@ -574,7 +577,7 @@ TEST_F("require that tensor attribute can be retrieved", Fixture) { FieldValue::UP value = doc->getValue(dyn_field_tensor); ASSERT_TRUE(value); auto * tensor_value = dynamic_cast<TensorFieldValue *>(value.get()); - ASSERT_TRUE(tensor_value->getAsTensorPtr()->equals(*dynamic_tensor)); + ASSERT_EQUAL(*tensor_value->getAsTensorPtr(), *dynamic_tensor); } struct Lookup : public IFieldInfo diff --git a/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.cpp b/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.cpp index 358556abce7..c470b7e909c 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.cpp @@ -6,7 +6,7 @@ #include <vespa/document/fieldvalue/tensorfieldvalue.h> #include <vespa/searchcommon/attribute/attributecontent.h> #include <vespa/searchlib/tensor/tensor_attribute.h> -#include <vespa/eval/tensor/tensor.h> +#include <vespa/eval/eval/value.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/log/log.h> diff --git a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp index d7cf6caff28..063ecffe729 100644 --- a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp @@ -17,7 +17,7 @@ #include <vespa/document/update/tensor_add_update.h> #include <vespa/document/update/tensor_modify_update.h> #include <vespa/document/update/tensor_remove_update.h> -#include <vespa/eval/tensor/tensor.h> +#include <vespa/eval/eval/value.h> #include <vespa/searchlib/attribute/attributevector.hpp> #include <vespa/searchlib/attribute/changevector.hpp> #include <vespa/searchlib/attribute/predicate_attribute.h> diff --git a/searchcore/src/vespa/searchcore/proton/docsummary/documentstoreadapter.cpp b/searchcore/src/vespa/searchcore/proton/docsummary/documentstoreadapter.cpp index 0e6ce5e689b..ecca993fa27 100644 --- a/searchcore/src/vespa/searchcore/proton/docsummary/documentstoreadapter.cpp +++ b/searchcore/src/vespa/searchcore/proton/docsummary/documentstoreadapter.cpp @@ -3,8 +3,7 @@ #include "documentstoreadapter.h" #include <vespa/searchsummary/docsummary/summaryfieldconverter.h> #include <vespa/document/fieldvalue/stringfieldvalue.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/document/fieldvalue/tensorfieldvalue.h> @@ -13,7 +12,6 @@ LOG_SETUP(".proton.docsummary.documentstoreadapter"); using namespace document; using namespace search::docsummary; -using vespalib::tensor::Tensor; namespace proton { @@ -88,7 +86,7 @@ DocumentStoreAdapter::writeField(const FieldValue &value, ResType type) const auto &tvalue = static_cast<const TensorFieldValue &>(value); auto tensor = tvalue.getAsTensorPtr(); if (tensor) { - vespalib::tensor::TypedBinaryFormat::serialize(serialized, *tensor); + vespalib::eval::EngineOrFactory::get().encode(*tensor, serialized); } } return _resultPacker.AddSerializedTensor(serialized.peek(), serialized.size()); diff --git a/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp index abd4a9cfbe4..624daaf3cb8 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp @@ -5,6 +5,7 @@ #include "search_session.h" #include <vespa/eval/eval/tensor.h> #include <vespa/eval/eval/tensor_engine.h> +#include <vespa/eval/eval/engine_or_factory.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/searchcommon/attribute/i_search_context.h> #include <vespa/searchlib/queryeval/blueprint.h> @@ -71,9 +72,9 @@ get_feature_set(const MatchToolsFactory &mtf, for (uint32_t j = 0; j < featureNames.size(); ++j) { if (resolver.is_object(j)) { auto obj = resolver.resolve(j).as_object(docId); - if (const auto *tensor = obj.get().as_tensor()) { + if (! obj.get().is_double()) { vespalib::nbostream buf; - tensor->engine().encode(*tensor, buf); + vespalib::eval::EngineOrFactory::get().encode(obj.get(), buf); f[j].set_data(vespalib::Memory(buf.peek(), buf.size())); } else { f[j].set_double(obj.get().as_double()); diff --git a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp index 86afeb5de24..cf8a8d0da06 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "requestcontext.h" +#include <vespa/eval/eval/engine_or_factory.h> #include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/searchlib/attribute/attributevector.h> #include <vespa/searchlib/fef/properties.h> @@ -10,6 +11,8 @@ #include <vespa/log/log.h> LOG_SETUP(".proton.matching.requestcontext"); +using vespalib::eval::EngineOrFactory; + namespace proton { using search::attribute::IAttributeVector; @@ -50,7 +53,7 @@ RequestContext::get_query_tensor(const vespalib::string& tensor_name) const const vespalib::string& value = property.get(); vespalib::nbostream stream(value.data(), value.size()); try { - return vespalib::tensor::DefaultTensorEngine::ref().decode(stream); + return EngineOrFactory::get().decode(stream); } catch (vespalib::IllegalArgumentException& ex) { LOG(warning, "Query tensor '%s' could not be deserialized", tensor_name.c_str()); return vespalib::eval::Value::UP(); diff --git a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h index ada11167983..3c48e40c33c 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h +++ b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h @@ -2,7 +2,7 @@ #pragma once -#include <vespa/eval/tensor/tensor.h> +#include <vespa/eval/eval/value.h> #include <vespa/searchlib/queryeval/irequestcontext.h> #include <vespa/searchcommon/attribute/iattributecontext.h> #include <vespa/searchlib/attribute/attribute_blueprint_params.h> diff --git a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp index 23ab568c767..481fe799f8f 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp @@ -29,6 +29,7 @@ using search::TuneFileDocumentDB; using search::index::Schema; using search::SerialNum; using vespalib::ThreadStackExecutorBase; +using vespalib::eval::EngineOrFactory; using namespace searchcorespi; namespace proton { @@ -40,7 +41,7 @@ SearchableDocSubDB::SearchableDocSubDB(const Config &cfg, const Context &ctx) _indexWriter(), _rSearchView(), _rFeedView(), - _tensorLoader(vespalib::tensor::DefaultTensorEngine::ref()), + _tensorLoader(EngineOrFactory::get()), _constantValueCache(_tensorLoader), _constantValueRepo(_constantValueCache), _configurer(_iSummaryMgr, _rSearchView, _rFeedView, ctx._queryLimiter, _constantValueRepo, ctx._clock, |