Ensure metric checks allow for sparse custom metrics
@@ -1582,6 +1582,10 @@ class UMAP(BaseEstimator):
# if checking the manifold distance metric, simulate some data on a
# reasonable interval with output dimensionality
x, y = np.random.uniform(low=-10, high=10, size=(2, self.n_components))
+
+ if scipy.sparse.issparse(data):
+ metric_out = metric(x.indices, x.data, y.indices, y.data, **kwds)
+ else:
metric_out = metric(x, y, **kwds)
# True if metric returns iterable of length 2, False otherwise
return hasattr(metric_out, "__iter__") and len(metric_out) == 2
