From b0533175451d077c9920eaa638f84cd7d36bd7c0 Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Tue, 7 Dec 2021 10:13:53 +0800 Subject: [PATCH] Rename FaissMetricTypeToString to MetricTypeToString (#12767) Signed-off-by: yudong.cai --- internal/core/src/query/SearchBruteForce.cpp | 4 +-- internal/core/src/segcore/Utils.h | 11 ++++--- internal/core/unittest/test_utils.cpp | 34 ++++++++++---------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/internal/core/src/query/SearchBruteForce.cpp b/internal/core/src/query/SearchBruteForce.cpp index 28a17e13bb..e3a38a6c6c 100644 --- a/internal/core/src/query/SearchBruteForce.cpp +++ b/internal/core/src/query/SearchBruteForce.cpp @@ -59,8 +59,8 @@ raw_search(MetricType metric_type, // only matched ids will be chosen, not to use heap binary_distance_knn_mc(metric_type, x, xb, n, ntotal, k, code_size, D, labels, bitset); } else { - std::string msg = std::string("do binary search with unsupported metric type: ") + - segcore::FaissMetricTypeToString(metric_type); + std::string msg = + std::string("binary search not support metric type: ") + segcore::MetricTypeToString(metric_type); PanicInfo(msg); } } diff --git a/internal/core/src/segcore/Utils.h b/internal/core/src/segcore/Utils.h index bef9bb6f6b..f2e03ca8c3 100644 --- a/internal/core/src/segcore/Utils.h +++ b/internal/core/src/segcore/Utils.h @@ -13,12 +13,13 @@ #include #include #include + #include "index/thirdparty/faiss/MetricType.h" -namespace milvus { -namespace segcore { +namespace milvus::segcore { + static inline constexpr const char* -FaissMetricTypeToString(faiss::MetricType metric_type) { +MetricTypeToString(faiss::MetricType metric_type) { switch (metric_type) { case faiss::MetricType::METRIC_INNER_PRODUCT: return "METRIC_INNER_PRODUCT"; @@ -50,5 +51,5 @@ FaissMetricTypeToString(faiss::MetricType metric_type) { return "Unsupported"; } } -} // namespace segcore -} // namespace milvus + +} // namespace milvus::segcore diff --git a/internal/core/unittest/test_utils.cpp b/internal/core/unittest/test_utils.cpp index f9777b184f..e3f3365592 100644 --- a/internal/core/unittest/test_utils.cpp +++ b/internal/core/unittest/test_utils.cpp @@ -9,27 +9,27 @@ // 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 +#include + #include "index/thirdparty/faiss/MetricType.h" #include "segcore/Utils.h" -#include - -#include - TEST(Util, FaissMetricTypeToString) { using namespace milvus::segcore; + using namespace faiss; - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_INNER_PRODUCT), "METRIC_INNER_PRODUCT")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_L2), "METRIC_L2")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_L1), "METRIC_L1")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_Linf), "METRIC_Linf")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_Lp), "METRIC_Lp")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_Jaccard), "METRIC_Jaccard")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_Tanimoto), "METRIC_Tanimoto")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_Hamming), "METRIC_Hamming")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_Substructure), "METRIC_Substructure")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_Superstructure), "METRIC_Superstructure")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_Canberra), "METRIC_Canberra")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_BrayCurtis), "METRIC_BrayCurtis")); - ASSERT_EQ(0, strcmp(FaissMetricTypeToString(faiss::MetricType::METRIC_JensenShannon), "METRIC_JensenShannon")); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_INNER_PRODUCT), "METRIC_INNER_PRODUCT"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_L2), "METRIC_L2"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_L1), "METRIC_L1"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_Linf), "METRIC_Linf"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_Lp), "METRIC_Lp"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_Jaccard), "METRIC_Jaccard"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_Tanimoto), "METRIC_Tanimoto"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_Hamming), "METRIC_Hamming"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_Substructure), "METRIC_Substructure"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_Superstructure), "METRIC_Superstructure"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_Canberra), "METRIC_Canberra"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_BrayCurtis), "METRIC_BrayCurtis"); + ASSERT_EQ(MetricTypeToString(MetricType::METRIC_JensenShannon), "METRIC_JensenShannon"); }