Skip to content

Commit

Permalink
Adjust deprecated cupy.sparse usage (#5867)
Browse files Browse the repository at this point in the history
Split from #5799

`cupy.sparse` is deprecated in favor of `cupyx.scipy.sparse`

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Dante Gama Dessavre (https://github.com/dantegd)

URL: #5867
  • Loading branch information
mroeschke authored Apr 25, 2024
1 parent 2842427 commit 4394a2e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions python/cuml/manifold/simpl_set.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-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 All @@ -20,6 +20,7 @@ from cuml.internals.safe_imports import cpu_only_import
np = cpu_only_import('numpy')
from cuml.internals.safe_imports import gpu_only_import
cp = gpu_only_import('cupy')
cupyx = gpu_only_import('cupyx')

from cuml.manifold.umap_utils cimport *
from cuml.manifold.umap_utils import GraphHolder, find_ab_params, \
Expand Down Expand Up @@ -350,8 +351,8 @@ def simplicial_set_embedding(

graph = graph.tocoo()
graph.sum_duplicates()
if not isinstance(graph, cp.sparse.coo_matrix):
graph = cp.sparse.coo_matrix(graph)
if not isinstance(graph, cupyx.scipy.sparse.coo_matrix):
graph = cupyx.scipy.sparse.coo_matrix(graph)

handle = Handle()
cdef handle_t* handle_ = <handle_t*><size_t>handle.getHandle()
Expand Down
5 changes: 3 additions & 2 deletions python/cuml/manifold/umap_utils.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-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 All @@ -25,6 +25,7 @@ from cuml.internals.safe_imports import cpu_only_import
np = cpu_only_import('numpy')
from cuml.internals.safe_imports import gpu_only_import
cp = gpu_only_import('cupy')
cupyx = gpu_only_import('cupyx')


cdef class GraphHolder:
Expand Down Expand Up @@ -102,7 +103,7 @@ cdef class GraphHolder:
rows = create_nonowning_cp_array(self.rows(), np.int32)
cols = create_nonowning_cp_array(self.cols(), np.int32)

return cp.sparse.coo_matrix(((vals, (rows, cols))))
return cupyx.scipy.sparse.coo_matrix(((vals, (rows, cols))))

def __dealloc__(self):
self.c_graph.reset(NULL)
Expand Down
5 changes: 3 additions & 2 deletions python/cuml/tests/test_simpl_set.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-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 Expand Up @@ -27,6 +27,7 @@

np = cpu_only_import("numpy")
cp = gpu_only_import("cupy")
cupyx = gpu_only_import("cupyx")


IS_ARM = platform.processor() == "aarch64"
Expand Down Expand Up @@ -111,7 +112,7 @@ def test_fuzzy_simplicial_set(
)[0].tocoo()

cu_fss_graph = cu_fss_graph.todense()
ref_fss_graph = cp.sparse.coo_matrix(ref_fss_graph).todense()
ref_fss_graph = cupyx.scipy.sparse.coo_matrix(ref_fss_graph).todense()
assert correctness_sparse(
ref_fss_graph, cu_fss_graph, atol=0.1, rtol=0.2, threshold=0.95
)
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/tests/test_umap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-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 Expand Up @@ -667,7 +667,7 @@ def test_fuzzy_simplicial_set(n_rows, n_features, n_neighbors):
ref_fss_graph = model.graph_

cu_fss_graph = cu_fss_graph.todense()
ref_fss_graph = cp.sparse.coo_matrix(ref_fss_graph).todense()
ref_fss_graph = cupyx.scipy.sparse.coo_matrix(ref_fss_graph).todense()
assert correctness_sparse(
ref_fss_graph, cu_fss_graph, atol=0.1, rtol=0.2, threshold=0.95
)
Expand Down

0 comments on commit 4394a2e

Please sign in to comment.