From 52827742ddc5af98db91a45dedabaabed55f521c Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Mon, 15 Jun 2020 08:12:15 +0000 Subject: use typify_invoke instead of dispatch_0/select_2 --- eval/src/vespa/eval/tensor/default_tensor_engine.cpp | 10 ++++++---- .../vespa/eval/tensor/serialization/dense_binary_format.cpp | 5 +++-- .../vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp | 5 +++-- searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp | 6 +++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp index d9fcbaa3e2a..22073143ac0 100644 --- a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp +++ b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp @@ -176,7 +176,7 @@ DefaultTensorEngine::to_spec(const Value &value) const struct CallDenseTensorBuilder { template static Value::UP - call(const ValueType &type, const TensorSpec &spec) + invoke(const ValueType &type, const TensorSpec &spec) { TypedDenseTensorBuilder builder(type); for (const auto &cell: spec.cells()) { @@ -191,6 +191,8 @@ struct CallDenseTensorBuilder { } }; +using MyTypify = eval::TypifyCellType; + Value::UP DefaultTensorEngine::from_spec(const TensorSpec &spec) const { @@ -201,7 +203,7 @@ DefaultTensorEngine::from_spec(const TensorSpec &spec) const double value = spec.cells().empty() ? 0.0 : spec.cells().begin()->second.value; return std::make_unique(value); } else if (type.is_dense()) { - return dispatch_0(type.cell_type(), type, spec); + return typify_invoke<1,MyTypify,CallDenseTensorBuilder>(type.cell_type(), type, spec); } else if (type.is_sparse()) { DirectSparseTensorBuilder builder(type); SparseTensorAddressBuilder address_builder; @@ -449,7 +451,7 @@ const Value &concat_vectors(const Value &a, const Value &b, const vespalib::stri struct CallConcatVectors { template - static const Value &call(const Value &a, const Value &b, const vespalib::string &dimension, size_t vector_size, Stash &stash) { + static const Value &invoke(const Value &a, const Value &b, const vespalib::string &dimension, size_t vector_size, Stash &stash) { return concat_vectors(a, b, dimension, vector_size, stash); } }; @@ -461,7 +463,7 @@ DefaultTensorEngine::concat(const Value &a, const Value &b, const vespalib::stri size_t b_size = vector_size(b.type(), dimension); if ((a_size > 0) && (b_size > 0)) { CellType result_cell_type = ValueType::unify_cell_types(a.type(), b.type()); - return dispatch_0(result_cell_type, a, b, dimension, (a_size + b_size), stash); + return typify_invoke<1,MyTypify,CallConcatVectors>(result_cell_type, a, b, dimension, (a_size + b_size), stash); } return to_default(simple_engine().concat(to_simple(a, stash), to_simple(b, stash), dimension, stash), stash); } diff --git a/eval/src/vespa/eval/tensor/serialization/dense_binary_format.cpp b/eval/src/vespa/eval/tensor/serialization/dense_binary_format.cpp index 493e4af3caf..4d6cfb1c9af 100644 --- a/eval/src/vespa/eval/tensor/serialization/dense_binary_format.cpp +++ b/eval/src/vespa/eval/tensor/serialization/dense_binary_format.cpp @@ -92,7 +92,7 @@ DenseBinaryFormat::serialize(nbostream &stream, const DenseTensorView &tensor) struct CallDecodeCells { template static std::unique_ptr - call(nbostream &stream, size_t numCells, ValueType &&newType) { + invoke(nbostream &stream, size_t numCells, ValueType &&newType) { std::vector newCells; newCells.reserve(numCells); decodeCells(stream, numCells, newCells); @@ -106,7 +106,8 @@ DenseBinaryFormat::deserialize(nbostream &stream, CellType cell_type) std::vector dimensions; size_t numCells = decodeDimensions(stream, dimensions); ValueType newType = ValueType::tensor_type(std::move(dimensions), cell_type); - return dispatch_0(cell_type, stream, numCells, std::move(newType)); + using MyTypify = eval::TypifyCellType; + return typify_invoke<1,MyTypify,CallDecodeCells>(cell_type, stream, numCells, std::move(newType)); } template diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp index 55342f91e93..d8b63909142 100644 --- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp @@ -45,7 +45,7 @@ convert_cells(std::unique_ptr &, vespalib::eval: struct ConvertCellsSelector { template - static auto get_fun() { return convert_cells; } + static auto invoke() { return convert_cells; } }; } // namespace @@ -67,7 +67,8 @@ NearestNeighborBlueprint::NearestNeighborBlueprint(const queryeval::FieldSpec& f { auto lct = _query_tensor->cellsRef().type; auto rct = _attr_tensor.getTensorType().cell_type(); - auto fixup_fun = vespalib::tensor::select_2(lct, rct); + using MyTypify = vespalib::eval::TypifyCellType; + auto fixup_fun = vespalib::typify_invoke<2,MyTypify,ConvertCellsSelector>(lct, rct); fixup_fun(_query_tensor, _attr_tensor.getTensorType()); _fallback_dist_fun = search::tensor::make_distance_function(_attr_tensor.getConfig().distance_metric(), rct); _dist_fun = _fallback_dist_fun.get(); diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp index 979eedec58a..f8db11ae9d8 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp @@ -20,7 +20,6 @@ using vespalib::tensor::SparseTensor; using vespalib::tensor::Tensor; using vespalib::tensor::TypedDenseTensorBuilder; using vespalib::tensor::WrappedSimpleTensor; -using vespalib::tensor::dispatch_0; using search::StateExplorerUtils; namespace search::tensor { @@ -34,7 +33,7 @@ constexpr size_t DEAD_SLACK = 0x10000u; struct CallMakeEmptyTensor { template - static Tensor::UP call(const ValueType &type) { + static Tensor::UP invoke(const ValueType &type) { TypedDenseTensorBuilder builder(type); return builder.build(); } @@ -46,7 +45,8 @@ createEmptyTensor(const ValueType &type) if (type.is_sparse()) { return std::make_unique(type, SparseTensor::Cells()); } else if (type.is_dense()) { - return dispatch_0(type.cell_type(), type); + using MyTypify = vespalib::eval::TypifyCellType; + return vespalib::typify_invoke<1,MyTypify,CallMakeEmptyTensor>(type.cell_type(), type); } else { return std::make_unique(std::make_unique(type, SimpleTensor::Cells())); } -- cgit v1.2.3