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

a basic version of Nearest[] #559

Merged
merged 2 commits into from
Sep 20, 2016
Merged

a basic version of Nearest[] #559

merged 2 commits into from
Sep 20, 2016

Conversation

poke1024
Copy link
Contributor

Only the Scan method is implemented here, but it's still quite useful, I think.

candidates = heapq.nsmallest(py_n, py_distances)

for d, i in candidates:
if py_r is not None and d > py_r:
Copy link
Member

@sn6uv sn6uv Sep 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should filter before finding the py_n smallest:

  1. Avoids comparison with None in heapq.nsmallest
  2. If k elements are within the limit distance the runtime is (very) slightly better: O(n) + O(min(k, m) log(k)) vs O(m log (n)) for m nearest elements.

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

Successfully merging this pull request may close these issues.

2 participants