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

avoid some square rooting to check distances #197

Merged
merged 1 commit into from
Jun 29, 2024

Conversation

KristofferC
Copy link
Owner

@KristofferC KristofferC commented Jun 29, 2024

 using Revise, StableRNGs
 using NearestNeighbors
 data = rand(StableRNG(1), 3, 10^4);
 x = BallTree(data);
 v = rand(StableRNG(1), 3);
 using GFlops
 @count_ops inrange(x, v, 0.01)

Master:

Flop Counter: 1491 flop
┌──────┬─────────┐
│      │ Float64 │
├──────┼─────────┤
│  add │     438 │
│  sub │     468 │
│  mul │     555 │
│ sqrt │      30 │
└──────┴─────────┘

PR:

Flop Counter: 1491 flop
┌─────┬─────────┐
│     │ Float64 │
├─────┼─────────┤
│ add │     438 │
│ sub │     468 │
│ mul │     558 │
└─────┴─────────┘

No more square roots 🎉.

@dkarrasch
Copy link
Contributor

Same with KDTree?

@KristofferC
Copy link
Owner Author

KDTree already does this.

@KristofferC
Copy link
Owner Author

By the way, it is amazing how little resources KDTree is using compared to the BallTree (in this very specific case):

 x = KDTree(data);
 @count_ops inrange(x, v, 0.01)
Flop Counter: 196 flop
┌─────┬─────────┐
│     │ Float64 │
├─────┼─────────┤
│ add │      43 │
│ sub │      89 │
│ mul │      64 │
└─────┴─────────┘

@KristofferC KristofferC merged commit 3636844 into master Jun 29, 2024
14 checks passed
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