The vector search and clustering algorithms in RAFT are being migrated to a new library dedicated to vector search called cuVS. We will continue to support the vector search algorithms in RAFT during this move, but will no longer update them after the RAPIDS 24.06 (June) release. We plan to complete the migration by RAPIDS 24.08 (August) release.

Pairwise Distance#

#include <raft/distance/distance.cuh>

namespace raft::distance

template<raft::distance::DistanceType DistT, typename DataT, typename AccT, typename OutT, typename layout = raft::layout_c_contiguous, typename IdxT = int>
void distance(raft::resources const &handle, raft::device_matrix_view<DataT, IdxT, layout> const x, raft::device_matrix_view<DataT, IdxT, layout> const y, raft::device_matrix_view<OutT, IdxT, layout> dist, DataT metric_arg = 2.0f)#

Evaluate pairwise distances for the simple use case.

Note: Only contiguous row- or column-major layouts supported currently.

Usage example:

#include <raft/core/resources.hpp>
#include <raft/core/device_mdarray.hpp>
#include <raft/random/make_blobs.cuh>
#include <raft/distance/distance.cuh>

raft::raft::resources handle;
int n_samples = 5000;
int n_features = 50;

auto input = raft::make_device_matrix<float>(handle, n_samples, n_features);
auto labels = raft::make_device_vector<int>(handle, n_samples);
auto output = raft::make_device_matrix<float>(handle, n_samples, n_samples);

raft::random::make_blobs(handle, input.view(), labels.view());
auto metric = raft::distance::DistanceType::L2SqrtExpanded;
raft::distance::pairwise_distance(handle, input.view(), input.view(), output.view(), metric);

Template Parameters:
  • DistanceType – which distance to evaluate

  • DataT – input argument type

  • AccT – accumulation type

  • OutT – output type

  • IdxT – Index type

  • handle – raft handle for managing expensive resources

  • x – first set of points (size n*k)

  • y – second set of points (size m*k)

  • dist – output distance matrix (size n*m)

  • metric_arg – metric argument (used for Minkowski distance)

template<typename Type, typename layout = layout_c_contiguous, typename IdxT = int>
void pairwise_distance(raft::resources const &handle, device_matrix_view<Type, IdxT, layout> const x, device_matrix_view<Type, IdxT, layout> const y, device_matrix_view<Type, IdxT, layout> dist, raft::distance::DistanceType metric, Type metric_arg = 2.0f)#

Convenience wrapper around ‘distance’ prim to convert runtime metric into compile time for the purpose of dispatch.

Template Parameters:
  • Type – input/accumulation/output data-type

  • IdxT – indexing type

  • handle – raft handle for managing expensive resources

  • x – first matrix of points (size mxk)

  • y – second matrix of points (size nxk)

  • dist – output distance matrix (size mxn)

  • metric – distance metric

  • metric_arg – metric argument (used for Minkowski distance)