[Numpy-discussion] my cython is slow

Eric Firing efiring@hawaii....
Wed Jan 7 17:37:56 CST 2009

John Hunter wrote:
> Partly as an excuse to learn cython, and partly because I need to eke
> out some extra performance of a neighborhood search, I tried to code
> up a brute force neighborhood search in cython around an N-dimensional
> point p.  I need to incrementally add a point, do a search, add
> another point, do another search, so some of the algorithms like those
> in scipy.stats.spatial which assume a static data structure with lots
> of searches over it probably won't help me.
> I wrote some cython code to grow a Npoints x Ndimensions numpy array
> (doubling in size every time I exceed Npoints) and then doing a brute
> force request for all points within a radius r using a euclidean
> distance.  The code is working fine, but it is still slower than a
> simple numpy implementation (damn you numpy performance!)

A couple small changes speed it up quite a bit:

efiring@manini:~/temp/nnbf$   python test_nnbf.py
loading data... this could take a while
testing nnbf...
     10 trials: mean=0.0150, min=0.0100
testing numpy...
     10 trials: mean=0.0660, min=0.0600

It is all a matter of keeping Python objects and function calls out of 
inner loops.  I suspect there is quite a bit more that could be done in 
that regard, but I haven't looked.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nnbf.pyx
Url: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090107/9d163cb6/attachment.pl 

More information about the Numpy-discussion mailing list