Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cpp/src/pca/pca_mg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ void fit_impl(raft::handle_t& handle,
n_streams,
true);
} else {
for (std::uint32_t i = 0; i < n_streams; i++) {
handle.sync_stream(streams[i]);
}
signFlipComponents(handle,
input_data[0]->ptr,
components,
Expand Down Expand Up @@ -191,6 +194,9 @@ void fit_impl(raft::handle_t& handle,
n_streams,
true);
} else {
for (std::uint32_t i = 0; i < n_streams; i++) {
handle.sync_stream(streams[i]);
}
signFlipComponents(h,
input_data[0]->ptr,
vMatrix.data(),
Expand Down
5 changes: 1 addition & 4 deletions python/cuml/cuml/decomposition/pca_mg.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
#

import numpy as np
import sklearn
from packaging.version import Version

import cuml.internals
from cuml.decomposition import PCA
Expand Down Expand Up @@ -94,7 +91,7 @@ class PCAMG(BaseDecompositionMG, PCA):
cdef uintptr_t noise_variance_ptr = noise_variance.ptr
cdef bool use_float32 = (dtype == np.float32)
cdef handle_t* handle_ = <handle_t*><size_t>self.handle.getHandle()
cdef bool flip_signs_based_on_U = (Version(sklearn.__version__) < Version("1.5.0"))
cdef bool flip_signs_based_on_U = self._u_based_sign_flip

# Perform fit
with nogil:
Expand Down
5 changes: 1 addition & 4 deletions python/cuml/cuml/decomposition/tsvd_mg.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
#

import numpy as np
import sklearn
from packaging.version import Version

import cuml.internals
from cuml.decomposition import TruncatedSVD
Expand Down Expand Up @@ -100,7 +97,7 @@ class TSVDMG(BaseDecompositionMG, TruncatedSVD):
cdef uintptr_t singular_values_ptr = singular_values.ptr
cdef bool use_float32 = dtype == np.float32
cdef handle_t* handle_ = <handle_t*><size_t>self.handle.getHandle()
cdef bool flip_signs_based_on_U = (Version(sklearn.__version__) < Version("1.5.0"))
cdef bool flip_signs_based_on_U = self._u_based_sign_flip

# Perform Fit
with nogil:
Expand Down
8 changes: 6 additions & 2 deletions python/cuml/tests/dask/test_dask_pca.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
#

import cupy as cp
import numpy as np
import pytest
import sklearn
from packaging.version import Version

from cuml.dask.common.dask_arr_utils import to_dask_cudf

SKLEARN_GE_1_5_0 = Version(sklearn.__version__) >= Version("1.5.0")


@pytest.mark.mg
@pytest.mark.parametrize("nrows", [1000])
Expand Down Expand Up @@ -56,11 +59,12 @@ def test_pca_fit(nrows, ncols, n_parts, input_type, client):
]

for attr in all_attr:
with_sign = SKLEARN_GE_1_5_0 if attr == "components_" else True
cuml_res = getattr(cupca, attr)
if type(cuml_res) is np.ndarray:
cuml_res = cuml_res.to_numpy()
skl_res = getattr(skpca, attr)
assert array_equal(cuml_res, skl_res, 1e-1, with_sign=True)
assert array_equal(cuml_res, skl_res, 1e-1, with_sign=with_sign)


@pytest.mark.mg
Expand Down
8 changes: 8 additions & 0 deletions python/cuml/tests/dask/test_dask_tsvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import cupy as cp
import numpy as np
import pytest
import sklearn
from packaging.version import Version

from cuml.dask.common.dask_arr_utils import to_dask_cudf
from cuml.testing.utils import array_equal, stress_param, unit_param

SKLEARN_GE_1_5_0 = Version(sklearn.__version__) >= Version("1.5.0")


@pytest.mark.mg
@pytest.mark.parametrize(
Expand Down Expand Up @@ -73,6 +77,10 @@ def test_tsvd_fit(data_info, input_type, client):
skl_res = getattr(sktsvd, attr)
if attr == "singular_values_":
assert array_equal(cuml_res, skl_res, 1, with_sign=True)
elif attr == "components_":
assert array_equal(
cuml_res, skl_res, 1e-1, with_sign=SKLEARN_GE_1_5_0
)
else:
assert array_equal(cuml_res, skl_res, 1e-1, with_sign=True)

Expand Down