Skip to content

Commit

Permalink
move get_list_size to index struct
Browse files Browse the repository at this point in the history
  • Loading branch information
tarang-jain committed Nov 17, 2023
1 parent 1efd28f commit 9841e6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
30 changes: 0 additions & 30 deletions cpp/include/raft/neighbors/ivf_pq_helpers.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -713,36 +713,6 @@ void set_centers(raft::resources const& res,
ivf_pq::detail::set_centers(res, index, cluster_centers.data_handle());
}

/**
* @brief Helper to fetch size of a particular IVF list in bytes using the list extents.
*
* Usage example:
* @code{.cpp}
* raft::resources res;
* // use default index params
* ivf_pq::index_params index_params;
* // extend the IVF lists while building the index
* index_params.add_data_on_build = true;
* // create and fill the index from a [N, D] dataset
* auto index = raft::neighbors::ivf_pq::build<int64_t>(res, index_params, dataset, N, D);
* // Fetch the size of the fourth list
* uint32_t size = raft::neighbors::ivf_pq::helpers::get_list_size_in_bytes(index, 3);
* @endcode
*
* @tparam IdxT
*
* @param[in] index IVF-PQ index (passed by reference)
* @param[in] label list ID
*/
template <typename IdxT>
auto get_list_size_in_bytes(const index<IdxT>& index, uint32_t label) -> uint32_t
{
RAFT_EXPECTS(label < index.n_lists(),
"Expected label to be less than number of lists in the index");
auto list_data = index.lists()[label]->data;
return list_data.size();
}

/**
* @brief Helper exposing the re-computation of list sizes and related arrays if IVF lists have been
* modified.
Expand Down
24 changes: 24 additions & 0 deletions cpp/include/raft/neighbors/ivf_pq_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,30 @@ struct index : ann::index {
return centers_rot_.view();
}

/** fetch size of a particular IVF list in bytes using the list extents.
* Usage example:
* @code{.cpp}
* raft::resources res;
* // use default index params
* ivf_pq::index_params index_params;
* // extend the IVF lists while building the index
* index_params.add_data_on_build = true;
* // create and fill the index from a [N, D] dataset
* auto index = raft::neighbors::ivf_pq::build<int64_t>(res, index_params, dataset, N, D);
* // Fetch the size of the fourth list
* uint32_t size = index.get_list_size_in_bytes(3);
* @endcode
*
* @param[in] label list ID
*/
inline auto get_list_size_in_bytes(uint32_t label) -> uint32_t
{
RAFT_EXPECTS(label < this->n_lists(),
"Expected label to be less than number of lists in the index");
auto list_data = this->lists()[label]->data;
return list_data.size();
}

private:
raft::distance::DistanceType metric_;
codebook_gen codebook_kind_;
Expand Down

0 comments on commit 9841e6c

Please sign in to comment.