[Numpy-discussion] inplace dot products

Olivier Grisel olivier.grisel at ensta.org
Wed Feb 18 04:06:26 EST 2009


Hi numpist people,

I discovered the ufunc and there ability to compute the results on
preallocated arrays:

>>> a = arange(10, dtype=float32)
>>> b = arange(10, dtype=float32) + 1
>>> c = add(a, b, a)
>>> c is a
    True
>>> a
    array([  1.,   3.,   5.,   7.,   9.,  11.,  13.,  15.,  17.,
19.], dtype=float32)

My questions is : is there a way to have an equivalent for the dot
product operation:
I want atlas to build my dot products without allocating a temporary
array and reuse
a preallocated array of results. Suppose I have:

>>> results = array((10, 3), dtype=float32)
>>> W = arange(6, dtype=float32).reshape((2, 3))
>>> x = arange(20, dtype=float32).reshape((10, 2))

What I want is the equivalent of the following without the
intermediate call to malloc:

>>> results[:] = dot(x, W)

Any idea? I tried to introspect the various docstring of numpy core
modules but I
could not get any lead.

-- 
Olivier



More information about the NumPy-Discussion mailing list