-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Surprising results from in-place operations involving views (Trac #1085) #1683
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
Comments
trac user tillmann wrote on 2009-04-15
|
@pv wrote on 2009-04-15 This was extensively discussed on the mailing list some time ago. IIRC, the outcome was that:
This probably needs to be brought up again on the ML. Issuing a warning whenever an in-place operation involves a (N-dimensional?) view of the same array on the LHS is probably a sensible. |
Milestone changed to |
Title changed from |
@pv wrote on 2009-04-15 More discussion here:
|
trac user lucaciti wrote on 2009-06-27 Hi! I think tillmann is right. This behaviour is unexpected. I think I fixed it, but please double-check whether it works as expected. The following now works as expected:
while with the current implementation, the results for the in-place versions differ from the corresponding out-of-place versions. Bye, Luca |
Attachment added by trac user lucaciti on 2009-06-27: inplace_views.patch |
Attachment added by trac user lucaciti on 2009-06-27: inplace_views.2.patch |
@pv wrote on 2009-06-28 Looks good! I don't think that anyone actually relies on in-place overwriting (as it's memory-order specific), even in 1D cases, but it might be good to recheck the old mailing list discussions if some good arguments were raised. I think some work should be put in predicting "easy" special cases, in which copies can be avoided. For example, the following:
In general, solving this decision problem is probably hard, but most common special cases could probably be worked out. Also, the prediction code should probably be put in a separate function, for clarity. |
trac user lucaciti wrote on 2009-06-28 With the current implementation this works
but this doesn't:
With my patch both works but by making possibly unnecessary copies.
into
but I might be wrong. |
trac user lucaciti wrote on 2009-06-28 Well, not, we should check for the sign of the strides... |
@pv wrote on 2009-06-28 Also that is not enough, since larger strides can overtake smaller ones. |
trac user lucaciti wrote on 2009-06-28 That is true. I might be wrong but it might still work. Of course, strides are very powerful but also very delicate and dangerous to handle. I might be completely wrong. On the separate function thing, I definitely agree. |
trac user lucaciti wrote on 2009-07-01 Hello! I attach a new patch. The code which decides whether or not to make a copy is in a separate function. If one input argument and one output argument are views of a same array, a copy is made unless:
I also added some tests to check the correctness of the results. Let me know if it works as expected. |
Attachment added by trac user lucaciti on 2009-07-01: inplace_views_rev2.patch |
@charris wrote on 2010-05-06 What are the current thoughts on this ticket? The patch does seem to deal with a common problem. |
@pv wrote on 2010-05-06 @charris: based on the discussions on the ML, I think there is agreement that (i) we want this feature, (ii) provided it does not cause unnecessary copies in "simple" operations. Regarding this patch, I suppose it only needs more eyes to verify that the approach does what is wanted. |
Milestone changed to |
Attachment added by @charris on 2010-05-30: inplace_views_rev3.patch |
@charris wrote on 2010-05-30 I'm looking at this and wondering if the ufuncs are the proper place for it. If we are only concerned with the extended assignment operators, then it would seem that that would be the proper place. The only normal use in a ufunc would be if output= was specified. I suppose the check could also be set up to take place in that circumstance. I've also attached a patch that works for the current trunk. |
@mwiebe wrote on 2011-03-24 A good approach for this might be to add a flag to the iterator like NPY_ITER_COPY_IF_OVERLAP. This would check if any READ or READWRITE operands overlap with READWRITE or WRITE operands, and make appropriate copies to avoid problems. |
Just wondering, what is the status on this? I know it is as such ancient, but for |
Original ticket http://projects.scipy.org/numpy/ticket/1085 on 2009-04-15 by trac user tillmann, assigned to @charris.
when writing code on such a high level of abstraction this behavior is not expected and imho wrong. At least a warning should be issued or better the in place operations should fall back to creating copies if the results are not correct otherwise.
The text was updated successfully, but these errors were encountered: