diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-12-03 14:39:39 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-12-03 14:41:30 +0000 |
commit | 64c0447caef5e327e5661dbb0be388ef03e112e1 (patch) | |
tree | 71590732314e589dba1da23455af28fa11ff6c8a /searchlib | |
parent | 07dd588fbeb942582d3f8d5cd5950d0a5851161e (diff) |
use FastValueBuilderFactory
Diffstat (limited to 'searchlib')
3 files changed, 33 insertions, 30 deletions
diff --git a/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h b/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h index a6d3de54d00..964d9599b57 100644 --- a/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h +++ b/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h @@ -3,9 +3,11 @@ #pragma once #include <vespa/searchcommon/attribute/iattributevector.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/value.h> #include <vespa/vespalib/stllike/string.h> -#include <vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h> + +using vespalib::eval::FastValueBuilderFactory; namespace search::features { @@ -40,15 +42,17 @@ void TensorFromAttributeExecutor<WeightedBufferType>::execute(uint32_t docId) { _attrBuffer.fill(*_attribute, docId); - vespalib::tensor::DirectSparseTensorBuilder<double> builder(_type); - builder.reserve(_attrBuffer.size()); - vespalib::tensor::SparseTensorAddressBuilder address; + auto factory = FastValueBuilderFactory::get(); + auto builder = factory.create_value_builder<double>(_type, 1, 1, _attrBuffer.size()); + std::vector<vespalib::stringref> addr_ref; for (size_t i = 0; i < _attrBuffer.size(); ++i) { - address.clear(); - address.add(vespalib::string(_attrBuffer[i].value())); - builder.insertCell(address, _attrBuffer[i].weight(), [](double, double v){ return v; }); + vespalib::string label(_attrBuffer[i].value()); + addr_ref.clear(); + addr_ref.push_back(label); + auto cell_array = builder->add_subspace(addr_ref); + cell_array[0] = _attrBuffer[i].weight(); } - _tensor = builder.build(); + _tensor = builder->build(std::move(builder)); outputs().set_object(0, *_tensor); } diff --git a/searchlib/src/vespa/searchlib/features/tensor_from_labels_feature.cpp b/searchlib/src/vespa/searchlib/features/tensor_from_labels_feature.cpp index e6c5f22dd16..e4f0a010ae2 100644 --- a/searchlib/src/vespa/searchlib/features/tensor_from_labels_feature.cpp +++ b/searchlib/src/vespa/searchlib/features/tensor_from_labels_feature.cpp @@ -8,6 +8,7 @@ #include <vespa/searchlib/fef/feature_type.h> #include <vespa/searchcommon/attribute/attributecontent.h> #include <vespa/searchcommon/attribute/iattributevector.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/value_type.h> #include <vespa/log/log.h> @@ -17,8 +18,7 @@ using namespace search::fef; using search::attribute::IAttributeVector; using search::attribute::WeightedConstCharContent; using search::attribute::WeightedStringContent; -using vespalib::tensor::DirectSparseTensorBuilder; -using vespalib::tensor::SparseTensorAddressBuilder; +using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::ValueType; using search::fef::FeatureType; @@ -91,15 +91,16 @@ createQueryExecutor(const search::fef::IQueryEnvironment &env, if (prop.found() && !prop.get().empty()) { std::vector<vespalib::string> vector; ArrayParser::parse(prop.get(), vector); - DirectSparseTensorBuilder<double> tensorBuilder(type); - tensorBuilder.reserve(vector.size()); - SparseTensorAddressBuilder address; + auto factory = FastValueBuilderFactory::get(); + auto builder = factory.create_value_builder<double>(type, 1, 1, vector.size()); + std::vector<vespalib::stringref> addr_ref; for (const auto &elem : vector) { - address.clear(); - address.add(elem); - tensorBuilder.insertCell(address, 1.0, [](double, double v){ return v; }); + addr_ref.clear(); + addr_ref.push_back(elem); + auto cell_array = builder->add_subspace(addr_ref); + cell_array[0] = 1.0; } - return ConstantTensorExecutor::create(tensorBuilder.build(), stash); + return ConstantTensorExecutor::create(builder->build(std::move(builder)), stash); } return ConstantTensorExecutor::createEmpty(type, stash); } diff --git a/searchlib/src/vespa/searchlib/features/tensor_from_weighted_set_feature.cpp b/searchlib/src/vespa/searchlib/features/tensor_from_weighted_set_feature.cpp index 8c290e1f2b0..88309120882 100644 --- a/searchlib/src/vespa/searchlib/features/tensor_from_weighted_set_feature.cpp +++ b/searchlib/src/vespa/searchlib/features/tensor_from_weighted_set_feature.cpp @@ -1,19 +1,16 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "tensor_from_weighted_set_feature.h" - #include "constant_tensor_executor.h" #include "utils.h" #include "tensor_from_attribute_executor.h" #include "weighted_set_parser.hpp" - #include <vespa/searchlib/fef/properties.h> #include <vespa/searchlib/fef/feature_type.h> #include <vespa/searchcommon/attribute/attributecontent.h> #include <vespa/searchcommon/attribute/iattributevector.h> -#include <vespa/eval/eval/function.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/value_type.h> -#include <vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h> #include <vespa/log/log.h> LOG_SETUP(".features.tensor_from_weighted_set_feature"); @@ -22,8 +19,7 @@ using namespace search::fef; using search::attribute::IAttributeVector; using search::attribute::WeightedConstCharContent; using search::attribute::WeightedStringContent; -using vespalib::tensor::DirectSparseTensorBuilder; -using vespalib::tensor::SparseTensorAddressBuilder; +using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::ValueType; using search::fef::FeatureType; @@ -106,15 +102,17 @@ createQueryExecutor(const search::fef::IQueryEnvironment &env, if (prop.found() && !prop.get().empty()) { WeightedStringVector vector; WeightedSetParser::parse(prop.get(), vector); - DirectSparseTensorBuilder<double> tensorBuilder(type); - tensorBuilder.reserve(vector._data.size()); - SparseTensorAddressBuilder address; + auto factory = FastValueBuilderFactory::get(); + size_t sz = vector._data.size(); + auto builder = factory.create_value_builder<double>(type, 1, 1, sz); + std::vector<vespalib::stringref> addr_ref; for (const auto &elem : vector._data) { - address.clear(); - address.add(elem.value()); - tensorBuilder.insertCell(address, elem.weight(), [](double, double v){ return v; }); + addr_ref.clear(); + addr_ref.push_back(elem.value()); + auto cell_array = builder->add_subspace(addr_ref); + cell_array[0] = elem.weight(); } - return ConstantTensorExecutor::create(tensorBuilder.build(), stash); + return ConstantTensorExecutor::create(builder->build(std::move(builder)), stash); } return ConstantTensorExecutor::createEmpty(type, stash); } |