-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[WIP] NEP-18 support for preprocessing algorithms #17744
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For cupy, I do not think we need to explicitly dispatch:
import cupy as cp
import numpy as np
X_cp = cp.ones(10)
# uses np.zeros_like
X_cp_zeros = np.zeros_like(X_cp)
type(X_cp_zeros)
# cupy.core.core.ndarray
|
||
scaler = MinMaxScaler(copy=True) | ||
t_X_cp = scaler.fit_transform(X_cp) | ||
assert type(t_X_cp) == type(X_cp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also check that the min and max values of t_X_cp
are 0 and 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
scaler = MinMaxScaler(copy=True) | ||
t_X_np = scaler.fit_transform(X_np) | ||
|
||
t_X_cp = cp.asnumpy(t_X_cp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed? Doesn't assert_almost_equal
(or better assert_allclose
) work with cupy arrays directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem to work.
|
||
empty_like = create_like(np.empty, np.empty_like) | ||
zeros_like = create_like(np.zeros, np.zeros_like) | ||
ones_like = create_like(np.ones, np.ones_like) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that NEP-35 has been accepted this could could be simplified (on the dev version of numpy):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would still need a similar hack as a backword compat (e.g. in sklearn/utils/fixes.py) to make it work for older versions of numpy, but we should definitely use the actual NEP-35 implementation on numpy versions that support it.
Now that #22554 was merged, I think we might want to close this issue in favor of a new implementation based on the Array API spec instead. WDYT? |
Closing this PR since we are going forward with the array API to solve this type of issue. |
Reference Issues/PRs
This PR completes the existing experimental attempt to support NEP-18, see #16196
What does this implement/fix? Explain your changes.
create_like
to support CuPy arrays