[Numpy-discussion] Array vectorization in numpy

Carlos Becker carlosbecker at gmail.com
Tue Jul 19 15:27:35 EDT 2011


Hi, everything was run on linux.

I am using numpy 2.0.0.dev-64fce7c, but I tried an older version (cannot
remember which one now) and saw similar results.
Matlab is R2011a, and I used taskset to assign its process to a single core.

Linux is 32-bit, on Intel Core i7-2630QM.

Besides the matlab/numpy comparison, I think that there is an inherent
problem with how expressions are handled, in terms of efficiency.
For instance, k = (m - 0.5)*0.3 takes 52msec average here (2000x2000 array),
while k = (m - 0.5)*0.3*0.2 takes 0.079, and k = (m - 0.5)*0.3*0.2*0.1 takes
101msec.
Placing parentheses around the scalar multipliers shows that it seems to
have to do with how expressions are handled, is there sometihng that can be
done about this so that numpy can deal with expressions rather than single
operations chained by python itself? Maybe I am missing the point as well.

----------------------
Carlos Becker


On Tue, Jul 19, 2011 at 6:44 PM, Christopher Jordan-Squire
<cjordan1 at uw.edu>wrote:

>
>
> On Tue, Jul 19, 2011 at 11:19 AM, Charles R Harris <
> charlesr.harris at gmail.com> wrote:
>
>>
>>
>> On Tue, Jul 19, 2011 at 9:49 AM, Carlos Becker <carlosbecker at gmail.com>wrote:
>>
>>> I made more tests with the same operation, restricting Matlab to use a
>>> single processing unit. I got:
>>>
>>> - Matlab: 0.0063 sec avg
>>> - Numpy: 0.026 sec avg
>>> - Numpy with weave.blitz: 0.0041
>>>
>>> Note that weave.blitz is even faster than Matlab (slightly).
>>> I tried on an older computer, and I got similar results between matlab
>>> and numpy without weave.blitz, so maybe it has to do with 'new'
>>> vectorization opcodes.
>>>
>>> Anyhow, even though these results are not very promising, it gets worse
>>> if I try to do something like:
>>>
>>> result = (m - 0.5)*0.3
>>>
>>> and I get the following timings:
>>>
>>> - Matlab: 0.0089
>>> - Numpy: 0.051
>>> - Numpy with blitz: 0.0043
>>>
>>> Now blitz is considerably faster! Anyways, I am concerned about numpy
>>> being much slower, in this case taking 2x the time of the previous
>>> operation.
>>> I guess this is because of the way that python operands/arguments are
>>> passed. Should I always use weave.blitz?
>>>
>>>
>> Out of curiosity, what os/architecture are you running on? What version of
>> numpy are you using?
>>
>> By and large, you shouldn't spend time programming in blitz, it will ruin
>> the whole point of using numpy in the first place. If there is an
>> inefficiency somewhere it is better to fix the core problem, whatever it is.
>>
>> <numpy>
>>
>> Chuck
>>
>
> Also what version of matlab were you using?
>
> -Chris JS
>
>
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110719/31997b0a/attachment.html>


More information about the NumPy-Discussion mailing list