diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2019-02-11 14:07:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-11 14:07:29 +0100 |
commit | 9275afcec94bc3b04b6c19d6a391704abdccf5b5 (patch) | |
tree | 7e804f474677607604e5f0df4f554bb1a15c56b8 | |
parent | d45993e8308b0b9cb586024923878af51c98a688 (diff) | |
parent | 23b35659dcc409e93d34aaf0e81e3ebbe78f6c21 (diff) |
Merge pull request #8467 from vespa-engine/geirst/integrate-tensor-add-update
Geirst/integrate tensor add update
11 files changed, 48 insertions, 23 deletions
diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index 32d23349dc0..5100e3683e5 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -12,8 +12,8 @@ #include <vespa/document/update/fieldupdate.h> #include <vespa/document/update/mapvalueupdate.h> #include <vespa/document/update/removevalueupdate.h> -#include <vespa/document/update/tensoraddupdate.h> -#include <vespa/document/update/tensormodifyupdate.h> +#include <vespa/document/update/tensor_add_update.h> +#include <vespa/document/update/tensor_modify_update.h> #include <vespa/document/update/valueupdate.h> #include <vespa/document/serialization/vespadocumentserializer.h> #include <vespa/document/util/bytebuffer.h> diff --git a/document/src/vespa/document/update/CMakeLists.txt b/document/src/vespa/document/update/CMakeLists.txt index 34f539ee4aa..2ece7877bdb 100644 --- a/document/src/vespa/document/update/CMakeLists.txt +++ b/document/src/vespa/document/update/CMakeLists.txt @@ -13,8 +13,8 @@ vespa_add_library(document_updates OBJECT mapvalueupdate.cpp removefieldpathupdate.cpp removevalueupdate.cpp - tensoraddupdate.cpp - tensormodifyupdate.cpp + tensor_add_update.cpp + tensor_modify_update.cpp valueupdate.cpp DEPENDS AFTER diff --git a/document/src/vespa/document/update/tensoraddupdate.cpp b/document/src/vespa/document/update/tensor_add_update.cpp index 714eee28ff3..6d251b04937 100644 --- a/document/src/vespa/document/update/tensoraddupdate.cpp +++ b/document/src/vespa/document/update/tensor_add_update.cpp @@ -1,6 +1,6 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "tensoraddupdate.h" +#include "tensor_add_update.h" #include <vespa/document/base/exceptions.h> #include <vespa/document/base/field.h> #include <vespa/document/fieldvalue/document.h> diff --git a/document/src/vespa/document/update/tensoraddupdate.h b/document/src/vespa/document/update/tensor_add_update.h index a92ff0101f0..a92ff0101f0 100644 --- a/document/src/vespa/document/update/tensoraddupdate.h +++ b/document/src/vespa/document/update/tensor_add_update.h diff --git a/document/src/vespa/document/update/tensormodifyupdate.cpp b/document/src/vespa/document/update/tensor_modify_update.cpp index 8cee367cae0..bb846581697 100644 --- a/document/src/vespa/document/update/tensormodifyupdate.cpp +++ b/document/src/vespa/document/update/tensor_modify_update.cpp @@ -1,6 +1,6 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "tensormodifyupdate.h" +#include "tensor_modify_update.h" #include <vespa/document/base/exceptions.h> #include <vespa/document/base/field.h> #include <vespa/document/fieldvalue/document.h> diff --git a/document/src/vespa/document/update/tensormodifyupdate.h b/document/src/vespa/document/update/tensor_modify_update.h index dcb9bcf0470..dcb9bcf0470 100644 --- a/document/src/vespa/document/update/tensormodifyupdate.h +++ b/document/src/vespa/document/update/tensor_modify_update.h diff --git a/document/src/vespa/document/update/updates.h b/document/src/vespa/document/update/updates.h index 1609c5bc3a3..4e520e61690 100644 --- a/document/src/vespa/document/update/updates.h +++ b/document/src/vespa/document/update/updates.h @@ -10,6 +10,6 @@ #include "clearvalueupdate.h" #include "mapvalueupdate.h" #include "removevalueupdate.h" -#include "tensormodifyupdate.h" -#include "tensoraddupdate.h" +#include "tensor_add_update.h" +#include "tensor_modify_update.h" diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateAdapter.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateAdapter.java index 0e3970db7fa..6c894dcdf4c 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateAdapter.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateAdapter.java @@ -139,6 +139,8 @@ public class FieldUpdateAdapter implements UpdateAdapter { } } else if (upd instanceof TensorModifyUpdate) { lst.add(upd); + } else if (upd instanceof TensorAddUpdate) { + lst.add(upd); } else { throw new UnsupportedOperationException( "Value update type " + upd.getClass().getName() + " not supported."); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateHelper.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateHelper.java index 61e38bd8bc6..40a3f832592 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateHelper.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateHelper.java @@ -91,7 +91,10 @@ public abstract class FieldUpdateHelper { throw new IllegalArgumentException("Expected multi-value data type, got " + val.getDataType().getName() + "."); } } else if (upd instanceof TensorModifyUpdate) { - // TODO: apply update to field value when supported in TensorModifyUpdate in Java. + // TODO: apply update to field value when supported in TensorModifyUpdate in Java? + return val; + } else if (upd instanceof TensorAddUpdate) { + // TODO: apply update to field value when supported in TensorAddUpdate in Java? return val; } throw new UnsupportedOperationException("Value update type " + upd.getClass().getName() + " not supported."); 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 1620daa67c2..c1e63a15653 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 @@ -17,7 +17,8 @@ #include <vespa/document/update/documentupdate.h> #include <vespa/document/update/mapvalueupdate.h> #include <vespa/document/update/removevalueupdate.h> -#include <vespa/document/update/tensormodifyupdate.h> +#include <vespa/document/update/tensor_add_update.h> +#include <vespa/document/update/tensor_modify_update.h> #include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/eval/tensor/tensor.h> #include <vespa/searchcore/proton/common/attribute_updater.h> @@ -25,6 +26,7 @@ #include <vespa/searchlib/attribute/attributevector.hpp> #include <vespa/searchlib/attribute/reference_attribute.h> #include <vespa/searchlib/tensor/dense_tensor_attribute.h> +#include <vespa/searchlib/tensor/generic_tensor_attribute.h> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/log/log.h> @@ -42,6 +44,8 @@ using search::attribute::Reference; using search::attribute::ReferenceAttribute; using search::tensor::ITensorAttribute; using search::tensor::DenseTensorAttribute; +using search::tensor::GenericTensorAttribute; +using search::tensor::TensorAttribute; using vespalib::eval::ValueType; using vespalib::eval::TensorSpec; using vespalib::tensor::DefaultTensorEngine; @@ -373,12 +377,13 @@ TEST_F("require that weighted set attributes are updated", Fixture) } } -std::unique_ptr<DenseTensorAttribute> -makeDenseTensorAttribute(const vespalib::string &name, const vespalib::string &tensorType) +template <typename TensorAttributeType> +std::unique_ptr<TensorAttributeType> +makeTensorAttribute(const vespalib::string &name, const vespalib::string &tensorType) { Config cfg(BasicType::TENSOR, CollectionType::SINGLE); cfg.setTensorType(ValueType::from_spec(tensorType)); - auto result = std::make_unique<DenseTensorAttribute>(name, cfg); + auto result = std::make_unique<TensorAttributeType>(name, cfg); result->addReservedDoc(); result->addDocs(1); return result; @@ -400,7 +405,7 @@ makeTensorFieldValue(const TensorSpec &spec) } void -setTensor(DenseTensorAttribute &attribute, uint32_t lid, const TensorSpec &spec) +setTensor(TensorAttribute &attribute, uint32_t lid, const TensorSpec &spec) { auto tensor = makeTensor(spec); attribute.setTensor(lid, *tensor); @@ -410,13 +415,24 @@ setTensor(DenseTensorAttribute &attribute, uint32_t lid, const TensorSpec &spec) TEST_F("require that tensor modify update is applied", Fixture) { vespalib::string type = "tensor(x[2])"; - auto attribute = makeDenseTensorAttribute("dense_tensor", type); + auto attribute = makeTensorAttribute<DenseTensorAttribute>("dense_tensor", type); setTensor(*attribute, 1, TensorSpec(type).add({{"x", 0}}, 3).add({{"x", 1}}, 5)); - TensorModifyUpdate update(TensorModifyUpdate::Operation::REPLACE, - makeTensorFieldValue(TensorSpec("tensor(x{})").add({{"x",0}}, 7))); - f.applyValueUpdate(*attribute, 1, update); - EXPECT_EQUAL(TensorSpec(type).add({{"x",0}}, 7).add({{"x", 1}}, 5), attribute->getTensor(1)->toSpec()); + f.applyValueUpdate(*attribute, 1, + TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE, + makeTensorFieldValue(TensorSpec("tensor(x{})").add({{"x", 0}}, 7)))); + EXPECT_EQUAL(TensorSpec(type).add({{"x", 0}}, 7).add({{"x", 1}}, 5), attribute->getTensor(1)->toSpec()); +} + +TEST_F("require that tensor add update is applied", Fixture) +{ + vespalib::string type = "tensor(x{})"; + auto attribute = makeTensorAttribute<GenericTensorAttribute>("dense_tensor", type); + setTensor(*attribute, 1, TensorSpec(type).add({{"x", "a"}}, 2)); + + f.applyValueUpdate(*attribute, 1, + TensorAddUpdate(makeTensorFieldValue(TensorSpec(type).add({{"x", "a"}}, 3)))); + EXPECT_EQUAL(TensorSpec(type).add({{"x", "a"}}, 3), attribute->getTensor(1)->toSpec()); } } diff --git a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp index 3ad838c595b..933857cffed 100644 --- a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "attribute_updater.h" -#include <vespa/eval/tensor/tensor.h> #include <vespa/document/base/forcelink.h> #include <vespa/document/fieldvalue/arrayfieldvalue.h> #include <vespa/document/fieldvalue/literalfieldvalue.h> @@ -15,7 +14,9 @@ #include <vespa/document/update/clearvalueupdate.h> #include <vespa/document/update/mapvalueupdate.h> #include <vespa/document/update/removevalueupdate.h> -#include <vespa/document/update/tensormodifyupdate.h> +#include <vespa/document/update/tensor_add_update.h> +#include <vespa/document/update/tensor_modify_update.h> +#include <vespa/eval/tensor/tensor.h> #include <vespa/searchlib/attribute/attributevector.hpp> #include <vespa/searchlib/attribute/changevector.hpp> #include <vespa/searchlib/attribute/predicate_attribute.h> @@ -205,8 +206,9 @@ AttributeUpdater::handleUpdate(PredicateAttribute &vec, uint32_t lid, const Valu namespace { +template <typename TensorUpdateType> void -applyTensorModifyUpdate(TensorAttribute &vec, uint32_t lid, const TensorModifyUpdate &update) +applyTensorUpdate(TensorAttribute &vec, uint32_t lid, const TensorUpdateType &update) { auto oldTensor = vec.getTensor(lid); if (oldTensor) { @@ -233,7 +235,9 @@ AttributeUpdater::handleUpdate(TensorAttribute &vec, uint32_t lid, const ValueUp updateValue(vec, lid, assign.getValue()); } } else if (op == ValueUpdate::TensorModifyUpdate) { - applyTensorModifyUpdate(vec, lid, static_cast<const TensorModifyUpdate &>(upd)); + applyTensorUpdate(vec, lid, static_cast<const TensorModifyUpdate &>(upd)); + } else if (op == ValueUpdate::TensorAddUpdate) { + applyTensorUpdate(vec, lid, static_cast<const TensorAddUpdate &>(upd)); } else if (op == ValueUpdate::Clear) { vec.clearDoc(lid); } else { |