[Cython] NumPy output works on 32bit not on 64bit
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Wed Sep 17 12:30:11 CEST 2008
Marcin Cieślik wrote:
> Thanks,
>
> I followed your advices and got my first useful cython program
> cross-platform. It is a kd-tree implementation which takes a numpy
> array as input and allows for k-nearest-neighbor and
> points-within-radius queries. A crude benchmark shows that for 7000 3D
> points (~number of heavy atoms in a protein) it is almost as fast as
> ANN via scikits-ANN and more than 3x faster than the current
> implementation of Bio.KDTree from biopython (SWIGed C++), which both
> have problems on 64bit machines.
>
Nice. Will you contribute it to SciPy/any other library?
Your code inspired me to make some additions to the buffer code, up in
the devel branch now. Your calls to PyArray_SimpleNewFromData should no
longer be necesarry, instead you can (if you so wish, of course...) do
cdef np.ndarray[unsigned int, mode="c"] ridx = np.empty((k,), dtype='I')
...
for 0 <= i < k:
ridx[i] = self.kdpnts[idx[i]].index
return (ridx, ...)
without any penalty. I.e. mode="c" causes no stride multiplication to
happen on the last dimension (the only on in 1D). (The only additional
overhead should be calling np.empty vs. PyArray_SimpleNewFromData + malloc).
If you do this I'm very interested in the benchmarks and whether there's
a performance regression, and also what happens to the timings if mode
is set to "strided" instead. (With "strided" you have the advantage that
you can take an optional "out" parameter like numpy often does...)
Dag Sverre
More information about the Cython-dev
mailing list