Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aamijar committed Jun 25, 2024
1 parent 5a4861a commit 88278d3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
3 changes: 1 addition & 2 deletions cpp/src/metrics/pairwise_distance_dice.cu
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

/*
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
* Copyright (c) 2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/metrics/pairwise_distance_dice.cuh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

/*
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
* Copyright (c) 2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
28 changes: 14 additions & 14 deletions python/cuml/manifold/umap_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,31 @@ def find_ab_params(spread, min_dist):


metric_parsing = {
"l2": DistanceType.L2SqrtUnexpanded,
"euclidean": DistanceType.L2SqrtUnexpanded,
"sqeuclidean": DistanceType.L2Unexpanded,
"cityblock": DistanceType.L1,
"l1": DistanceType.L1,
"manhattan": DistanceType.L1,
"taxicab": DistanceType.L1,
"minkowski": DistanceType.LpUnexpanded,
"canberra": DistanceType.Canberra,
"chebyshev": DistanceType.Linf,
"linf": DistanceType.Linf,
"cityblock": DistanceType.L1,
"cosine": DistanceType.CosineExpanded,
"correlation": DistanceType.CorrelationExpanded,
"hellinger": DistanceType.HellingerExpanded,
"dice": DistanceType.DiceExpanded,
"euclidean": DistanceType.L2SqrtUnexpanded,
"hamming": DistanceType.HammingUnexpanded,
"hellinger": DistanceType.HellingerExpanded,
"jaccard": DistanceType.JaccardExpanded,
"canberra": DistanceType.Canberra,
"dice": DistanceType.DiceExpanded,
"l1": DistanceType.L1,
"l2": DistanceType.L2SqrtUnexpanded,
"linf": DistanceType.Linf,
"manhattan": DistanceType.L1,
"minkowski": DistanceType.LpUnexpanded,
"sqeuclidean": DistanceType.L2Unexpanded,
"taxicab": DistanceType.L1,
}


DENSE_SUPPORTED_METRICS = [
DistanceType.Canberra,
DistanceType.CorrelationExpanded,
DistanceType.CosineExpanded,
DistanceType.DiceExpanded,
DistanceType.HammingUnexpanded,
DistanceType.HellingerExpanded,
# DistanceType.JaccardExpanded, # not supported
Expand All @@ -167,14 +168,14 @@ DENSE_SUPPORTED_METRICS = [
DistanceType.L2Unexpanded,
DistanceType.Linf,
DistanceType.LpUnexpanded,
DistanceType.DiceExpanded,
]


SPARSE_SUPPORTED_METRICS = [
DistanceType.Canberra,
DistanceType.CorrelationExpanded,
DistanceType.CosineExpanded,
DistanceType.DiceExpanded,
DistanceType.HammingUnexpanded,
DistanceType.HellingerExpanded,
DistanceType.JaccardExpanded,
Expand All @@ -183,5 +184,4 @@ SPARSE_SUPPORTED_METRICS = [
DistanceType.L2Unexpanded,
DistanceType.Linf,
DistanceType.LpUnexpanded,
DistanceType.DiceExpanded,
]
8 changes: 4 additions & 4 deletions python/cuml/metrics/pairwise_distances.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ PAIRWISE_DISTANCE_METRICS = {
"kldivergence": DistanceType.KLDivergence,
"russellrao": DistanceType.RusselRaoExpanded,
"nan_euclidean": DistanceType.L2Expanded,
"dice": DistanceType.DiceExpanded
"dice": DistanceType.DiceExpanded,
}

PAIRWISE_DISTANCE_SPARSE_METRICS = {
Expand All @@ -98,7 +98,7 @@ PAIRWISE_DISTANCE_SPARSE_METRICS = {
"jaccard": DistanceType.JaccardExpanded,
"hellinger": DistanceType.HellingerExpanded,
"chebyshev": DistanceType.Linf,
"dice": DistanceType.DiceExpanded
"dice": DistanceType.DiceExpanded,
}


Expand Down Expand Up @@ -345,7 +345,7 @@ def pairwise_distances(X, Y=None, metric="euclidean", handle=None,
if metric in ['nan_euclidean']:
return nan_euclidean_distances(X, Y, **kwds)

if metric in ['russellrao', 'dice'] and not np.all(X.data == 1.):
if metric in {'russellrao', 'dice'} and not np.all(X.data == 1.):
warnings.warn("X was converted to boolean for metric {}"
.format(metric))
X = np.where(X != 0., 1.0, 0.0)
Expand All @@ -368,7 +368,7 @@ def pairwise_distances(X, Y=None, metric="euclidean", handle=None,
if (n_samples_x == 1 or n_features_x == 1):
input_order = "K"

if metric in ['russellrao', 'dice'] and not np.all(Y.data == 1.):
if metric in {'russellrao', 'dice'} and not np.all(Y.data == 1.):
warnings.warn("Y was converted to boolean for metric {}"
.format(metric))
Y = np.where(Y != 0., 1.0, 0.0)
Expand Down

0 comments on commit 88278d3

Please sign in to comment.