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
np.conj has divergent behavior from ndarray.conj #17124
Standard behavior, functions usually make copies, methods don't if they don't need to. We should probably do a better job of documenting the view vs copy behavior of all our methods. The sort method is a bit of an outlier as it sorts in place like Python does, and while conj could also change the imaginary part in place, it would break up a bunch of code to change that now.
As some follow-up context, other NumPy functions are also inconsistent here. np.round and np.trunc, for example, will return self when called on an int64 array.
Yes, the inconsistency is quite annoying, but it's also hard to fix up because of the danger of silently introducing bugs in end user code.
I suspect the best we can do is document it well.
Standard behavior, functions usually make copies, methods don't if they don't need t
I don't think that has been the design principle. The goal was, I think, returning views whenever possible, and copies if needed (remember, e.g., the np.diag stuff where we tried deprecating and then changing to a view to comply to this principle).
I agree that the expectation that function and method work the same is sensible - it would be mine as well.
Activity
charris commentedon Aug 20, 2020
Standard behavior, functions usually make copies, methods don't if they don't need to. We should probably do a better job of documenting the view vs copy behavior of all our methods. The
sortmethod is a bit of an outlier as it sorts in place like Python does, and whileconjcould also change the imaginary part in place, it would break up a bunch of code to change that now.mruberry commentedon Aug 20, 2020
As some follow-up context, other NumPy functions are also inconsistent here.
np.roundandnp.trunc, for example, will returnselfwhen called on an int64 array.rgommers commentedon Aug 20, 2020
Yes, the inconsistency is quite annoying, but it's also hard to fix up because of the danger of silently introducing bugs in end user code.
I suspect the best we can do is document it well.
I don't think that has been the design principle. The goal was, I think, returning views whenever possible, and copies if needed (remember, e.g., the
np.diagstuff where we tried deprecating and then changing to a view to comply to this principle).I agree that the expectation that function and method work the same is sensible - it would be mine as well.