From 4d617156c593a677f6683c693e13f0f62d19cb44 Mon Sep 17 00:00:00 2001 From: Buqian Zheng Date: Thu, 21 Sep 2023 17:01:31 +0800 Subject: [PATCH] Add missing return keyword... Signed-off-by: Buqian Zheng --- src/index/flat/flat.cc | 6 +++--- src/index/gpu/flat_gpu/flat_gpu.cc | 10 +++++----- src/index/gpu/ivf_gpu/ivf_gpu.cc | 16 ++++++++-------- src/index/hnsw/hnsw.cc | 7 ++++--- src/index/ivf/ivf.cc | 14 +++++++------- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/index/flat/flat.cc b/src/index/flat/flat.cc index 0a4f44705..5fffb46ec 100644 --- a/src/index/flat/flat.cc +++ b/src/index/flat/flat.cc @@ -68,7 +68,7 @@ class FlatIndexNode : public IndexNode { Search(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const override { if (!index_) { LOG_KNOWHERE_WARNING_ << "search on empty index"; - expected::Err(Status::empty_index, "index not loaded"); + return expected::Err(Status::empty_index, "index not loaded"); } DataSetPtr results = std::make_shared(); @@ -130,7 +130,7 @@ class FlatIndexNode : public IndexNode { RangeSearch(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const override { if (!index_) { LOG_KNOWHERE_WARNING_ << "range search on empty index"; - expected::Err(Status::empty_index, "index not loaded"); + return expected::Err(Status::empty_index, "index not loaded"); } const FlatConfig& f_cfg = static_cast(cfg); @@ -253,7 +253,7 @@ class FlatIndexNode : public IndexNode { Serialize(BinarySet& binset) const override { if (!index_) { LOG_KNOWHERE_ERROR_ << "Can not serialize empty index."; - expected::Err(Status::empty_index, "index not loaded"); + return Status::empty_index; } try { MemoryIOWriter writer; diff --git a/src/index/gpu/flat_gpu/flat_gpu.cc b/src/index/gpu/flat_gpu/flat_gpu.cc index f0f4d0bd4..30c4a8142 100644 --- a/src/index/gpu/flat_gpu/flat_gpu.cc +++ b/src/index/gpu/flat_gpu/flat_gpu.cc @@ -47,7 +47,7 @@ class GpuFlatIndexNode : public IndexNode { // need not copy index from CPU to GPU for IDMAP } catch (const std::exception& e) { LOG_KNOWHERE_WARNING_ << "faiss inner error, " << e.what(); - return expected::Err(Status::faiss_inner_error, e.what()); + return Status::faiss_inner_error; } return Status::success; } @@ -56,7 +56,7 @@ class GpuFlatIndexNode : public IndexNode { Search(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const override { if (!index_) { LOG_KNOWHERE_WARNING_ << "index not empty, deleted old index."; - expected::Err(Status::empty_index, "index not loaded"); + return expected::Err(Status::empty_index, "index not loaded"); } const FlatConfig& f_cfg = static_cast(cfg); @@ -114,7 +114,7 @@ class GpuFlatIndexNode : public IndexNode { Serialize(BinarySet& binset) const override { if (!index_) { LOG_KNOWHERE_WARNING_ << "serilalization on empty index."; - expected::Err(Status::empty_index, "index not loaded"); + return Status::empty_index; } try { MemoryIOWriter writer; @@ -124,7 +124,7 @@ class GpuFlatIndexNode : public IndexNode { binset.Append(Type(), data, writer.tellg()); } catch (const std::exception& e) { LOG_KNOWHERE_WARNING_ << "faiss inner error, " << e.what(); - return expected::Err(Status::faiss_inner_error, e.what()); + return Status::faiss_inner_error; } return Status::success; } @@ -147,7 +147,7 @@ class GpuFlatIndexNode : public IndexNode { res_ = gpu_res; } catch (const std::exception& e) { LOG_KNOWHERE_WARNING_ << "faiss inner error, " << e.what(); - return expected::Err(Status::faiss_inner_error, e.what()); + return Status::faiss_inner_error; } return Status::success; diff --git a/src/index/gpu/ivf_gpu/ivf_gpu.cc b/src/index/gpu/ivf_gpu/ivf_gpu.cc index 53c6422bb..c486ca0a0 100644 --- a/src/index/gpu/ivf_gpu/ivf_gpu.cc +++ b/src/index/gpu/ivf_gpu/ivf_gpu.cc @@ -101,7 +101,7 @@ class GpuIvfIndexNode : public IndexNode { res_ = gpu_res; } catch (std::exception& e) { LOG_KNOWHERE_WARNING_ << "faiss inner error, " << e.what(); - return expected::Err(Status::faiss_inner_error, e.what()); + return Status::faiss_inner_error; } index_ = std::move(index); return Status::success; @@ -111,11 +111,11 @@ class GpuIvfIndexNode : public IndexNode { Add(const DataSet& dataset, const Config& cfg) override { if (!index_) { LOG_KNOWHERE_ERROR_ << "Can not add data to empty GpuIvfIndex."; - expected::Err(Status::empty_index, "index not loaded"); + return Status::empty_index; } if (!index_->is_trained) { LOG_KNOWHERE_ERROR_ << "Can not add data to not trained GpuIvfIndex."; - expected::Err(Status::index_not_trained, "index not trained"); + return Status::index_not_trained; } auto rows = dataset.GetRows(); auto tensor = dataset.GetTensor(); @@ -124,7 +124,7 @@ class GpuIvfIndexNode : public IndexNode { index_->add(rows, (const float*)tensor); } catch (std::exception& e) { LOG_KNOWHERE_WARNING_ << "faiss inner error, " << e.what(); - return expected::Err(Status::faiss_inner_error, e.what()); + return Status::faiss_inner_error; } return Status::success; } @@ -177,11 +177,11 @@ class GpuIvfIndexNode : public IndexNode { Serialize(BinarySet& binset) const override { if (!index_) { LOG_KNOWHERE_ERROR_ << "Can not serialize empty GpuIvfIndex."; - expected::Err(Status::empty_index, "index not loaded"); + return Status::empty_index; } if (!index_->is_trained) { LOG_KNOWHERE_ERROR_ << "Can not serialize not trained GpuIvfIndex."; - expected::Err(Status::index_not_trained, "index not trained"); + return Status::index_not_trained; } try { @@ -195,7 +195,7 @@ class GpuIvfIndexNode : public IndexNode { binset.Append(Type(), data, writer.tellg()); } catch (std::exception& e) { LOG_KNOWHERE_WARNING_ << "faiss inner error, " << e.what(); - return expected::Err(Status::faiss_inner_error, e.what()); + return Status::faiss_inner_error; } return Status::success; @@ -218,7 +218,7 @@ class GpuIvfIndexNode : public IndexNode { res_ = gpu_res; } catch (std::exception& e) { LOG_KNOWHERE_WARNING_ << "faiss inner error, " << e.what(); - return expected::Err(Status::faiss_inner_error, e.what()); + return Status::faiss_inner_error; } return Status::success; } diff --git a/src/index/hnsw/hnsw.cc b/src/index/hnsw/hnsw.cc index d03494d1d..1d0338da4 100644 --- a/src/index/hnsw/hnsw.cc +++ b/src/index/hnsw/hnsw.cc @@ -74,7 +74,7 @@ class HnswIndexNode : public IndexNode { Add(const DataSet& dataset, const Config& cfg) override { if (!index_) { LOG_KNOWHERE_ERROR_ << "Can not add data to empty HNSW index."; - expected::Err(Status::empty_index, "index not loaded"); + return Status::empty_index; } knowhere::TimeRecorder build_time("Building HNSW cost"); @@ -98,7 +98,7 @@ class HnswIndexNode : public IndexNode { Search(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const override { if (!index_) { LOG_KNOWHERE_WARNING_ << "search on empty index"; - expected::Err(Status::empty_index, "index not loaded"); + return expected::Err(Status::empty_index, "index not loaded"); } auto nq = dataset.GetRows(); auto xq = dataset.GetTensor(); @@ -207,7 +207,8 @@ class HnswIndexNode : public IndexNode { AnnIterator(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const override { if (!index_) { LOG_KNOWHERE_WARNING_ << "creating iterator on empty index"; - expected::Err(Status::empty_index, "index not loaded"); + return expected>>::Err(Status::empty_index, + "index not loaded"); } auto nq = dataset.GetRows(); auto xq = dataset.GetTensor(); diff --git a/src/index/ivf/ivf.cc b/src/index/ivf/ivf.cc index f0070b0bb..0b0e301ff 100644 --- a/src/index/ivf/ivf.cc +++ b/src/index/ivf/ivf.cc @@ -346,7 +346,7 @@ Status IvfIndexNode::Add(const DataSet& dataset, const Config& cfg) { if (!this->index_) { LOG_KNOWHERE_ERROR_ << "Can not add data to empty IVF index."; - expected::Err(Status::empty_index, "index not loaded"); + return Status::empty_index; } auto data = dataset.GetTensor(); auto rows = dataset.GetRows(); @@ -373,11 +373,11 @@ expected IvfIndexNode::Search(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const { if (!this->index_) { LOG_KNOWHERE_WARNING_ << "search on empty index"; - expected::Err(Status::empty_index, "index not loaded"); + return expected::Err(Status::empty_index, "index not loaded"); } if (!this->index_->is_trained) { LOG_KNOWHERE_WARNING_ << "index not trained"; - expected::Err(Status::index_not_trained, "index not trained"); + return expected::Err(Status::index_not_trained, "index not trained"); } auto dim = dataset.GetDim(); @@ -454,11 +454,11 @@ expected IvfIndexNode::RangeSearch(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const { if (!this->index_) { LOG_KNOWHERE_WARNING_ << "range search on empty index"; - expected::Err(Status::empty_index, "index not loaded"); + return expected::Err(Status::empty_index, "index not loaded"); } if (!this->index_->is_trained) { LOG_KNOWHERE_WARNING_ << "index not trained"; - expected::Err(Status::index_not_trained, "index not trained"); + return expected::Err(Status::index_not_trained, "index not trained"); } auto nq = dataset.GetRows(); @@ -544,7 +544,7 @@ template expected IvfIndexNode::GetVectorByIds(const DataSet& dataset) const { if (!this->index_) { - expected::Err(Status::empty_index, "index not loaded"); + return expected::Err(Status::empty_index, "index not loaded"); } if (!this->index_->is_trained) { return expected::Err(Status::index_not_trained, "index not trained"); @@ -622,7 +622,7 @@ expected IvfIndexNode::GetIndexMeta(const Config& config) const { if (!index_) { LOG_KNOWHERE_WARNING_ << "get index meta on empty index"; - expected::Err(Status::empty_index, "index not loaded"); + return expected::Err(Status::empty_index, "index not loaded"); } auto ivf_index = dynamic_cast(index_.get());