diff options
author | Arne Juul <arnej@yahooinc.com> | 2023-04-26 07:29:30 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2023-04-26 14:36:08 +0000 |
commit | 7c6ca1371698cd347a2868f6fa935013ecd02ead (patch) | |
tree | a6fd0d067f56e748124dea6ba75313a7b74d36b5 | |
parent | f0ed62d462143f06df778c824a43821ec41da5af (diff) |
no need to convert cells in DistanceCalculator anymore
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<float>(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<float>(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<float>(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<typename LCT, typename RCT> -std::unique_ptr<Value> -convert_cells(const ValueType& new_type, const Value& old_value) -{ - auto old_cells = old_value.cells().typify<LCT>(); - auto builder = FastValueBuilderFactory::get().create_value_builder<RCT>(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 <typename LCT, typename RCT> - static auto invoke(const ValueType& new_type, const Value& old_value) { - return convert_cells<LCT, RCT>(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<vespalib::eval::Value> _query_tensor_uptr; const vespalib::eval::Value* _query_tensor; std::unique_ptr<BoundDistanceFunction> _dist_fun; |