-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Other *_like creation functions #14441
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
Comments
So you're looking for some shorthand for, e.g.,
? |
Not exactly no. We are looking for something like this. np.linspace_like(x, 0, 1, 0.1) Where |
I'm not sure that that makes sense. If |
Seems to me that the "default" numpy implementation just has to raise an error if |
@seberg then this becomes a very weird thing - we add a I think this is a variation of " |
I am not saying I like the idea :), although not ruling out that hiding them away somewhere for library users may actually be a practical solution. Of course that is what NEP 31 is about, but that does not mean alternatives may not exist. It may be worth spelling out how this is expected to work for libraries. Since it could be nice if NEP 31 can help libraries to write such an implicit choice/return:
|
the library would simply write:
and the user would write:
Of course. But then we need a real proposal. "we need a few more", and then "another few", and then still have incomplete coverage is problematic. We have a lot of array creation functions: https://numpy.org/devdocs/reference/routines.array-creation.html |
Yes, NEP 31 is all about explict opt-in (which is good). I am wondering if we can and should allow library authors to not force that explicit opt-in on the end user. This is what Anyway, sorry. I really just wanted to clarify how I think I understood the request, this is getting way too much discussion about NEP 31 and explicit opt-in vs. "array-like" type behaviour. |
Actually it would be nice to complete this proposal, so we can compare with the alternative proposal. I think the only thing that makes sense is to add a
It seems like you're asking to have both opt-in and default at the same time. In general, I think it's one or the other.
|
I don't think that's true. For example, I wrote this code for np.cumsum(np.ones_like(X, dtype="i8", shape=(n_samples,))) - 1 That said, writing this multiple times is not great. Also library authors generally don't like the lack of clarity in this code. An |
I do think Ralf is right though, having an issue about it is not all that helpful. We need an NEP (or a a bit more comprehensive write up+proposal), that discusses different options to solve this:
And I guess, what about arguments that one array like needs and another does not? Is it OK to ignore those? The original duck array NEP also lists a few other interesting points, such as checking whether a duck array/array-like can act as an |
I've also been wondering about another alternative. (note, not well thought out)
This issue basically proposes a workaround for array creation functions not having an array-like input. So perhaps that can be solved with such a hack, which is limited in scope, rather than doubling the number of array creation functions we offer (because that feels really wrong ...). |
Right, another option. My first gut feeling is to not do that, since it probably allows for scary scoping which is a risk that is probably unnecessary in this use case. As typically, I would love library authors to step in to at least co-champion proposals such as this, because they have better experience with their needs. |
This issue comes in hand with the ones I've been personally experiencing. Part of that is addressed with NEP-30 for duckarray, but there's still the open question for something like I agree that doubling all array creation functions is undesired, but what about providing a new optional argument |
Thanks @pentschev, I think a
I don't think that's the case. I tried using dispatch with SciPy functions (ref http://scipy.github.io/devdocs/roadmap.html#support-for-distributed-arrays-and-gpu-arrays) to see how far I could get with the current state of NumPy, and the answer was: not very far. Pretty much everywhere there's an |
If adding |
+1 adding like= arguments that support dispatching sounds like a nice
lightweight solution to me, definitely better than adding a bunch of new
functions.
…On Tue, Sep 10, 2019 at 8:47 AM jakirkham ***@***.***> wrote:
If adding like= keyword arguments is feasible, that would be helpful for
my use case as well.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14441?email_source=notifications&email_token=AAJJFVQYKEFK5DYZNTHUNB3QI66SNA5CNFSM4IUI4U72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6LSPSQ#issuecomment-529999818>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJJFVR5UQO7M4FYURS76I3QI66SNANCNFSM4IUI4U7Q>
.
|
That's awesome! I guess this covers most (if not all, and apart from duckarrays) use cases related to array creation with |
@pentschev not sure, but doing a PR first seems like a good idea either way. Perhaps it's so simple that it's just obvious that this is the best idea. Perhaps there's bigger design questions once seeing a PR, and then a NEP can be produced afterwards. |
I think I would be slightly in favor of a very short NEP. And if just to list (rejected) alternatives and clarify a bit which part it solves and which parts it does not (i.e. random creation functions as Hameer noted, although I think that is something best left alone in any case?). |
Just to keep this thread updated, I've opened #14715 with the proposal. |
Thanks, I am going to close this in favor of the NEP draft at gh-14715 which I think replaces this proposal. That may want to be pushed ahead. |
Yeah, there are a lot of things to hash out in that general direction. @pentschev if you are up to it some time mid April, we could even think about a larger video conference envent around these protocols/ideas. I will put something in my calendar for then, lets see where things go. |
Sorry for the delayed response @seberg . Indeed there are many things to be sorted out, I think a conference would be very nice for that! |
Much as there are functions like
zeros_like
,ones_like
, etc. It would be useful to have a few more*_like
functions for operations such asarange
,linspace
, etc. This would be useful for cases where one wishes to create an array of a specific type that has some particular initialization.cc @pentschev
The text was updated successfully, but these errors were encountered: