-
Notifications
You must be signed in to change notification settings - Fork 1
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
ENH: add lazywhere
#14
Comments
Yup, probably! But perhaps should check whether other libraries would like to use it. |
This proposal is lacking a bit of context. What is |
This was not meant to be a full proposal yet! Was just wanting to check whether Matt saw any obvious problems before putting more thought in. SciPy has a private helper called While Example: a = xp.asarray([1, 2, 3, 4])
b = xp.asarray([5, 6, 7, 8])
def f(a, b):
return a + b
_lazywhere(a > 2, (a, b), f, xp.nan) returns
One thing we would do if we add it here would be to make the parameter names consistent with Matt has already implemented this function in terms of the standard at https://github.com/scipy/scipy/blob/6f3a8bc82d07939dbca329ab3f8a8042f8668c44/scipy/_lib/_util.py#L85-L161. |
Re: performance optimisation, just wanted to clarify that due to the overhead of indexing, etc., the underlying calculation may need to be rather slow to observe a speed increase. However, it will typically reduce memory usage, and it is also commonly used to avoid warnings and/or errors (e.g. if the operation is division and some elements could be zero). I'd mention that the (private) function has been in SciPy for a long time; I just translated (/rewrote) it for the array API. |
Thanks for proposing this idea! 😀 This seems like a nice addition for libraries leveraging delayed computation as well 😉 |
Isn't this not needed for those libraries? |
@mdhaber do you think
lazywhere
would be in scope for this library? It seems to me like it would be useful beyond SciPy?The text was updated successfully, but these errors were encountered: