Skip to content

Commit 4338268

Browse files
authored
[MNT] Small NumPy 2 related fixes (#5954)
This applies some smaller NumPy 2 related fixes. With (in progress) cupy 13.2 fixups, the single gpu test suite seems to be doing mostly fine. There is a single test remaining: ``` test_simpl_set.py::test_simplicial_set_embedding ``` is failing with: ``` (Pdb) cp.asarray(cu_embedding) array([[23067.518, 23067.518], [17334.559, 17334.559], [22713.598, 22713.598], ..., [23238.438, 23238.438], [25416.912, 25416.912], [19748.943, 19748.943]], dtype=float32) ``` being completely different from the reference: ``` array([[5.330462 , 4.3419437], [4.1822557, 5.6225405], [5.200859 , 4.530094 ], ..., [4.852359 , 5.0026293], [5.361374 , 4.1475334], [4.0259256, 5.7187223]], dtype=float32) ``` And I am not sure why that might be, I will prod it a bit more, but it may need someone who knows the methods to have a look. One wrinkle is that hdbscan is not yet released for NumPy 2, but I guess that still required even though sklearn has a version? (Probably, not a big issue, but my fixups scikit-learn-contrib/hdbscan#644 run into some issue even though it doesn't seem NumPy 2 related.) xref: rapidsai/build-planning#38 Authors: - Sebastian Berg (https://github.com/seberg) - https://github.com/jakirkham - Dante Gama Dessavre (https://github.com/dantegd) Approvers: - Kyle Edwards (https://github.com/KyleFromNVIDIA) - Dante Gama Dessavre (https://github.com/dantegd) URL: #5954
1 parent d4535d2 commit 4338268

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ repos:
7373
setup[.]cfg$
7474
exclude: |
7575
(?x)
76-
cpp/src/tsne/cannylab/bh[.]cu$
76+
cpp/src/tsne/cannylab/bh[.]cu$|
77+
python/cuml/cuml/_thirdparty
7778
- id: verify-alpha-spec
7879
- repo: https://github.com/rapidsai/dependency-file-generator
7980
rev: v1.13.11

python/cuml/cuml/_thirdparty/sklearn/utils/sparsefuncs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def _sparse_min_or_max(X, axis, min_or_max):
214214
if np.isnan(m):
215215
if 'nan' in min_or_max:
216216
m = 0
217-
elif X.nnz != cpu_np.product(X.shape):
217+
elif X.nnz != cpu_np.prod(X.shape):
218218
if 'min' in min_or_max:
219219
m = m if m <= 0 else 0
220220
else:

python/cuml/cuml/internals/array.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,12 +1163,16 @@ def from_input(
11631163
if (
11641164
not fail_on_order and order != arr.order and order != "K"
11651165
) or make_copy:
1166-
arr = cls(
1167-
arr.mem_type.xpy.array(
1168-
arr.to_output("array"), order=order, copy=make_copy
1169-
),
1170-
index=index,
1171-
)
1166+
if make_copy:
1167+
data = arr.mem_type.xpy.array(
1168+
arr.to_output("array"), order=order
1169+
)
1170+
else:
1171+
data = arr.mem_type.xpy.asarray(
1172+
arr.to_output("array"), order=order
1173+
)
1174+
1175+
arr = cls(data, index=index)
11721176

11731177
n_rows = arr.shape[0]
11741178

python/cuml/cuml/tests/test_make_classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
2+
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -115,7 +115,7 @@ def test_make_classification_informative_features():
115115

116116
# Cluster by sign, viewed as strings to allow uniquing
117117
signs = np.sign(cp.asnumpy(X))
118-
signs = signs.view(dtype="|S{0}".format(signs.strides[0]))
118+
signs = signs.view(dtype="|S{0}".format(signs.strides[0])).ravel()
119119
unique_signs, cluster_index = np.unique(signs, return_inverse=True)
120120

121121
assert (

python/cuml/cuml/tests/test_metrics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ def test_pairwise_distances(metric: str, matrix_size, is_col_major):
10651065
cp.testing.assert_array_almost_equal(S, S2, decimal=compare_precision)
10661066

10671067
# Change precision of one parameter
1068-
Y = np.asfarray(Y, dtype=np.float32)
1068+
Y = np.asarray(Y, dtype=np.float32)
10691069
S = pairwise_distances(X, Y, metric=metric)
10701070
S2 = ref_dense_pairwise_dist(X, Y, metric=metric)
10711071
cp.testing.assert_array_almost_equal(S, S2, decimal=compare_precision)
@@ -1074,8 +1074,8 @@ def test_pairwise_distances(metric: str, matrix_size, is_col_major):
10741074
compare_precision = 2
10751075

10761076
# Change precision of both parameters to float
1077-
X = np.asfarray(X, dtype=np.float32)
1078-
Y = np.asfarray(Y, dtype=np.float32)
1077+
X = np.asarray(X, dtype=np.float32)
1078+
Y = np.asarray(Y, dtype=np.float32)
10791079
S = pairwise_distances(X, Y, metric=metric)
10801080
S2 = ref_dense_pairwise_dist(X, Y, metric=metric)
10811081
cp.testing.assert_array_almost_equal(S, S2, decimal=compare_precision)
@@ -1132,8 +1132,8 @@ def test_pairwise_distances_sklearn_comparison(metric: str, matrix_size):
11321132
# For fp32, compare at 4 decimals, (3 places less than the ~7 max)
11331133
compare_precision = 4
11341134

1135-
X = np.asfarray(X, dtype=np.float32)
1136-
Y = np.asfarray(Y, dtype=np.float32)
1135+
X = np.asarray(X, dtype=np.float32)
1136+
Y = np.asarray(Y, dtype=np.float32)
11371137

11381138
# Compare to sklearn, fp32
11391139
S = pairwise_distances(X, Y, metric=metric)
@@ -1228,7 +1228,7 @@ def test_pairwise_distances_exceptions():
12281228

12291229
X_int = rng.randint(10, size=(5, 4))
12301230
X_double = rng.random_sample((5, 4))
1231-
X_float = np.asfarray(X_double, dtype=np.float32)
1231+
X_float = np.asarray(X_double, dtype=np.float32)
12321232
X_bool = rng.choice([True, False], size=(5, 4))
12331233

12341234
# Test int inputs (only float/double accepted at this time)

python/cuml/cuml/tests/test_umap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ def get_embedding(n_components, random_state):
420420
)
421421
return reducer.fit_transform(data, convert_dtype=True)
422422

423-
state = copy.copy(random_state)
423+
state = copy.deepcopy(random_state)
424424
cuml_embedding1 = get_embedding(n_components, state)
425-
state = copy.copy(random_state)
425+
state = copy.deepcopy(random_state)
426426
cuml_embedding2 = get_embedding(n_components, state)
427427

428428
assert not np.isnan(cuml_embedding1).any()
@@ -475,9 +475,9 @@ def get_embedding(n_components, random_state):
475475
reducer.fit(fit_data, convert_dtype=True)
476476
return reducer.transform(transform_data, convert_dtype=True)
477477

478-
state = copy.copy(random_state)
478+
state = copy.deepcopy(random_state)
479479
cuml_embedding1 = get_embedding(n_components, state)
480-
state = copy.copy(random_state)
480+
state = copy.deepcopy(random_state)
481481
cuml_embedding2 = get_embedding(n_components, state)
482482

483483
assert not np.isnan(cuml_embedding1).any()

0 commit comments

Comments
 (0)