diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-03-23 14:02:34 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-03-23 14:30:35 +0000 |
commit | b2bef82b64c8ddd707fa58d394eb325aac1812fb (patch) | |
tree | 1143a2561d69d7617c43143e0d4f82604ae97137 /searchlib | |
parent | 4867cc43efc6d92e5ff9db2924cb38280ebe7037 (diff) |
split out DistanceFunction factory
Diffstat (limited to 'searchlib')
3 files changed, 57 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt b/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt index d0f33c6fd0b..7090158c773 100644 --- a/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt @@ -5,6 +5,7 @@ vespa_add_library(searchlib_tensor OBJECT dense_tensor_attribute.cpp dense_tensor_attribute_saver.cpp dense_tensor_store.cpp + distance_function_factory.cpp generic_tensor_attribute.cpp generic_tensor_attribute_saver.cpp generic_tensor_store.cpp diff --git a/searchlib/src/vespa/searchlib/tensor/distance_function_factory.cpp b/searchlib/src/vespa/searchlib/tensor/distance_function_factory.cpp new file mode 100644 index 00000000000..6b24a062727 --- /dev/null +++ b/searchlib/src/vespa/searchlib/tensor/distance_function_factory.cpp @@ -0,0 +1,41 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "distance_function_factory.h" +#include "distance_functions.h" + +using search::attribute::DistanceMetric; +using vespalib::eval::ValueType; + +namespace search::tensor { + +DistanceFunction::UP +make_distance_function(DistanceMetric variant, ValueType::CellType cell_type) +{ + switch (variant) { + case DistanceMetric::Euclidean: + if (cell_type == ValueType::CellType::FLOAT) { + return std::make_unique<SquaredEuclideanDistance<float>>(); + } else { + return std::make_unique<SquaredEuclideanDistance<double>>(); + } + break; + case DistanceMetric::Angular: + if (cell_type == ValueType::CellType::FLOAT) { + return std::make_unique<AngularDistance<float>>(); + } else { + return std::make_unique<AngularDistance<double>>(); + } + break; + case DistanceMetric::GeoDegrees: + if (cell_type == ValueType::CellType::FLOAT) { + return std::make_unique<GeoDegreesDistance<float>>(); + } else { + return std::make_unique<GeoDegreesDistance<double>>(); + } + break; + } + // not reached: + return DistanceFunction::UP(); +} + +} diff --git a/searchlib/src/vespa/searchlib/tensor/distance_function_factory.h b/searchlib/src/vespa/searchlib/tensor/distance_function_factory.h new file mode 100644 index 00000000000..0faab5217cf --- /dev/null +++ b/searchlib/src/vespa/searchlib/tensor/distance_function_factory.h @@ -0,0 +1,15 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "distance_function.h" +#include <vespa/eval/eval/value_type.h> +#include <vespa/searchcommon/attribute/distance_metric.h> + +namespace search::tensor { + +DistanceFunction::UP +make_distance_function(search::attribute::DistanceMetric variant, + vespalib::eval::ValueType::CellType cell_type); + +} |