aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2019-11-29 12:44:21 +0000
committerArne Juul <arnej@verizonmedia.com>2019-11-29 13:46:44 +0000
commit4ea960c7e62918a53dff17fc8d52108532553dc9 (patch)
treeef2e88cab24c5f6bfb4f7522e66d7f13b3e2451f
parentd090a8ea8baac772fc08b5d4e563b2e6201bb086 (diff)
use select_2 for cell type resolving
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp42
1 files changed, 15 insertions, 27 deletions
diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp
index dcf599daa6a..cc0e306f5a4 100644
--- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp
@@ -94,41 +94,29 @@ create_impl(const NearestNeighborIterator::Params &params)
return std::make_unique<NNI>(params);
}
-template<bool strict, typename LCT>
-std::unique_ptr<NearestNeighborIterator>
-resolve_RCT(const NearestNeighborIterator::Params &params)
-{
- CellType ct = params.tensorAttribute.getTensorType().cell_type();
- if (ct == CellType::FLOAT) {
- return create_impl<strict, LCT, float>(params);
- }
- if (ct == CellType::DOUBLE) {
- return create_impl<strict, LCT, double>(params);
- }
- abort();
-}
+using Creator = std::unique_ptr<NearestNeighborIterator>(*)(const NearestNeighborIterator::Params &params);
-template<bool strict>
-std::unique_ptr<NearestNeighborIterator>
-resolve_LCT_RCT(const NearestNeighborIterator::Params &params)
+template <bool strict>
+struct CellTypeResolver
{
- CellType ct = params.queryTensor.fast_type().cell_type();
- if (ct == CellType::FLOAT) {
- return resolve_RCT<strict, float>(params);
- }
- if (ct == CellType::DOUBLE) {
- return resolve_RCT<strict, double>(params);
- }
- abort();
-}
+ template <typename LCT, typename RCT>
+ static Creator
+ get_fun() { return create_impl<strict, LCT, RCT>; }
+};
std::unique_ptr<NearestNeighborIterator>
resolve_strict_LCT_RCT(bool strict, const NearestNeighborIterator::Params &params)
{
+ CellType lct = params.queryTensor.fast_type().cell_type();
+ CellType rct = params.tensorAttribute.getTensorType().cell_type();
if (strict) {
- return resolve_LCT_RCT<true>(params);
+ using Resolver = CellTypeResolver<true>;
+ auto fun = vespalib::tensor::select_2<Resolver>(lct, rct);
+ return fun(params);
} else {
- return resolve_LCT_RCT<false>(params);
+ using Resolver = CellTypeResolver<false>;
+ auto fun = vespalib::tensor::select_2<Resolver>(lct, rct);
+ return fun(params);
}
}