From 7c6ca1371698cd347a2868f6fa935013ecd02ead Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Wed, 26 Apr 2023 07:29:30 +0000 Subject: no need to convert cells in DistanceCalculator anymore --- .../searchable/attributeblueprint_test.cpp | 6 +-- .../vespa/searchlib/tensor/distance_calculator.cpp | 44 +--------------------- .../vespa/searchlib/tensor/distance_calculator.h | 1 - 3 files changed, 4 insertions(+), 47 deletions(-) diff --git a/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp b/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp index 0a6a912156a..ed1e15e17e7 100644 --- a/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp @@ -373,9 +373,9 @@ TEST(AttributeBlueprintTest, nearest_neighbor_blueprint_is_created_by_attribute_ // same cell type: expect_nearest_neighbor_blueprint("tensor(x[2])", x_2_double, x_2_double); expect_nearest_neighbor_blueprint("tensor(x[2])", x_2_float, x_2_float); - // convert cell type: - expect_nearest_neighbor_blueprint("tensor(x[2])", x_2_float, x_2_double); - expect_nearest_neighbor_blueprint("tensor(x[2])", x_2_double, x_2_float); + // converts cell type internally: + expect_nearest_neighbor_blueprint("tensor(x[2])", x_2_float, x_2_float); + expect_nearest_neighbor_blueprint("tensor(x[2])", x_2_double, x_2_double); } void diff --git a/searchlib/src/vespa/searchlib/tensor/distance_calculator.cpp b/searchlib/src/vespa/searchlib/tensor/distance_calculator.cpp index 8da777d97eb..5759b4b74ea 100644 --- a/searchlib/src/vespa/searchlib/tensor/distance_calculator.cpp +++ b/searchlib/src/vespa/searchlib/tensor/distance_calculator.cpp @@ -16,65 +16,23 @@ using vespalib::eval::Value; using vespalib::eval::ValueType; using vespalib::make_string; -namespace { - -template -std::unique_ptr -convert_cells(const ValueType& new_type, const Value& old_value) -{ - auto old_cells = old_value.cells().typify(); - auto builder = FastValueBuilderFactory::get().create_value_builder(new_type); - auto new_cells = builder->add_subspace(); - assert(old_cells.size() == new_cells.size()); - auto p = new_cells.begin(); - for (LCT value : old_cells) { - RCT conv(value); - *p++ = conv; - } - return builder->build(std::move(builder)); -} - -struct ConvertCellsSelector -{ - template - static auto invoke(const ValueType& new_type, const Value& old_value) { - return convert_cells(new_type, old_value); - } - auto operator() (CellType from, CellType to, const Value& old_value) const { - using MyTypify = vespalib::eval::TypifyCellType; - ValueType new_type = old_value.type().cell_cast(to); - return vespalib::typify_invoke<2,MyTypify,ConvertCellsSelector>(from, to, new_type, old_value); - } -}; - -} - namespace search::tensor { DistanceCalculator::DistanceCalculator(const tensor::ITensorAttribute& attr_tensor, const vespalib::eval::Value& query_tensor_in) : _attr_tensor(attr_tensor), - _query_tensor_uptr(), _query_tensor(&query_tensor_in), _dist_fun() { auto * nns_index = _attr_tensor.nearest_neighbor_index(); auto & dff = nns_index ? nns_index->distance_function_factory() : attr_tensor.distance_function_factory(); - auto query_ct = _query_tensor->cells().type; - CellType required_ct = dff.expected_cell_type; - if (query_ct != required_ct) { - ConvertCellsSelector converter; - _query_tensor_uptr = converter(query_ct, required_ct, *_query_tensor); - _query_tensor = _query_tensor_uptr.get(); - } - _dist_fun = dff.for_query_vector(_query_tensor->cells()); + _dist_fun = dff.for_query_vector(query_tensor_in.cells()); assert(_dist_fun); } DistanceCalculator::DistanceCalculator(const tensor::ITensorAttribute& attr_tensor, BoundDistanceFunction::UP function_in) : _attr_tensor(attr_tensor), - _query_tensor_uptr(), _query_tensor(nullptr), _dist_fun(std::move(function_in)) { diff --git a/searchlib/src/vespa/searchlib/tensor/distance_calculator.h b/searchlib/src/vespa/searchlib/tensor/distance_calculator.h index a3ca771e30c..f29cd389732 100644 --- a/searchlib/src/vespa/searchlib/tensor/distance_calculator.h +++ b/searchlib/src/vespa/searchlib/tensor/distance_calculator.h @@ -22,7 +22,6 @@ namespace search::tensor { class DistanceCalculator { private: const tensor::ITensorAttribute& _attr_tensor; - std::unique_ptr _query_tensor_uptr; const vespalib::eval::Value* _query_tensor; std::unique_ptr _dist_fun; -- cgit v1.2.3