-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Use np.empty_like in PolynomialFeatures for NEP18 support #16196
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
Use np.empty_like in PolynomialFeatures for NEP18 support #16196
Conversation
It would be nice to find a solution to array creation that can take advantage of NEP 18. This is being looked at in NEP 35 numpy/numpy#14715 |
3b9cd3a
to
216fcaa
Compare
Thanks @thomasjpfan I'll take a look at that NEP I think the failure is unrelated (SpectralCoclustering) |
It should be fixed in master. |
Thanks, I'll rebase (and more changes coming)
(from mobile phone)
…On Sun, 26 Jan 2020, 11:19 Guillaume Lemaitre, ***@***.***> wrote:
I think the failure is unrelated (SpectralCoclustering)
It should be fixed in master.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#16196?email_source=notifications&email_token=AANPEPNEIQ4VGNNADTUADL3Q7VPSTA5CNFSM4KLLNLP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ5QNVI#issuecomment-578488021>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANPEPPMC7DNOKLWL65UKRLQ7VPSTANCNFSM4KLLNLPQ>
.
|
216fcaa
to
e88c8bf
Compare
shape for empty_like requires nump 1.17, is this an issue? |
That will be a problem since our minimum requirements for numpy are 1.11.0 With #15106 it will move to 1.13.3. |
Hmm, this is a blocker to move forward with nep13/18 support. Do you have any suggestions to be future compatible with numpy >= 1.17, for instance, try np.empty_like, but provide a fallback to np.empy for earlier versions. Is this generally accepted in sklearn? Maybe @amueller has some ideas as well, I believe he has some interest in nep13/nep18 support. |
for instance, try np.empty_like, but provide a fallback to np.empy for
earlier versions
We would usually paper over such compatibility issues in
sklearn.utils.fixes.
|
de610d2
to
1183d81
Compare
I did an attempt to implement empty_like in fixes.py, it is less simple than I hoped. It works on numpy < 1.17 by forwarding to np.empy or np.empty_like depending on the shape parameter and the type of array. For >= 1.17, it simply forwards to np.empty_like. The only loose end is order='K', but one could argue not to use that, and always specify 'C' or 'F' and maybe allow 'A'. |
Are there We will need dispatching for |
Yes, there is no need to fully backport empty_like, only the parts of it
that we intend to use.
|
From https://docs.scipy.org/doc/numpy/reference/routines.array-creation.html I can see I thought linspace could be an issue, but
I guess np.arange would be most common. Apart from whatever NEP will be the best way forward, do you think it makes sense to put array creation functions in a separate module (maybe not fixed.py)? |
If we adopt towards whatever NEP will succeed, maybe we should have a separate file just for helping implement the NEP, including array creation and other things (like scipy dispatch). Though right now it looks like we mostly do a backport, which is somewhat different from writing helpers. |
so, for instance, a stripped-down version of empty_like in this PR, plus some others, possible a range_like, etc, is that what you have in mind?
Never heard of this, does scipy have it's own dispatch mechanism? |
Sorry for being cryptic. No, it does not. But we often use scipy.linalg and we need to figure out in what cases we can use the |
1183d81
to
aae6e33
Compare
Indeed, I rely on monkey patching now, but it would be nice to for instance to try to use the NEP18 protocol for this. I gave it another refactor, a separate module for array creation function (implemented The downside of this approach is that it introduces another layer of indirection, which does not make it easier to read the source code. Using an API with the same name and similar behavior should help digest it I think. |
Regarding the |
So closing as superseded by array API work. |
Reference Issues/PRs
Followup of my quest to make vaex work with sklearn via NEP18 #14963 / vaexio/vaex#415
What does this implement/fix? Explain your changes.
PolynomialFeatures uses
np.empty
, if it uses np.empty_like, I can intercept it via NEP18, so that vaex can use this transformer.Any other comments?
I could push more of these changes on this branch, but I first want to see if this is what people like to see or not.