Emulate in-place operators like +=
by replacing layout
#3084
Labels
feature
New feature or request
Projects
+=
by replacing layout
#3084
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: