// Copyright (C) 2019-2020 Zilliz. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software distributed under the License // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express // or implied. See the License for the specific language governing permissions and limitations under the License #include "common/Types.h" #include #include "exceptions/EasyAssert.h" #include #include namespace milvus { using boost::algorithm::to_upper_copy; namespace Metric = knowhere::Metric; static const auto metric_bimap = [] { boost::bimap mapping; using pos = boost::bimap::value_type; mapping.insert(pos(std::string(Metric::L2), MetricType::METRIC_L2)); mapping.insert(pos(std::string(Metric::IP), MetricType::METRIC_INNER_PRODUCT)); mapping.insert(pos(std::string(Metric::JACCARD), MetricType::METRIC_Jaccard)); mapping.insert(pos(std::string(Metric::TANIMOTO), MetricType::METRIC_Tanimoto)); mapping.insert(pos(std::string(Metric::HAMMING), MetricType::METRIC_Hamming)); mapping.insert(pos(std::string(Metric::SUBSTRUCTURE), MetricType::METRIC_Substructure)); mapping.insert(pos(std::string(Metric::SUPERSTRUCTURE), MetricType::METRIC_Superstructure)); return mapping; }(); MetricType GetMetricType(const std::string& type_name) { // Assume Metric is all upper at knowhere auto real_name = to_upper_copy(type_name); AssertInfo(metric_bimap.left.count(real_name), "metric type not found: (" + type_name + ")"); return metric_bimap.left.at(real_name); } std::string MetricTypeToName(MetricType metric_type) { AssertInfo(metric_bimap.right.count(metric_type), "metric_type enum(" + std::to_string((int)metric_type) + ") not found"); return metric_bimap.right.at(metric_type); } } // namespace milvus