{"id":16573253,"url":"https://github.com/jefferis/rann2","last_synced_at":"2025-10-29T02:30:22.979Z","repository":{"id":19453428,"uuid":"22697715","full_name":"jefferis/RANN2","owner":"jefferis","description":"Fast Nearest Neighbour Search (Rcpp wrapper for libANN)","archived":false,"fork":false,"pushed_at":"2024-02-26T22:11:32.000Z","size":5569,"stargazers_count":2,"open_issues_count":2,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T21:11:59.941Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://jefferis.github.io/RANN2/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jefferis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-06T20:51:25.000Z","updated_at":"2024-02-25T08:12:44.000Z","dependencies_parsed_at":"2022-08-24T01:20:46.269Z","dependency_job_id":null,"html_url":"https://github.com/jefferis/RANN2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jefferis%2FRANN2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jefferis%2FRANN2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jefferis%2FRANN2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jefferis%2FRANN2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jefferis","download_url":"https://codeload.github.com/jefferis/RANN2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238758301,"owners_count":19525749,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T21:29:49.119Z","updated_at":"2025-10-29T02:30:22.589Z","avatar_url":"https://github.com/jefferis.png","language":"C++","readme":"# RANN2\n\u003c!-- badges: start --\u003e\n[![Docs](https://img.shields.io/badge/docs-100%25-brightgreen.svg)](https://jefferis.github.io/RANN2/)\n[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)\n[![R-CMD-check](https://github.com/jefferis/RANN2/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jefferis/RANN2/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\nThis package is an updated version of the [RANN](https://cran.r-project.org/package=RANN) \npackage, making use of the Rcpp package. \nFor basic use, there is little difference with original RANN \npackage although there are some small (typically 5-10%) speedups for certain \nquery/target size combinations. **RANN2** also includes experimental \nfunctionality via `WANN` objects to:\n  * keep ANN points in memory to avoid repeated copying\n  * keep the ANN k-d tree in memory to avoid repeated building\n  * separate building the k-d tree from allocating the points\n  * permit very fast self queries\n  * permit queries of the points from one ANN tree against a second tree\n\n## Installation\nCurrently there isn't a released version on [CRAN](https://cran.r-project.org/),\nalthough we are considering a submission when the package develops sufficiently\ndistinct functionality from the original RANN package.\n\n### Development version\nYou can use the **devtools** package to install the development version:\n\n```r\nif (!require(\"devtools\")) install.packages(\"devtools\")\ndevtools::install_github(\"jefferis/RANN2\")\n```\n\nNote: Windows users need [Rtools](http://www.murdoch-sutherland.com/Rtools/) and [devtools](https://cran.r-project.org/package=devtools) to install this way.\n\n## Use\n### Basic use\nThe expectation is that for 90% of users the `nn2` function should be the only\nway that the library is used. This takes a target matrix of R points, copies them into\nan array used by ANN and builds a k-d tree. It then iterates over the query\npoints, searching the tree one at a time.\n\n### Advanced use\n**RANN2** adds `WANN` objects, which allow fine control of when the k-d tree is\nbuilt and removed.\n\n```\ndata(kcpoints)\nw1=WANN(kcpoints[[1]])\nlibrary(microbenchmark)\nmicrobenchmark(w1sq\u003c-w1$selfQuery(k=1,eps=0))\nmicrobenchmark(nn2(kcpoints[[1]],k=1))\nw2=WANN(kcpoints[[2]])\n# NB must pass the Cpp object not the reference class object\nw1$queryWANN(w2$.CppObject)\n```\n\nWANN objects will primarily be useful if you make repeated queries. You can also\ndelay building the k-d tree:\n\n```\nw1=WANN(kcpoints[[1]])\nw1$querySelf(k=1,eps=0)\nw1$build_tree()\nw1$delete_tree()\n```\nif only a fraction of the objects will need to be searched; the tree will\nautomatically be built when it is queried. You can also explicitly control\nwhen the tree is built or deleted (for memory management). The tree is wrapped\nin an R reference class (R5) object which imposes a significant performance\npenalty for building small trees (\u003c ~ 1000 points).\n\n### Changing ANN data types\nBy default ANN uses `double`s for both points and returned distances. You can\nsave space by changing this if you want. To do to this you must recompile after\nsetting either `ANN_COORD_TYPE` or `ANN_DIST_TYPE` in `src/MAKEVARS` or \n`MAKEVARS.win` as appropriate. e.g. \n```\nPKG_CPPFLAGS=-I. -IANN -DRANN -DANN_COORD_TYPE=float\n```\nwould switch to the use of floats for the main ANN coordinate type. Note however\nthat the k-d tree itself appears to occupy ~ 2x the space of the underlying\ndouble coordinates.\n\n### Linking and using ANN library\nThis package compiles a static library for ANN and provides the headers for it.\nDevelopers can directly include them in their C++ code / Rcpp based package.\n\n#### Instructions\n\n`DESCRIPTION` file: \n```\n    LinkingTo: RANN2\n```\n`src/Makevars` file: \n```sh\n    PKG_IMPORT=RANN2\n    PKG_HOME=`${R_HOME}/bin/Rscript -e 'cat(system.file(package=\\\"$(PKG_IMPORT)\\\"))'`\n    PKG_LIBS=-L$(PKG_HOME)/lib -l$(PKG_IMPORT)\n```\n`src/Makevars.win` file:\n```sh\n    PKG_IMPORT=RANN2\n    PKG_HOME=`${R_HOME}/bin/Rscript -e 'cat(system.file(package=\\\"$(PKG_IMPORT)\\\"))'`\n    PKG_LIBS+=-L$(PKG_HOME)/lib -l$(PKG_IMPORT)\n\n    PKG_CPPFLAGS+=-DDLL_EXPORTS\n```\nYour `C++` file (e.g. `src/mycodeusingANN.cpp`) will typically start: \n```C\n    #include \u003cANN/ANN.h\u003e\n    #include \u003cRcpp.h\u003e\n    using namespace Rcpp;\n```\n    \n[Here](https://github.com/caiohamamura/MeanShiftR/blob/RANN2/) is an example of linking to RANN2 and using the base ANN library. See in particular \n\n    * [DESCRIPTION](https://github.com/caiohamamura/MeanShiftR/blob/RANN2/DESCRIPTION)\n    * [src/MeanShift_Classical.cpp](https://github.com/caiohamamura/MeanShiftR/blob/RANN2/src/MeanShift_Classical.cpp)\n\n#### Using WANN from RCpp \n\nAs already noted the WANN C++ class wraps ANN and provides some \nadditional functionality for RCpp users. You can use this from RCpp code in your\nown project by following the step above but the start of your C++ file will look\nslightly different. \n\nYour `C++` file (e.g. `src/mycodeusingWANN.cpp`) will typically start: \n```C\n    #include \"WANN.h\"\n    using namespace Rcpp;\n```\n\nFor usage example: [src/nn.cpp](https://github.com/jefferis/RANN2/blob/master/src/nn.cpp)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjefferis%2Frann2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjefferis%2Frann2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjefferis%2Frann2/lists"}