Types.cpp 2.3 KB
Newer Older
X
XuanYang-cn 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
// 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 <knowhere/index/vector_index/helpers/IndexParameter.h>
F
FluorineDog 已提交
14
#include "exceptions/EasyAssert.h"
X
XuanYang-cn 已提交
15 16
#include <boost/bimap.hpp>
#include <boost/algorithm/string/case_conv.hpp>
17 18 19
#include "common/type_c.h"
#include "pb/schema.pb.h"
#include "CGoHelper.h"
X
XuanYang-cn 已提交
20 21 22

namespace milvus {

F
FluorineDog 已提交
23
using boost::algorithm::to_upper_copy;
X
XuanYang-cn 已提交
24
namespace Metric = knowhere::Metric;
25
static const auto metric_bimap = [] {
X
XuanYang-cn 已提交
26 27
    boost::bimap<std::string, MetricType> mapping;
    using pos = boost::bimap<std::string, MetricType>::value_type;
F
FluorineDog 已提交
28 29 30 31 32 33 34
    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));
X
XuanYang-cn 已提交
35 36 37 38 39
    return mapping;
}();

MetricType
GetMetricType(const std::string& type_name) {
C
cxytz01 已提交
40
    // Assume Metric is all upper at Knowhere
F
FluorineDog 已提交
41
    auto real_name = to_upper_copy(type_name);
42 43 44 45 46 47 48 49 50
    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);
X
XuanYang-cn 已提交
51 52 53
}

}  // namespace milvus