periodic_kdtree icon indicating copy to clipboard operation
periodic_kdtree copied to clipboard

Axis out of bounds

Open jsevo opened this issue 11 years ago • 2 comments

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 avatar Nov 04 '13 11:11 jsevo

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])

jsevo avatar Nov 04 '13 16:11 jsevo

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.

pdebuyl avatar May 22 '14 10:05 pdebuyl