-
Notifications
You must be signed in to change notification settings - Fork 85
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
Emulate in-place operators like +=
by replacing layout
#3084
Comments
I am mildly in favour of this, as long as it can be replicated in Dask (I don't think we want people to have to think too hard about which kind of array they're working with)! |
Dask consistency motivated it: apparently, |
Oh, wonderful! It's nice that although it's user-facing mutability, we're still immutable (effectively) in our internals :) |
Description of new feature
Although Awkward layouts can't be updated in place, high-level
ak.Array
objects are a slightly mutable layer on top of the immutable core. For example,ak.Array.__setitem__
allows fields to be added by replacing theak.Array.layout
with the result of ak.with_field.Sometimes, users want to use operators like
+=
,-=
,*=
, etc. for conciseness. We currently don't allowand the way we report the error is like this:
That is, we don't support the
out
argument of ufuncs. The connection between+=
andnp.add
without
can be unclear, though. What we're doing is following a regular rule, but the consequences are obscure to anyone who doesn't know this level of detail about NumPy ufuncs, or even the fact that binary operators dispatch to NumPy ufuncs in the first place.This feature request is to add
and similar to high-level
ak.Array
, instead of letting theNDArrayOperatorsMixin
formalism have its way. It should probably be done in src/awkward/_operators.py, replacingawkward/src/awkward/_operators.py
Lines 71 to 78 in e9dd269
I'm not sure what happens to the copyright in that case (this file, alone, is copyright the NumPy developers because it was lifted from NumPy), since this one function would be different from the original
NDArrayOperatorsMixin
.Keep in mind that this would mean that in-place operators like
+=
do nothing for performance (minimizing memory latency and total memory use); it would just be a syntactic convenience. But it would be in line with similar treatment indask.array
, dask-histogram, and soon dask-awkward.The text was updated successfully, but these errors were encountered: