Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent 'invalid' result value #35

Open
QuLogic opened this issue Oct 19, 2018 · 2 comments
Open

Inconsistent 'invalid' result value #35

QuLogic opened this issue Oct 19, 2018 · 2 comments

Comments

@QuLogic
Copy link
Contributor

QuLogic commented Oct 19, 2018

I'm not sure if this is a bug or not, but the 'invalid' value is different depending on the query:

>>> import numpy as np
>>> a = np.arange(30.0)
>>> kdt = KDTree(a)
>>> kdt.query(np.arange(5) + 0.5)
(array([0.5, 0.5, 0.5, 0.5, 0.5]), array([0, 1, 2, 3, 4], dtype=uint32))
>>> kdt.query(np.arange(50) + 0.5)
(array([ 0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,
        0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,
        0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  1.5,  2.5,  3.5,
        4.5,  5.5,  6.5,  7.5,  8.5,  9.5, 10.5, 11.5, 12.5, 13.5, 14.5,
       15.5, 16.5, 17.5, 18.5, 19.5, 20.5]), array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 15, 15, 16,
       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 29, 29, 29,
       29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29],
      dtype=uint32))

everything okay above.

So if we set distance_upper_bound, then invalid points are np.inf and len(data_pts):

>>> kdt.query(np.arange(50) + 0.5, distance_upper_bound=10)
(array([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
       0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
       0.5, 0.5, 0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5,
       inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf]), array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 15, 15, 16,
       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 29, 29, 29,
       29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
      dtype=uint32))

But if we pass np.nan, the invalid point is DBL_MAX and UINT_MAX:

>>> kdt.query(np.array([np.nan]))
(array([1.34078079e+154]), array([4294967295], dtype=uint32))
@QuLogic
Copy link
Contributor Author

QuLogic commented Oct 19, 2018

For reference, SciPy's cKDTree returns (inf, len(data_pts)) for np.nan.

@storpipfugl
Copy link
Owner

The intention is to be drop-in compatible with SciPy's CKDTree so this is a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants