question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Massive performance regression in cKDTree.query with L_inf distance in scipy 0.17

See original GitHub issue

Hi,

While running some of my own code, I noticed a major slowdown in scipy 0.17 which I tracked to the cKDtree.query call with L_inf distance. I did a git bisect and tracked the commit that caused the issue – the commit is : 58a10c2688398ab440de8d6d7b5fba29671df182 Here is the example program that finishes in ~ 10 seconds before this commit and pretty much never finishes after it

import scipy.spatial.ckdtree
import numpy as np
arr1 = np.random.uniform(size=(6000000, 3))
tree2 = scipy.spatial.ckdtree.cKDTree(arr1)
distances, ind = tree2.query(arr1, 1, p=np.inf)

I also checked that if I change the distance from L_inf to L_2, then program finishes pretty quickly. I also tried to stop the program with gdb a few times to see where the code is mostly spending the time on and it seems to be here scipy/spatial/ckdtree/src/query.cxx:311. I also tried to dig into the problematic commit but I don’t know enough about ckdtree internals to suggest a patch.

Thanks, Sergey

If relevant, I’m seeing this issue on a both systems that I tried 64bit RHEL6.7 with gcc 4.4 and Debian 7.9 with gcc-4.7. In all the cases it is python 2.7

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:26 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
sturlamoldencommented, Mar 10, 2016

I will just add a couple of const members to the template structs and use a conditional branch on those instead of p and raw_boxsize_data. Then the compiler will optimize it away.

0reactions
rainwoodmancommented, Mar 11, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

scipy.spatial.cKDTree.query — SciPy v1.9.3 Manual
Return only neighbors within this distance. This is used to prune tree searches, so if you are doing a series of nearest-neighbor queries,...
Read more >
scipy.spatial.cKDTree — SciPy v1.9.3 Manual
The number of nodes in the tree. Count how many nearby pairs can be formed. Find all points within distance r of point(s)...
Read more >
SciPy 1.6.0 Release Notes — SciPy v1.9.3 Manual
scipy.spatial.distance.cdist has improved performance with the minkowski metric ... cKDTree.query now returns 64-bit rather than 32-bit integers on Windows, ...
Read more >
scipy.spatial.cKDTree.query_ball_point — SciPy v1.9.3 Manual
Find all points within distance r of point(s) x. Parameters. xarray_like, shape tuple + (self.m,). The point or points to search for neighbors ......
Read more >
scipy.spatial.cKDTree.query_pairs — SciPy v1.9.3 Manual
cKDTree.query_pairs(self, r, p=2., eps=0)#. Find all pairs of points in self whose distance is at most r. Parameters. rpositive float. The maximum distance....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found