Skip to content

Commit 503d445

Browse files
committed
address comments
1 parent 609b20c commit 503d445

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

cpp/include/cuvs/neighbors/cagra.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ struct CUVS_EXPORT index : cuvs::neighbors::index {
471471
/** Total length of the index (number of vectors). */
472472
[[nodiscard]] constexpr inline auto size() const noexcept -> IdxT
473473
{
474+
if (dataset_fd_.has_value() || graph_fd_.has_value()) { return n_rows_; }
474475
auto data_rows = dataset_.n_rows();
475-
if (dataset_fd_.has_value()) { return n_rows_; }
476476
return data_rows > 0 ? data_rows : graph_view_.extent(0);
477477
}
478478

@@ -484,7 +484,14 @@ struct CUVS_EXPORT index : cuvs::neighbors::index {
484484
/** Graph degree */
485485
[[nodiscard]] constexpr inline auto graph_degree() const noexcept -> uint32_t
486486
{
487-
return dataset_fd_.has_value() ? graph_degree_ : graph_view_.extent(1);
487+
return graph_fd_.has_value() ? graph_degree_ : graph_view_.extent(1);
488+
}
489+
490+
/** Number of rows represented by the graph. */
491+
[[nodiscard]] constexpr inline auto graph_size() const noexcept -> IdxT
492+
{
493+
return graph_fd_.has_value() ? static_cast<IdxT>(n_rows_)
494+
: static_cast<IdxT>(graph_view_.extent(0));
488495
}
489496

490497
/** Non-owning dataset binding stored by the index. */

cpp/src/neighbors/cagra.cuh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
#pragma once
77

8+
#include "detail/ann_utils.cuh"
89
#include "detail/cagra/add_nodes.cuh"
910
#include "detail/cagra/cagra_build.cuh"
1011
#include "detail/cagra/cagra_merge.cuh"
1112
#include "detail/cagra/cagra_search.cuh"
1213
#include "detail/cagra/graph_core.cuh"
1314

14-
#include "detail/ann_utils.cuh"
1515
#include <raft/core/device_mdspan.hpp>
1616
#include <raft/core/host_device_accessor.hpp>
17+
#include <raft/core/logger.hpp>
1718
#include <raft/core/mdspan.hpp>
1819
#include <raft/core/resources.hpp>
1920
#include <raft/linalg/norm.cuh>
@@ -22,12 +23,11 @@
2223
#include <cuvs/core/bitset.hpp>
2324
#include <cuvs/distance/distance.hpp>
2425
#include <cuvs/neighbors/cagra.hpp>
25-
2626
#include <cuvs/neighbors/common.hpp>
27+
2728
#include <rmm/cuda_stream_view.hpp>
2829

2930
#include <algorithm>
30-
#include <memory>
3131
#include <optional>
3232
#include <type_traits>
3333

@@ -573,11 +573,16 @@ auto update_dataset(raft::resources const& res,
573573
index<T, IdxT, SrcDatasetViewT>&& cagra_index,
574574
DstDatasetViewT dataset) -> index<T, IdxT, DstDatasetViewT>
575575
{
576-
if constexpr (!std::is_same_v<SrcDatasetViewT, DstDatasetViewT>) {
577-
RAFT_EXPECTS(dataset.n_rows() == static_cast<int64_t>(cagra_index.size()),
578-
"The new dataset row count must match the source dataset row count");
579-
RAFT_EXPECTS(cagra_index.dim() == 0 || dataset.dim() == cagra_index.dim(),
580-
"The new dataset dimension must match the source dataset dimension");
576+
auto const graph_rows = static_cast<int64_t>(cagra_index.graph_size());
577+
if (dataset.n_rows() != graph_rows) {
578+
RAFT_LOG_WARN("The new dataset row count (%ld) does not match the graph row count (%ld)",
579+
static_cast<long>(dataset.n_rows()),
580+
static_cast<long>(graph_rows));
581+
}
582+
if (dataset.dim() != cagra_index.dim()) {
583+
RAFT_LOG_WARN("The new dataset dimension (%u) does not match the index dimension (%u)",
584+
static_cast<unsigned>(dataset.dim()),
585+
static_cast<unsigned>(cagra_index.dim()));
581586
}
582587

583588
index<T, IdxT, DstDatasetViewT> new_index(res, std::move(cagra_index), dataset);

cpp/src/neighbors/detail/cagra/add_nodes.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ void extend_core(raft::resources const& handle,
408408
cuvs::neighbors::cagra::add_graph_nodes<T, IdxT>(
409409
handle, extended_strided, index, updated_graph.view(), params);
410410

411-
index = cuvs::neighbors::cagra::update_dataset(handle, std::move(index), extended_dataset);
412411
index.update_graph(handle, raft::make_const_mdspan(updated_graph.view()));
412+
index = cuvs::neighbors::cagra::update_dataset(handle, std::move(index), extended_dataset);
413413
}
414414
}
415415
} // namespace cuvs::neighbors::cagra

0 commit comments

Comments
 (0)