patvarilly / periodic_kdtree

SciPy-based kd-tree with periodic boundary conditions
36 stars 13 forks source link

Axis out of bounds #2

Open jsevo opened 11 years ago

jsevo commented 11 years ago

Hi there,

I tried using your code on my own data and encountered several issues. It appears to boil down to an axis out of bounds issue.

Running your sample code (using python 2.7.3 on linux) returns the following error: """ d, i = T.query([45.0, 10.0, 10.0], k=4) File "/usr/local/lib/python2.7/dist-packages/periodic_kdtree.py", line 306, in query hits = self.__query(x, k=k, eps=eps, p=p, distance_upper_bound=distance_upper_bound) File "/usr/local/lib/python2.7/dist-packages/periodic_kdtree.py", line 217, in __query self.max_distance_upper_bound) File "/usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 1894, in amin return _wrapit(a, 'min', axis, out) File "/usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 37, in _wrapit result = getattr(asarray(obj),method)(_args, *_kwds) ValueError: axis(=15) out of bounds

"""

jsevo commented 11 years ago

I found the bit that caused the bug but I am unsure how to proceed:

Line 216-217 of periodic_kdtree.py

It appears that the following (class PeriodiccKDTree(KDTree)):

distance_upper_bound = np.min(distance_upper_bound, self.max_distance_upper_bound)

needs to be changed to (note the square brackets)

distance_upper_bound = np.min([distance_upper_bound, self.max_distance_upper_bound])

EDIT:

The same applies for Line 131 (class PeriodicKDTree(KDTree)):

r = np.min(r, self.max_distance_upper_bound)

has to be changed to

r = np.min([r, self.max_distance_upper_bound])

pdebuyl commented 10 years ago

Hi,

I have the exact same issue. From np.min docstring, it is clear that the second argument is axis and not an item to be compared.

Using NumPy 1.7.1

I'd be happy to make this a pull request if @patvarilly is ok with submissions.