diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-09-29 08:12:07 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-10-01 09:32:18 +0000 |
commit | 920eea97620f6db8b58cbb53def2eea783b2dcbd (patch) | |
tree | 4c7335c8ff4813f5696d9ab3c67facbd13188910 /searchlib | |
parent | cc954b2df294897606a6b1b40da9d5810394a2d8 (diff) |
Implement new Value API in SparseTensor
* new Address -> index mapping in SparseTensorIndex
* extra indirection in SparseTensor
* rename old "apply" utilities -> join
* make a celltype-templated SparseTensorT and its Builder
* add large vector sparse multiply benchmark
* get rid of temporary SparseTensorValue
* handle templated DirectSparseTensorBuilder in searchlib
Diffstat (limited to 'searchlib')
4 files changed, 16 insertions, 15 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 b9349071617..d6175bf57b7 100644 --- a/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h +++ b/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h @@ -41,7 +41,7 @@ void TensorFromAttributeExecutor<WeightedBufferType>::execute(uint32_t docId) { _attrBuffer.fill(*_attribute, docId); - vespalib::tensor::DirectSparseTensorBuilder builder(_type); + vespalib::tensor::DirectSparseTensorBuilder<double> builder(_type); vespalib::tensor::SparseTensorAddressBuilder address; for (size_t i = 0; i < _attrBuffer.size(); ++i) { address.clear(); 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 e43aea0a637..fbeed77e5d0 100644 --- a/searchlib/src/vespa/searchlib/features/tensor_from_labels_feature.cpp +++ b/searchlib/src/vespa/searchlib/features/tensor_from_labels_feature.cpp @@ -91,7 +91,7 @@ createQueryExecutor(const search::fef::IQueryEnvironment &env, if (prop.found() && !prop.get().empty()) { std::vector<vespalib::string> vector; ArrayParser::parse(prop.get(), vector); - DirectSparseTensorBuilder tensorBuilder(type); + DirectSparseTensorBuilder<double> tensorBuilder(type); SparseTensorAddressBuilder address; for (const auto &elem : vector) { address.clear(); 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 1c2167f4d4d..a3d0aa1f706 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 @@ -106,7 +106,7 @@ createQueryExecutor(const search::fef::IQueryEnvironment &env, if (prop.found() && !prop.get().empty()) { WeightedStringVector vector; WeightedSetParser::parse(prop.get(), vector); - DirectSparseTensorBuilder tensorBuilder(type); + DirectSparseTensorBuilder<double> tensorBuilder(type); SparseTensorAddressBuilder address; for (const auto &elem : vector._data) { address.clear(); diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp index 7abc7bd22b5..a0185b7f7c1 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp @@ -5,7 +5,7 @@ #include <vespa/document/datatype/tensor_data_type.h> #include <vespa/eval/eval/simple_tensor.h> #include <vespa/eval/tensor/dense/typed_dense_tensor_builder.h> -#include <vespa/eval/tensor/sparse/sparse_tensor.h> +#include <vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h> #include <vespa/eval/tensor/wrapped_simple_tensor.h> #include <vespa/searchlib/util/state_explorer_utils.h> #include <vespa/vespalib/data/slime/cursor.h> @@ -16,7 +16,7 @@ using document::TensorDataType; using document::WrongTensorTypeException; using vespalib::eval::SimpleTensor; using vespalib::eval::ValueType; -using vespalib::tensor::SparseTensor; +using vespalib::tensor::DirectSparseTensorBuilder; using vespalib::tensor::Tensor; using vespalib::tensor::TypedDenseTensorBuilder; using vespalib::tensor::WrappedSimpleTensor; @@ -34,22 +34,23 @@ constexpr size_t DEAD_SLACK = 0x10000u; struct CallMakeEmptyTensor { template <typename CT> static Tensor::UP invoke(const ValueType &type) { - TypedDenseTensorBuilder<CT> builder(type); - return builder.build(); + if (type.is_dense()) { + TypedDenseTensorBuilder<CT> builder(type); + return builder.build(); + } + if (type.is_sparse()) { + DirectSparseTensorBuilder<CT> builder(type); + return builder.build(); + } + return std::make_unique<WrappedSimpleTensor>(std::make_unique<SimpleTensor>(type, SimpleTensor::Cells())); } }; Tensor::UP createEmptyTensor(const ValueType &type) { - if (type.is_sparse()) { - return std::make_unique<SparseTensor>(type, SparseTensor::Cells()); - } else if (type.is_dense()) { - using MyTypify = vespalib::eval::TypifyCellType; - return vespalib::typify_invoke<1,MyTypify,CallMakeEmptyTensor>(type.cell_type(), type); - } else { - return std::make_unique<WrappedSimpleTensor>(std::make_unique<SimpleTensor>(type, SimpleTensor::Cells())); - } + using MyTypify = vespalib::eval::TypifyCellType; + return vespalib::typify_invoke<1,MyTypify,CallMakeEmptyTensor>(type.cell_type(), type); } vespalib::string makeWrongTensorTypeMsg(const ValueType &fieldTensorType, const ValueType &tensorType) |