You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Quantity created with copy=True doesn't owndata #7244
It seems that the copy keyword for creating Quantity doesn't do what I expect it to, namely ensuring that the returned Quantity actually owns the data:
This is all because internal to Quantity.__new__ the .value property is set using ndarray.view.
If the copy keyword is supposed to guarantee data ownership, can Quantity.__new__ get modified to use Quantity.copy, otherwise can the documentation be expanded a wee bit to highlight this potential confusion?
Maybe I've just missed some documentation that already exists somewhere, if so, sorry for the spam.
@duncanmmacleod - I think a Quantity can, as currently written, never own its data as it is always constructed via a view of an ndarray (which itself, though, holds a new copy of the data). In principle, I guess this could be changed by doing something like
self = super().__new__(cls, shape=..., dtype=...)
and then copying the data to self.
Since we're doing the copy anyway, maybe there is a way to do this more immediately -- worth investigating since it might also speed up initialization just a little bit...
Activity
Array: use .copy() to ensure data ownership
mhvk commentedon Feb 28, 2018
@duncanmmacleod - I think a
Quantitycan, as currently written, never own its data as it is always constructed via a view of anndarray(which itself, though, holds a new copy of the data). In principle, I guess this could be changed by doing something likeand then copying the data to self.
Since we're doing the copy anyway, maybe there is a way to do this more immediately -- worth investigating since it might also speed up initialization just a little bit...
mhvk commentedon Feb 28, 2018
p.s. The way I usually test data is a copy is via
np.may_share_memory.