[Numpy-discussion] Efficient ?axpy operation without copy (B += a*A)

Michael McNeil Forbes mforbes at physics.ubc.ca
Tue Jun 23 18:51:49 EDT 2009


Thanks Pauli,

On 23 Jun 2009, at 12:46 PM, Pauli Virtanen wrote:
>>>> from scipy.lib.blas import get_blas_funcs
>>>> axpy, = get_blas_funcs(['axpy'], [A, B])
>>>> res = axpy(A.ravel(), B.ravel(), A.size, a)
>>>> res.base is B
...
> Works provided A and B are initially in C-order so that ravel()
> doesn't create copies. If unsure, it's best to make use of the
> return value of axpy and not assume B is modified in-place.
>
> [clip]
>> There are exposed blas daxpy operations in scipy, but in the  
>> version I
>> have (EPD), these also seem to make copies (though recent version  
>> seem
>> to be fixed by looking at the source.)
>
> I don't see many relevant changes in scipy.lib recently, so I'm
> not sure what change you mean by the above.


I was not ravelling or providing the size, and as a result the return  
value was a copy and B was not modified leading me to an incorrect  
conclusion: It works with EPD.

Michael.



More information about the NumPy-Discussion mailing list