[Numpy-discussion] performing operations in-place in numpy

Citi, Luca lciti at essex.ac.uk
Wed Jul 8 17:57:43 EDT 2009


Hi Stefan,
I am afraid I did not explain myself clear enough.

Of course
c = a + b + d
leaves a, b, and d unchanged.
The only array that is overwritten is (a+b) which is a temporary
array that would be destroyed anyway.
Normally the operation above is performed like this:
1) allocation of a temporary array f
2) execution of sum(a, b, out=f)
3) allocation of a temporary array g
4) execution of sum(f, d, out=g)
5) assignment of g to c
6) deallocation of f
With my method it is performed like this:
1) allocation of a temporary array f
2) execution of sum(a, b, out=f)
3) execution of sum(f, d, out=f)
4) assignment of f to c

When I write
"The approach works in most cases (it passes
most of the numpy tests) but makes the assumption that ufuncs can work
even if one of the inputs is used as output."
I mean that the core ufunc, the atomic operation working on the
single array element, must be able to work even if one of the
input is used as output.
As far as I can tell, they already work like this.
Can we expect someone implementing a new ufunc to keep that in mind?

Actually with my last version of the patch, all tests are passed.
If after further thorough testing, this approach is found to not
break things, there is no reason not to include it.
It is completely transparent to the python user.
The only programmer that should be aware of it is the numpy C
developer.

I hope I answered your concerns.
I am sorry if my description of the ticket is a bit confused.

Best,
Luca



More information about the NumPy-Discussion mailing list