Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Rapidsai Cuml DistanceType Enum

From Leeroopedia
Revision as of 16:26, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Rapidsai_Cuml_DistanceType_Enum.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Machine_Learning, Distance_Metrics
Last Updated 2026-02-08 12:00 GMT

Overview

Defines an enumeration of distance metric types used throughout the cuML library for specifying how distances between data points are computed.

Description

The ML::distance::DistanceType enum class provides a comprehensive set of distance and similarity metrics commonly used in machine learning algorithms. It includes Euclidean (L2), Manhattan (L1), cosine similarity, Minkowski (Lp), and many others. Each enumerator is assigned a unique integer value, enabling efficient selection of distance computation strategies at runtime. The enum resides in the ML::distance namespace and is referenced by clustering, nearest-neighbor, silhouette score, and pairwise distance APIs across cuML.

The special value Precomputed = 100 indicates that a precomputed distance matrix is provided rather than raw feature data, which avoids redundant computation when distances have already been calculated.

Usage

Use this enum whenever a cuML C++ API requires a distance metric parameter. It is passed to functions such as silhouette_score, pairwise_distance, and various clustering routines to select the desired distance computation. Import the header and specify the desired metric when calling these functions.

Code Reference

Source Location

  • Repository: Rapidsai_Cuml
  • File: cpp/include/cuml/common/distance_type.hpp

Signature

namespace ML::distance {

enum class DistanceType {
  L2Expanded          = 0,
  L2SqrtExpanded      = 1,
  CosineExpanded      = 2,
  L1                  = 3,
  L2Unexpanded        = 4,
  L2SqrtUnexpanded    = 5,
  InnerProduct        = 6,
  Linf                = 7,
  Canberra            = 8,
  LpUnexpanded        = 9,
  CorrelationExpanded = 10,
  JaccardExpanded     = 11,
  HellingerExpanded   = 12,
  Haversine           = 13,
  BrayCurtis          = 14,
  JensenShannon       = 15,
  HammingUnexpanded   = 16,
  KLDivergence        = 17,
  RusselRaoExpanded   = 18,
  DiceExpanded        = 19,
  BitwiseHamming      = 20,
  Precomputed         = 100
};

}  // end namespace ML::distance

Import

#include <cuml/common/distance_type.hpp>

I/O Contract

Inputs

Name Type Required Description
(N/A -- this is an enum definition)

Outputs

Name Type Description
DistanceType enum class (int) An enumerator value representing the chosen distance metric.

Enum Values

Enumerator Value Description
L2Expanded 0 Squared L2 (Euclidean) distance, expanded form
L2SqrtExpanded 1 L2 (Euclidean) distance (square root of L2Expanded)
CosineExpanded 2 Cosine distance (1 - cosine similarity)
L1 3 Manhattan (L1) distance
L2Unexpanded 4 Squared L2 distance, unexpanded form
L2SqrtUnexpanded 5 L2 distance, unexpanded form
InnerProduct 6 Inner (dot) product
Linf 7 Chebyshev (L-infinity) distance
Canberra 8 Canberra distance
LpUnexpanded 9 Minkowski (Lp) distance, unexpanded form
CorrelationExpanded 10 Correlation distance
JaccardExpanded 11 Jaccard distance
HellingerExpanded 12 Hellinger distance
Haversine 13 Haversine distance for geographical coordinates
BrayCurtis 14 Bray-Curtis distance
JensenShannon 15 Jensen-Shannon divergence
HammingUnexpanded 16 Hamming distance
KLDivergence 17 Kullback-Leibler divergence
RusselRaoExpanded 18 Russell-Rao distance
DiceExpanded 19 Dice distance
BitwiseHamming 20 Bitwise Hamming distance
Precomputed 100 Indicates a precomputed distance matrix is provided

Usage Examples

#include <cuml/common/distance_type.hpp>
#include <cuml/metrics/metrics.hpp>
#include <raft/core/handle.hpp>

void compute_pairwise() {
    raft::handle_t handle;

    // Assume x and y are device pointers to feature matrices,
    // dist is a device pointer to the output distance matrix.
    float* x = /* ... */;
    float* y = /* ... */;
    float* dist = /* ... */;
    int m = 100, n = 200, k = 50;

    // Compute pairwise L2 (Euclidean) distances
    ML::Metrics::pairwise_distance(
        handle, x, y, dist, m, n, k,
        ML::distance::DistanceType::L2SqrtExpanded,
        true  // row-major
    );
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment