Skip to content

Commit

Permalink
Merge pull request #12673 from peterbell10/ckdtree-query-intreturn
Browse files Browse the repository at this point in the history
API: Unconditionally return np.intp from cKDTree.query
  • Loading branch information
rgommers committed Aug 9, 2020
2 parents 2155864 + a5354df commit 8ea3fe3
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions scipy/spatial/ckdtree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -785,31 +785,8 @@ cdef class cKDTree:

_run_threads(_thread_func, n, n_jobs)

# massage the output in conformabity to the documented behavior

if sizeof(long) < sizeof(np.intp_t):
# ... e.g. Windows 64
overflown = False
for i in range(n):
for j in range(len(k)):
if ii[i,j] > <np.intp_t>LONG_MAX:
# C long overlow, return array of dtype=np.int_p
overflown = True
break
if overflown:
break

if overflown:
ddret = np.reshape(dd,retshape+(len(k),))
iiret = np.reshape(ii,retshape+(len(k),))
else:
ddret = np.reshape(dd,retshape+(len(k),))
iiret = np.reshape(ii,retshape+(len(k),)).astype(int)

else:
# ... most other platforms
ddret = np.reshape(dd,retshape+(len(k),))
iiret = np.reshape(ii,retshape+(len(k),))
ddret = np.reshape(dd, retshape + (len(k),))
iiret = np.reshape(ii, retshape + (len(k),))

if nearest:
ddret = ddret[..., 0]
Expand Down

0 comments on commit 8ea3fe3

Please sign in to comment.