[Numpy-discussion] On loop and broadcasting (again)

David Cournapeau david at ar.media.kyoto-u.ac.jp
Fri Oct 6 01:33:11 CDT 2006


Travis Oliphant wrote:
> David Cournapeau wrote:
>
>> Hi,
>>
>>   The email from Albert made me look again on some surprising results I 
>> got a few months ago when starting my first "serious" numpy project. I 
>> noticed that when computing multivariate gaussian densities, centering 
>> the data was more expensive than everything else, including 
>> exponentiation. Now that I have some experience with numpy, and 
>> following the previous discussion, I tried the following script:
>>  
>>
>
> Try it again with the new code in SVN.
>
It looks like your modification solved this particular issue !:

     10    0.645    0.065    0.645    0.065 
storage_email.py:8(center_broadcast)
     10    0.625    0.062    0.625    0.062 
storage_email.py:26(center_manual)
      1    0.333    0.333    0.333    0.333 
/usr/lib/python2.4/site-packages/numpy/lib/shape_base.py:530(repmat)

Now, using broadcast is as fast as doing the substraction itself (which 
does not include the necessary repmat). I tried it on my laptop, where I 
can safely use beta code (python 2.4 + SVN numpy), which  explains the 
timing differences compared to my previous email; as the memory is 
limited on the laptop, I only benchmarked the brodcasting. For smaller 
arrays, I couldn't see major differences in relative timing for the 
other implementations.

Thank you very much !

David




More information about the Numpy-discussion mailing list