Skip to content

[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

Closed

Conversation

viclafargue
Copy link

@viclafargue viclafargue commented Jun 26, 2020

Reference Issues/PRs

This PR completes the existing experimental attempt to support NEP-18, see #16196

What does this implement/fix? Explain your changes.

  • Modify create_like to support CuPy arrays
  • Modify a few parts of some preprocessing algorithms for NEP-18 support
  • Add CuPy tests for some preprocessing algorithms

Copy link
Member

@thomasjpfan thomasjpfan left a 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)
Copy link
Member

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.

Copy link
Author

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)
Copy link
Member

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?

Copy link
Author

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)
Copy link
Member

@ogrisel ogrisel Nov 4, 2020

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):

numpy/numpy#16935

Copy link
Member

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.

Base automatically changed from master to main January 22, 2021 10:52
@ogrisel
Copy link
Member

ogrisel commented Oct 10, 2022

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?

@glemaitre
Copy link
Member

Closing this PR since we are going forward with the array API to solve this type of issue.

@glemaitre glemaitre closed this Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants