Skip to content

Commit

Permalink
Add missing return keyword...
Browse files Browse the repository at this point in the history
Signed-off-by: Buqian Zheng <[email protected]>
  • Loading branch information
zhengbuqian committed Sep 21, 2023
1 parent ea12387 commit a124821
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/index/flat/flat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}

DataSetPtr results = std::make_shared<DataSet>();
Expand Down Expand Up @@ -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<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}

const FlatConfig& f_cfg = static_cast<const FlatConfig&>(cfg);
Expand Down Expand Up @@ -253,7 +253,7 @@ class FlatIndexNode : public IndexNode {
Serialize(BinarySet& binset) const override {
if (!index_) {
LOG_KNOWHERE_ERROR_ << "Can not serialize empty index.";
expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return Status::empty_index;
}
try {
MemoryIOWriter writer;
Expand Down
10 changes: 5 additions & 5 deletions src/index/gpu/flat_gpu/flat_gpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSetPtr>::Err(Status::faiss_inner_error, e.what());
return Status::faiss_inner_error;
}
return Status::success;
}
Expand All @@ -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<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}

const FlatConfig& f_cfg = static_cast<const FlatConfig&>(cfg);
Expand Down Expand Up @@ -114,7 +114,7 @@ class GpuFlatIndexNode : public IndexNode {
Serialize(BinarySet& binset) const override {
if (!index_) {
LOG_KNOWHERE_WARNING_ << "serilalization on empty index.";
expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return Status::empty_index;
}
try {
MemoryIOWriter writer;
Expand All @@ -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<DataSetPtr>::Err(Status::faiss_inner_error, e.what());
return Status::faiss_inner_error;
}
return Status::success;
}
Expand All @@ -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<DataSetPtr>::Err(Status::faiss_inner_error, e.what());
return Status::faiss_inner_error;
}

return Status::success;
Expand Down
8 changes: 4 additions & 4 deletions src/index/gpu/ivf_gpu/ivf_gpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}
if (!index_->is_trained) {
LOG_KNOWHERE_ERROR_ << "Can not add data to not trained GpuIvfIndex.";
expected<DataSetPtr>::Err(Status::index_not_trained, "index not trained");
return expected<DataSetPtr>::Err(Status::index_not_trained, "index not trained");
}
auto rows = dataset.GetRows();
auto tensor = dataset.GetTensor();
Expand Down Expand Up @@ -177,11 +177,11 @@ class GpuIvfIndexNode : public IndexNode {
Serialize(BinarySet& binset) const override {
if (!index_) {
LOG_KNOWHERE_ERROR_ << "Can not serialize empty GpuIvfIndex.";
expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}
if (!index_->is_trained) {
LOG_KNOWHERE_ERROR_ << "Can not serialize not trained GpuIvfIndex.";
expected<DataSetPtr>::Err(Status::index_not_trained, "index not trained");
return expected<DataSetPtr>::Err(Status::index_not_trained, "index not trained");
}

try {
Expand Down
7 changes: 4 additions & 3 deletions src/index/hnsw/hnsw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return Status::empty_index;
}

knowhere::TimeRecorder build_time("Building HNSW cost");
Expand All @@ -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<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}
auto nq = dataset.GetRows();
auto xq = dataset.GetTensor();
Expand Down Expand Up @@ -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<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<std::vector<std::shared_ptr<IndexNode::iterator>>>::Err(Status::empty_index,
"index not loaded");
}
auto nq = dataset.GetRows();
auto xq = dataset.GetTensor();
Expand Down
14 changes: 7 additions & 7 deletions src/index/ivf/ivf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ Status
IvfIndexNode<T>::Add(const DataSet& dataset, const Config& cfg) {
if (!this->index_) {
LOG_KNOWHERE_ERROR_ << "Can not add data to empty IVF index.";
expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return Status::empty_index;
}
auto data = dataset.GetTensor();
auto rows = dataset.GetRows();
Expand All @@ -373,11 +373,11 @@ expected<DataSetPtr>
IvfIndexNode<T>::Search(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const {
if (!this->index_) {
LOG_KNOWHERE_WARNING_ << "search on empty index";
expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}
if (!this->index_->is_trained) {
LOG_KNOWHERE_WARNING_ << "index not trained";
expected<DataSetPtr>::Err(Status::index_not_trained, "index not trained");
return expected<DataSetPtr>::Err(Status::index_not_trained, "index not trained");
}

auto dim = dataset.GetDim();
Expand Down Expand Up @@ -454,11 +454,11 @@ expected<DataSetPtr>
IvfIndexNode<T>::RangeSearch(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const {
if (!this->index_) {
LOG_KNOWHERE_WARNING_ << "range search on empty index";
expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}
if (!this->index_->is_trained) {
LOG_KNOWHERE_WARNING_ << "index not trained";
expected<DataSetPtr>::Err(Status::index_not_trained, "index not trained");
return expected<DataSetPtr>::Err(Status::index_not_trained, "index not trained");
}

auto nq = dataset.GetRows();
Expand Down Expand Up @@ -544,7 +544,7 @@ template <typename T>
expected<DataSetPtr>
IvfIndexNode<T>::GetVectorByIds(const DataSet& dataset) const {
if (!this->index_) {
expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}
if (!this->index_->is_trained) {
return expected<DataSetPtr>::Err(Status::index_not_trained, "index not trained");
Expand Down Expand Up @@ -622,7 +622,7 @@ expected<DataSetPtr>
IvfIndexNode<faiss::IndexIVFFlat>::GetIndexMeta(const Config& config) const {
if (!index_) {
LOG_KNOWHERE_WARNING_ << "get index meta on empty index";
expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
return expected<DataSetPtr>::Err(Status::empty_index, "index not loaded");
}

auto ivf_index = dynamic_cast<faiss::IndexIVF*>(index_.get());
Expand Down

0 comments on commit a124821

Please sign in to comment.