Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added LinearOperator support in safe_sparse_dot() #16463

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion doc/whats_new/v0.23.rst
Expand Up @@ -341,7 +341,8 @@ Changelog
pandas sparse DataFrame.
:pr:`16021` by :user:`Rushabh Vasani <rushabh-v>`.

- |Feature| :func:`utils.extmath.randomized_svd` now accepts
- |Feature| :func:`utils.extmath.randomized_svd` and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are still failing. Also please add a test for randomized_svd on a LinearOperator.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The test added

:func:`utils.extmath.safe_dot_product` now accepts
:class:`scipy.sparse.linalg.LinearOperator` as argument.
:pr:`#16463` by :user:`Pavel V. Stishenko <Mazay0>`.

Expand Down
11 changes: 6 additions & 5 deletions sklearn/utils/tests/test_extmath.py
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from scipy import sparse
from scipy import linalg
from scipy.sparse.linalg import aslinearoperator
from scipy.sparse.linalg import LinearOperator
from scipy import stats
from scipy.special import expit

Expand Down Expand Up @@ -730,14 +730,15 @@ def test_safe_sparse_dot_operator():
A = rng.random_sample((10, 20))
B = rng.random_sample((20, 30))
expected = np.dot(A, B)
A = aslinearoperator(A)
actual = safe_sparse_dot(A, B)
op = LinearOperator(A.shape, matvec=lambda x: np.dot(A, x))
actual = safe_sparse_dot(op, B)
assert_allclose(actual, expected)

# ndarray @ LinearOperator
A = rng.random_sample((10, 20))
B = rng.random_sample((20, 30))
expected = np.dot(A, B)
B = aslinearoperator(B)
actual = safe_sparse_dot(A, B)
op = LinearOperator(B.shape, matvec=lambda x: np.dot(B, x),
rmatvec=lambda x: np.dot(B.T, x))
actual = safe_sparse_dot(A, op)
assert_allclose(actual, expected)