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

Function to make queries using pre-computed trees #7

Open
elipickh opened this issue Oct 13, 2020 · 1 comment
Open

Function to make queries using pre-computed trees #7

elipickh opened this issue Oct 13, 2020 · 1 comment

Comments

@elipickh
Copy link

It would be useful to have a dedicated function in C++/R to make queries on trees that have already been computed. This would especially help when making many repeated queries and when we would prefer separate objects/processes for trees and queries.

For example:

library(RANN2)
p1=kcpoints[[1]]
w1=WANN(p1)
q = t(c(1.0, 1.0, 1.0))

We can query by doing, e.g., w1$query(q, 1, 0.0), which works well (and is very fast).

However, instead of using the above R5 class function, I would like to have a simpler function that can input the tree directly, as a separate object. So something like:

// [[Rcpp::export]]
List wann_query(?? kd_tree_object, NumericMatrix query, const int k) {

//Skip the tree-building process and proceed to calculate distances, as in nn.cpp
//WANN tree = WANN(data);  -- This line would not be needed

return List::create(Rcpp::Named("nn.idx")=ridx, Rcpp::Named("nn.dists")=rdists);
}

The main challenges I'm facing are

  1. How to extract the tree from the w1 WANN object?
  2. How exactly can the tree object be passed into wann_query and used to calculate distances?

The end goal would be something like:

tree_out <- w1$tree
wann_query(tree_out, q, 1)
# Output identical to 
w1$query(q, 1, 0.0)
@caiohamamura
Copy link
Contributor

caiohamamura commented Mar 1, 2024

Why not pass w1 to wann_query and inside it just return the result of w1$query(q, 1, 0.0)?

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