[Numpy-discussion] Re: [EXTERNAL] Copy on __setitem__

2024-12-27 Thread Israel, Daniel M via NumPy-Discussion
Done. https://github.com/numpy/numpy/issues/28070 — Daniel Israel XCP-4: Continuum Models and Numerical Algorithms d...@lanl.gov On Dec 26, 2024, at 3:44 AM, Sebastian Berg wrote: That seems like a bug but not sure why it would happen. It needs to call `__array__`, but indeed of course not wi

[Numpy-discussion] Re: [EXTERNAL] Copy on __setitem__

2024-12-26 Thread Robert Kern via NumPy-Discussion
On Thu, Dec 26, 2024 at 5:48 PM Benjamin Root via NumPy-Discussion < numpy-discussion@python.org> wrote: > Seems to make sense to me? Or is the following a bug? > > >>> import numpy as np > >>> u = np.zeros(5) > >>> v = np.ones(5) > >>> u > array([0., 0., 0., 0., 0.]) > >>> u[...] = v > >>> u > ar

[Numpy-discussion] Re: [EXTERNAL] Copy on __setitem__

2024-12-26 Thread Benjamin Root via NumPy-Discussion
Seems to make sense to me? Or is the following a bug? >>> import numpy as np >>> u = np.zeros(5) >>> v = np.ones(5) >>> u array([0., 0., 0., 0., 0.]) >>> u[...] = v >>> u array([1., 1., 1., 1., 1.]) >>> v[4] = 5 >>> v array([1., 1., 1., 1., 5.]) >>> u array([1., 1., 1., 1., 1.]) If you don't do a

[Numpy-discussion] Re: [EXTERNAL] Copy on __setitem__

2024-12-26 Thread Mateusz Sokol
It looks like general assignment function `array_assign_subscript` calls `PyArray_CopyObject(view, op)` link which in turn always calls `PyArray_DiscoverDTypeAndShape` with `cop

[Numpy-discussion] Re: [EXTERNAL] Copy on __setitem__

2024-12-26 Thread Sebastian Berg
That seems like a bug but not sure why it would happen. It needs to call `__array__`, but indeed of course not with `copy=True`. Would you open an issue on github? - Sebastian On Thu, 2024-12-26 at 03:46 +, Israel, Daniel M via NumPy- Discussion wrote: > Sure.  I didn’t originally, because

[Numpy-discussion] Re: [EXTERNAL] Copy on __setitem__

2024-12-25 Thread Israel, Daniel M via NumPy-Discussion
Sure. I didn’t originally, because I thought it would require an entire custom array container, but the following trivial example actually shows the behavior in question: import numpy class MyThing(object): def __array__(self, dtype=None, copy=None): print(f"MyThing.__array__(dtype