diff options
author | Håvard Pettersen <havardpe@oath.com> | 2019-05-27 12:24:06 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2019-05-31 11:49:25 +0000 |
commit | b74a5049bb1bc8b7dce4167f4b639dfb3761c411 (patch) | |
tree | 5b405602554eda05c541e2cce8f01c259f6fa67a /searchcore/src | |
parent | ad59a2b76aa92da991805758dfcb15ad7d9bc0ea (diff) |
remove tensor factory
Diffstat (limited to 'searchcore/src')
3 files changed, 37 insertions, 41 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp index 992a9c56dfb..3734d2fe1dc 100644 --- a/searchcore/src/tests/proton/attribute/attribute_test.cpp +++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp @@ -7,9 +7,8 @@ #include <vespa/document/update/arithmeticvalueupdate.h> #include <vespa/document/update/assignvalueupdate.h> #include <vespa/document/update/documentupdate.h> -#include <vespa/eval/tensor/default_tensor.h> #include <vespa/eval/tensor/tensor.h> -#include <vespa/eval/tensor/tensor_factory.h> +#include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/eval/tensor/types.h> #include <vespa/fastos/file.h> #include <vespa/searchcommon/attribute/attributecontent.h> @@ -75,9 +74,9 @@ using search::tensor::TensorAttribute; using search::test::DirectoryHandler; using std::string; using vespalib::eval::ValueType; +using vespalib::eval::TensorSpec; using vespalib::tensor::Tensor; -using vespalib::tensor::TensorCells; -using vespalib::tensor::TensorDimensions; +using vespalib::tensor::DefaultTensorEngine; using AVConfig = search::attribute::Config; using AVBasicType = search::attribute::BasicType; @@ -612,13 +611,11 @@ TEST_F("require that filter attribute manager can return flushed serial number", namespace { -Tensor::UP -createTensor(const TensorCells &cells, const TensorDimensions &dimensions) { - vespalib::tensor::DefaultTensor::builder builder; - return vespalib::tensor::TensorFactory::create(cells, dimensions, builder); +Tensor::UP make_tensor(const TensorSpec &spec) { + auto tensor = DefaultTensorEngine::ref().from_spec(spec); + return Tensor::UP(dynamic_cast<Tensor*>(tensor.release())); } - AttributeVector::SP createTensorAttribute(Fixture &f) { AVConfig cfg(AVBasicType::TENSOR); @@ -650,8 +647,8 @@ TEST_F("Test that we can use attribute writer to write to tensor attribute", AttributeVector::SP a1 = createTensorAttribute(f); Schema s = createTensorSchema(); DocBuilder builder(s); - auto tensor = createTensor({ {{{"x", "4"}, {"y", "5"}}, 7} }, - {"x", "y"}); + auto tensor = make_tensor(TensorSpec("tensor(x{},y{})") + .add({{"x", "4"}, {"y", "5"}}, 7)); Document::UP doc = createTensorPutDoc(builder, *tensor); f.put(1, *doc, 1); EXPECT_EQUAL(2u, a1->getNumDocs()); @@ -668,8 +665,8 @@ TEST_F("require that attribute writer handles tensor assign update", Fixture) AttributeVector::SP a1 = createTensorAttribute(f); Schema s = createTensorSchema(); DocBuilder builder(s); - auto tensor = createTensor({ {{{"x", "6"}, {"y", "7"}}, 9} }, - {"x", "y"}); + auto tensor = make_tensor(TensorSpec("tensor(x{},y{})") + .add({{"x", "6"}, {"y", "7"}}, 9)); Document::UP doc = createTensorPutDoc(builder, *tensor); f.put(1, *doc, 1); EXPECT_EQUAL(2u, a1->getNumDocs()); @@ -682,8 +679,8 @@ TEST_F("require that attribute writer handles tensor assign update", Fixture) const document::DocumentType &dt(builder.getDocumentType()); DocumentUpdate upd(*builder.getDocumentTypeRepo(), dt, DocumentId("doc::1")); - auto new_tensor = createTensor({ {{{"x", "8"}, {"y", "9"}}, 11} }, - {"x", "y"}); + auto new_tensor = make_tensor(TensorSpec("tensor(x{},y{})") + .add({{"x", "8"}, {"y", "9"}}, 11)); TensorDataType xySparseTensorDataType(vespalib::eval::ValueType::from_spec("tensor(x{},y{})")); TensorFieldValue new_value(xySparseTensorDataType); new_value = new_tensor->clone(); diff --git a/searchcore/src/tests/proton/docsummary/docsummary.cpp b/searchcore/src/tests/proton/docsummary/docsummary.cpp index 38b85594a62..e8152161faa 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/default_tensor.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/tensor/tensor_factory.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/test/make_bucket_space.h> #include <vespa/searchcore/proton/attribute/attribute_writer.h> @@ -55,10 +55,9 @@ using search::index::schema::CollectionType; 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::TensorCells; -using vespalib::tensor::TensorDimensions; -using vespalib::tensor::TensorFactory; +using vespalib::tensor::DefaultTensorEngine; using namespace vespalib::slime; typedef std::unique_ptr<GeneralResult> GeneralResultPtr; @@ -137,10 +136,9 @@ getDocTypeName() return "searchdocument"; } -Tensor::UP createTensor(const TensorCells &cells, - const TensorDimensions &dimensions) { - vespalib::tensor::DefaultTensor::builder builder; - return TensorFactory::create(cells, dimensions, builder); +Tensor::UP make_tensor(const TensorSpec &spec) { + auto tensor = DefaultTensorEngine::ref().from_spec(spec); + return Tensor::UP(dynamic_cast<Tensor*>(tensor.release())); } vespalib::string asVstring(vespalib::Memory str) { @@ -750,7 +748,8 @@ Test::requireThatAttributesAreUsed() endElement(). endField(). startAttributeField("bj"). - addTensor(createTensor({ {{{"x","f"},{"y","g"}}, 3} }, { "x", "y"})). + addTensor(make_tensor(TensorSpec("tensor(x{},y{})") + .add({{"x", "f"}, {"y", "g"}}, 3))). endField(). endDocument(), 2); @@ -776,7 +775,8 @@ Test::requireThatAttributesAreUsed() "bh:[{item:40.4,weight:4},{item:50.5,weight:5}]," "bi:[{item:'quux',weight:7},{item:'qux',weight:6}]," "bj:'0x01020178017901016601674008000000000000'}", *rep, 0, true)); - TEST_DO(assertTensor(createTensor({ {{{"x","f"},{"y","g"}}, 3} }, { "x", "y"}), + TEST_DO(assertTensor(make_tensor(TensorSpec("tensor(x{},y{})") + .add({{"x", "f"}, {"y", "g"}}, 3)), "bj", *rep, 0, rclass)); // empty doc @@ -790,13 +790,15 @@ Test::requireThatAttributesAreUsed() attributeFieldWriter.execute(attributeFieldWriter.getExecutorId(bjAttr->getNamePrefix()), [&]() { - bjTensorAttr->setTensor(3, *createTensor({ {{{"x", "a"},{"y", "b"}}, 4} }, { "x"})); + bjTensorAttr->setTensor(3, *make_tensor(TensorSpec("tensor(x{},y{})") + .add({{"x", "a"}, {"y", "b"}}, 4))); bjTensorAttr->commit(); }); attributeFieldWriter.sync(); DocsumReply::UP rep2 = dc._ddb->getDocsums(req); - TEST_DO(assertTensor(createTensor({ {{{"x","a"},{"y","b"}}, 4} }, { "x", "y"}), + TEST_DO(assertTensor(make_tensor(TensorSpec("tensor(x{},y{})") + .add({{"x", "a"}, {"y", "b"}}, 4)), "bj", *rep2, 1, rclass)); DocsumRequest req3; diff --git a/searchcore/src/tests/proton/docsummary/summaryfieldconverter_test.cpp b/searchcore/src/tests/proton/docsummary/summaryfieldconverter_test.cpp index b82fec85d47..cc6eef14fd6 100644 --- a/searchcore/src/tests/proton/docsummary/summaryfieldconverter_test.cpp +++ b/searchcore/src/tests/proton/docsummary/summaryfieldconverter_test.cpp @@ -47,8 +47,7 @@ #include <vespa/searchlib/util/slime_output_raw_buf_adapter.h> #include <vespa/eval/tensor/tensor.h> #include <vespa/eval/tensor/types.h> -#include <vespa/eval/tensor/default_tensor.h> -#include <vespa/eval/tensor/tensor_factory.h> +#include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/vespalib/data/slime/slime.h> using document::Annotation; @@ -95,12 +94,12 @@ using vespa::config::search::SummarymapConfig; using vespa::config::search::SummarymapConfigBuilder; using vespalib::Slime; using vespalib::eval::ValueType; +using vespalib::eval::TensorSpec; using vespalib::geo::ZCurve; using vespalib::slime::Cursor; using vespalib::string; using vespalib::tensor::Tensor; -using vespalib::tensor::TensorCells; -using vespalib::tensor::TensorDimensions; +using vespalib::tensor::DefaultTensorEngine; using namespace search::docsummary; @@ -676,11 +675,9 @@ Test::requireThatPredicateIsPrinted() SFC::convertSummaryField(false, *doc.getValue("predicate")).get()); } - -Tensor::UP -createTensor(const TensorCells &cells, const TensorDimensions &dimensions) { - vespalib::tensor::DefaultTensor::builder builder; - return vespalib::tensor::TensorFactory::create(cells, dimensions, builder); +Tensor::UP make_tensor(const TensorSpec &spec) { + auto tensor = DefaultTensorEngine::ref().from_spec(spec); + return Tensor::UP(dynamic_cast<Tensor*>(tensor.release())); } void @@ -688,14 +685,14 @@ Test::requireThatTensorIsNotConverted() { TensorDataType tensorDataType(ValueType::from_spec("tensor(x{},y{})")); TensorFieldValue tensorFieldValue(tensorDataType); - tensorFieldValue = createTensor({ {{{"x", "4"}, {"y", "5"}}, 7} }, - {"x", "y"}); + tensorFieldValue = make_tensor(TensorSpec("tensor(x{},y{})") + .add({{"x", "4"}, {"y", "5"}}, 7)); Document doc(getDocType(), DocumentId("doc:scheme:")); doc.setRepo(*_documentRepo); doc.setValue("tensor", tensorFieldValue); - TEST_CALL(checkTensor(createTensor({ {{{"x", "4"}, {"y", "5"}}, 7} }, - {"x", "y"}), + TEST_CALL(checkTensor(make_tensor(TensorSpec("tensor(x{},y{})") + .add({{"x", "4"}, {"y", "5"}}, 7)), SFC::convertSummaryField(false, *doc.getValue("tensor")).get())); doc.setValue("tensor", TensorFieldValue()); |