diff options
author | Arne Juul <arnej@yahooinc.com> | 2023-04-25 13:44:34 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2023-04-25 15:56:19 +0000 |
commit | b2401a91381d1f66ef316d850d469181f06f0d36 (patch) | |
tree | dc439ba6d66bc306c27b82a0488d8d788e47b3a9 | |
parent | 807aeb083db71c2504c38dcd684e7556952c9047 (diff) |
use switch not multiple ifs
-rw-r--r-- | searchlib/src/vespa/searchlib/tensor/distance_function_factory.cpp | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/searchlib/src/vespa/searchlib/tensor/distance_function_factory.cpp b/searchlib/src/vespa/searchlib/tensor/distance_function_factory.cpp index 8a004e0d3c9..c088d498f0f 100644 --- a/searchlib/src/vespa/searchlib/tensor/distance_function_factory.cpp +++ b/searchlib/src/vespa/searchlib/tensor/distance_function_factory.cpp @@ -93,37 +93,35 @@ std::unique_ptr<DistanceFunctionFactory> make_distance_function_factory(search::attribute::DistanceMetric variant, vespalib::eval::CellType cell_type) { - if (variant == DistanceMetric::Angular) { - if (cell_type == CellType::DOUBLE) { - return std::make_unique<AngularDistanceFunctionFactory<double>>(); - } - return std::make_unique<AngularDistanceFunctionFactory<float>>(); - } - if (variant == DistanceMetric::Euclidean) { - switch (cell_type) { - case CellType::DOUBLE: return std::make_unique<EuclideanDistanceFunctionFactory<double>>(); - case CellType::INT8: return std::make_unique<EuclideanDistanceFunctionFactory<vespalib::eval::Int8Float>>(); - default: return std::make_unique<EuclideanDistanceFunctionFactory<float>>(); - } - } - if (variant == DistanceMetric::PrenormalizedAngular) { - if (cell_type == CellType::DOUBLE) { - return std::make_unique<PrenormalizedAngularDistanceFunctionFactory<double>>(); - } - return std::make_unique<PrenormalizedAngularDistanceFunctionFactory<float>>(); - } - if (variant == DistanceMetric::GeoDegrees) { - return std::make_unique<GeoDistanceFunctionFactory>(); - } - if (variant == DistanceMetric::Hamming) { - switch (cell_type) { - case CellType::DOUBLE: return std::make_unique<HammingDistanceFunctionFactory<double>>(); - case CellType::INT8: return std::make_unique<HammingDistanceFunctionFactory<vespalib::eval::Int8Float>>(); - default: return std::make_unique<HammingDistanceFunctionFactory<float>>(); - } + switch (variant) { + case DistanceMetric::Angular: + switch (cell_type) { + case CellType::DOUBLE: return std::make_unique<AngularDistanceFunctionFactory<double>>(); + default: return std::make_unique<AngularDistanceFunctionFactory<float>>(); + } + case DistanceMetric::Euclidean: + switch (cell_type) { + case CellType::DOUBLE: return std::make_unique<EuclideanDistanceFunctionFactory<double>>(); + case CellType::INT8: return std::make_unique<EuclideanDistanceFunctionFactory<vespalib::eval::Int8Float>>(); + default: return std::make_unique<EuclideanDistanceFunctionFactory<float>>(); + } + case DistanceMetric::InnerProduct: + case DistanceMetric::PrenormalizedAngular: + switch (cell_type) { + case CellType::DOUBLE: return std::make_unique<PrenormalizedAngularDistanceFunctionFactory<double>>(); + default: return std::make_unique<PrenormalizedAngularDistanceFunctionFactory<float>>(); + } + case DistanceMetric::GeoDegrees: + return std::make_unique<GeoDistanceFunctionFactory>(); + case DistanceMetric::Hamming: + switch (cell_type) { + case CellType::DOUBLE: return std::make_unique<HammingDistanceFunctionFactory<double>>(); + case CellType::INT8: return std::make_unique<HammingDistanceFunctionFactory<vespalib::eval::Int8Float>>(); + default: return std::make_unique<HammingDistanceFunctionFactory<float>>(); + } } - auto df = make_distance_function(variant, cell_type); - return std::make_unique<SimpleDistanceFunctionFactory>(std::move(df)); + // not reached: + return {}; } } |