From 735830d8fe865b91f4346dd5da0502861569116b Mon Sep 17 00:00:00 2001 From: "gony.noreply" Date: Mon, 17 Feb 2020 17:55:39 +0900 Subject: [PATCH] resolve travis build error --- src/hnsw.cc | 8 +++++++- tests/python_test/test_n2.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hnsw.cc b/src/hnsw.cc index d0d8b99..d8e1f64 100644 --- a/src/hnsw.cc +++ b/src/hnsw.cc @@ -19,6 +19,7 @@ using std::move; using std::pair; using std::runtime_error; using std::string; +using std::to_string; using std::vector; Hnsw::Hnsw() : Hnsw(0) {} @@ -126,7 +127,12 @@ bool Hnsw::SaveModel(const string& fname) const { bool Hnsw::LoadModel(const string& fname, const bool use_mmap) { model_ = HnswModel::LoadModelFromFile(fname, use_mmap); - data_dim_ = model_->GetDataDim(); + size_t model_data_dim = model_->GetDataDim(); + if (data_dim_ > 0 && data_dim_ != model_data_dim) { + throw runtime_error("[Error] index dimension(" + to_string(data_dim_) + + ") != model dimension(" + to_string(model_data_dim) + ")"); + } + data_dim_ = model_data_dim; metric_ = model_->GetMetric(); searcher_ = HnswSearch::GenerateSearcher(model_, data_dim_, metric_); return true; diff --git a/tests/python_test/test_n2.py b/tests/python_test/test_n2.py index 0077c63..91047c4 100644 --- a/tests/python_test/test_n2.py +++ b/tests/python_test/test_n2.py @@ -41,9 +41,9 @@ def test_search_by_vector(self): i.add_data([1, 0, 0]) i.build(max_m0=10, m=5) - self.assertEqual(i.search_by_vector([3, 2, 1], 3), [0, 1, 2]) + self.assertEqual(i.search_by_vector([3, 2, 1], 3), [2, 1, 0]) self.assertEqual(i.search_by_vector([1, 2, 3], 3), [0, 1, 2]) - self.assertEqual(i.search_by_vector([2, 0, 1], 3), [0, 1, 2]) + self.assertEqual(i.search_by_vector([2, 0, 1], 3), [2, 0, 1]) def test_search_by_id(self): f = 3