[SciPy-User] Finding closest point in array - inverse of KDTree

Daπid davidmenhur at gmail.com
Thu Oct 12 10:16:27 EDT 2017


On 12 October 2017 at 15:18, Ant <antoniy.py at gmail.com> wrote:

> @Daπid
> Thank you! This indeed is twice as fast as doing it normally (not counting
> the fixed time of sorting A, of course).
> I would still like to speed it up, getting another 2x  speedup. This is my
> code, please tell me if you have any suggestions!
>


As always, when optimising you must profile. For A of size 3000000 and k of
size 30, this is what I get:

https://gist.github.com/Dapid/ed23a1bb8e96782c0b698edecff14435

89% of the time is being spent on this line (and it gets worse as you
increase the size of A):

indicesClosest = final_indices[inv_idx_sort]
>
>
I don't know from the top of my head of a faster way of doing this, so, can
you somehow adapt your problem to use your sorted indexes of A instead?
This you can very easily rewrite unrolled in Cython, I think you can scrape
a bit of time there.

Here is a good tutorial for Numpy:
http://docs.cython.org/en/latest/src/userguide/numpy_tutorial.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20171012/f5ddb034/attachment.html>


More information about the SciPy-User mailing list