Distance#

This page provides C++ class references for the publicly-exposed elements of the cuvs/distance package. cuVS’s distances have been highly optimized and support a wide assortment of different distance measures.

Distance Types#

#include <cuvs/distance/distance.hpp>

namespace cuvs::distance

Warning

doxygenenum: Cannot find enum “cuvs::distance::DistanceType” in doxygen xml output for project “cuvs” from directory: ../../cpp/doxygen/_xml/

Pairwise Distances#

include <cuvs/distance/distance.hpp>

namespace cuvs::distance

void pairwise_distance(raft::resources const &handle, raft::device_matrix_view<const float, std::int64_t, raft::layout_c_contiguous> const x, raft::device_matrix_view<const float, std::int64_t, raft::layout_c_contiguous> const y, raft::device_matrix_view<float, std::int64_t, raft::layout_c_contiguous> dist, cuvs::distance::DistanceType metric, float metric_arg = 2.0f)#

Compute pairwise distances for two matrices.

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

Usage example:

#include <raft/core/resources.hpp>
#include <raft/core/device_mdarray.hpp>
#include <cuvs/distance/distance.hpp>

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

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

// ... fill input with data ...

auto output = raft::make_device_matrix<float>(handle, n_samples, n_samples);

auto metric = cuvs::distance::DistanceType::L2SqrtExpanded;
cuvs::distance::pairwise_distance(handle,
                                  raft::make_const(input.view()),
                                  raft::make_const(input.view()),
                                  output.view(),
                                  metric);

Parameters:
  • handle[in] raft handle for managing expensive resources

  • x[in] first set of points (size n*k)

  • y[in] second set of points (size m*k)

  • dist[out] output distance matrix (size n*m)

  • metric[in] distance to evaluate

  • metric_arg[in] metric argument (used for Minkowski distance)

void pairwise_distance(raft::resources const &handle, raft::device_matrix_view<const double, std::int64_t, raft::layout_c_contiguous> const x, raft::device_matrix_view<const double, std::int64_t, raft::layout_c_contiguous> const y, raft::device_matrix_view<double, std::int64_t, raft::layout_c_contiguous> dist, cuvs::distance::DistanceType metric, double metric_arg = 2.0f)#

Compute pairwise distances for two matrices.

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

Usage example:

#include <raft/core/resources.hpp>
#include <raft/core/device_mdarray.hpp>
#include <cuvs/distance/distance.hpp>

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

auto input = raft::make_device_matrix<double>(handle, n_samples, n_features);

// ... fill input with data ...

auto output = raft::make_device_matrix<double>(handle, n_samples, n_samples);

auto metric = cuvs::distance::DistanceType::L2SqrtExpanded;
cuvs::distance::pairwise_distance(handle,
                                  raft::make_const(input.view()),
                                  raft::make_const(input.view()),
                                  output.view(),
                                  metric);

Parameters:
  • handle[in] raft handle for managing expensive resources

  • x[in] first set of points (size n*k)

  • y[in] second set of points (size m*k)

  • dist[out] output distance matrix (size n*m)

  • metric[in] distance to evaluate

  • metric_arg[in] metric argument (used for Minkowski distance)

void pairwise_distance(raft::resources const &handle, raft::device_matrix_view<const half, std::int64_t, raft::layout_c_contiguous> const x, raft::device_matrix_view<const half, std::int64_t, raft::layout_c_contiguous> const y, raft::device_matrix_view<float, std::int64_t, raft::layout_c_contiguous> dist, cuvs::distance::DistanceType metric, float metric_arg = 2.0f)#

Compute pairwise distances for two matrices.

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

Usage example:

#include <raft/core/resources.hpp>
#include <raft/core/device_mdarray.hpp>
#include <cuvs/distance/distance.hpp>

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

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

// ... fill input with data ...

auto output = raft::make_device_matrix<float>(handle, n_samples, n_samples);

auto metric = cuvs::distance::DistanceType::L2SqrtExpanded;
cuvs::distance::pairwise_distance(handle,
                                  raft::make_const(input.view()),
                                  raft::make_const(input.view()),
                                  output.view(),
                                  metric);

Parameters:
  • handle[in] raft handle for managing expensive resources

  • x[in] first set of points (size n*k)

  • y[in] second set of points (size m*k)

  • dist[out] output distance matrix (size n*m)

  • metric[in] distance to evaluate

  • metric_arg[in] metric argument (used for Minkowski distance)

void pairwise_distance(raft::resources const &handle, raft::device_matrix_view<const float, std::int64_t, raft::layout_f_contiguous> const x, raft::device_matrix_view<const float, std::int64_t, raft::layout_f_contiguous> const y, raft::device_matrix_view<float, std::int64_t, raft::layout_f_contiguous> dist, cuvs::distance::DistanceType metric, float metric_arg = 2.0f)#

Compute pairwise distances for two matrices.

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

Usage example:

#include <raft/core/resources.hpp>
#include <raft/core/device_mdarray.hpp>
#include <cuvs/distance/distance.hpp>

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

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

// ... fill input with data ...

auto output = raft::make_device_matrix<float>(handle, n_samples, n_samples);

auto metric = cuvs::distance::DistanceType::L2SqrtExpanded;
cuvs::distance::pairwise_distance(handle,
                                  raft::make_const(input.view()),
                                  raft::make_const(input.view()),
                                  output.view(),
                                  metric);

Parameters:
  • handle[in] raft handle for managing expensive resources

  • x[in] first set of points (size n*k)

  • y[in] second set of points (size m*k)

  • dist[out] output distance matrix (size n*m)

  • metric[in] distance to evaluate

  • metric_arg[in] metric argument (used for Minkowski distance)

void pairwise_distance(raft::resources const &handle, raft::device_matrix_view<const double, std::int64_t, raft::layout_f_contiguous> const x, raft::device_matrix_view<const double, std::int64_t, raft::layout_f_contiguous> const y, raft::device_matrix_view<double, std::int64_t, raft::layout_f_contiguous> dist, cuvs::distance::DistanceType metric, double metric_arg = 2.0f)#

Compute pairwise distances for two matrices.

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

Usage example:

#include <raft/core/resources.hpp>
#include <raft/core/device_mdarray.hpp>
#include <cuvs/distance/distance.hpp>

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

auto input = raft::make_device_matrix<double>(handle, n_samples, n_features);

// ... fill input with data ...

auto output = raft::make_device_matrix<double>(handle, n_samples, n_samples);

auto metric = cuvs::distance::DistanceType::L2SqrtExpanded;
cuvs::distance::pairwise_distance(handle,
                                  raft::make_const(input.view()),
                                  raft::make_const(input.view()),
                                  output.view(),
                                  metric);

Parameters:
  • handle[in] raft handle for managing expensive resources

  • x[in] first set of points (size n*k)

  • y[in] second set of points (size m*k)

  • dist[out] output distance matrix (size n*m)

  • metric[in] distance to evaluate

  • metric_arg[in] metric argument (used for Minkowski distance)

void pairwise_distance(raft::resources const &handle, raft::device_matrix_view<const half, std::int64_t, raft::layout_f_contiguous> const x, raft::device_matrix_view<const half, std::int64_t, raft::layout_f_contiguous> const y, raft::device_matrix_view<float, std::int64_t, raft::layout_f_contiguous> dist, cuvs::distance::DistanceType metric, float metric_arg = 2.0f)#

Compute pairwise distances for two matrices.

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

Usage example:

#include <raft/core/resources.hpp>
#include <raft/core/device_mdarray.hpp>
#include <cuvs/distance/distance.hpp>

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

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

// ... fill input with data ...

auto output = raft::make_device_matrix<float>(handle, n_samples, n_samples);

auto metric = cuvs::distance::DistanceType::L2SqrtExpanded;
cuvs::distance::pairwise_distance(handle,
                                  raft::make_const(input.view()),
                                  raft::make_const(input.view()),
                                  output.view(),
                                  metric);

Parameters:
  • handle[in] raft handle for managing expensive resources

  • x[in] first set of points (size n*k)

  • y[in] second set of points (size m*k)

  • dist[out] output distance matrix (size n*m)

  • metric[in] distance to evaluate

  • metric_arg[in] metric argument (used for Minkowski distance)