Skip to content

Commit

Permalink
Pass CHECK.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Jul 29, 2024
1 parent 18d7a16 commit 448186c
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 53 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: BiocNeighbors
Version: 1.21.2
Date: 2022-12-17
Version: 1.21.3
Date: 2024-07-28
Title: Nearest Neighbor Detection for Bioconductor Packages
Authors@R: c(person("Aaron", "Lun", role=c("aut", "cre", "cph"),
email="infinite.monkeys.with.keyboards@gmail.com"))
Expand Down
7 changes: 4 additions & 3 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ setGeneric("buildIndex", signature=c("X", "BNPARAM"), function(X, transposed=FAL
# This is explicitly a S4 generic so that developers can extend it at the R
# level, not at the C++ level. We need to support dispatch on both X and
# BNPARAM as X could be an arbitrary index structure (i.e., not an external
# pointer). If we only dispatched on BNPARAM, the developer wouldn't be able to
# select the correct method based on the type of a prebuilt non-pointer index
# without also being supplied the BNPARAM, which is not ergonomic for the user.
# pointer). If we only dispatched on BNPARAM, a user could call the method with
# a prebuilt X that doesn't match the BNPARAM. This means that the developer of
# the BNPARAM method would be responsible for figuring out what to do with a X
# that they don't know anything about, which is pretty weird.

#' @export
#' @rdname findKNN
Expand Down
2 changes: 1 addition & 1 deletion R/AnnoyParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ setMethod("show", "AnnoyParam", function(object) {

#' @export
#' @rdname AnnoyParam
setMethod("buildIndex", c("ANY", "AnnoyParam"), function(X, transposed = FALSE, ..., BNPARAM) {
setMethod("buildIndex", c("matrix", "AnnoyParam"), function(X, transposed = FALSE, ..., BNPARAM) {
X <- .coerce_matrix_build(X, transposed)
build_annoy(X, num_trees=BNPARAM@ntrees, search_mult=BNPARAM@search.mult, distance=BNPARAM@distance)
})
13 changes: 7 additions & 6 deletions R/BiocNeighborParam-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#'
#' @details
#' The BiocNeighborParam class is a virtual base class on which other parameter objects are built.
#' There are currently 4 concrete subclasses:
#' There are currently 5 concrete subclasses in \pkg{BiocNeighbors}:
#' \describe{
#' \item{}{\code{\link{KmknnParam}}: exact nearest-neighbor search with the KMKNN algorithm.}
#' \item{}{\code{\link{VptreeParam}}: exact nearest-neighbor search with the VP tree algorithm.}
#' \item{}{\code{\link{AnnoyParam}}: approximate nearest-neighbor search with the Annoy algorithm.}
#' \item{}{\code{\link{HnswParam}}: approximate nearest-neighbor search with the HNSW algorithm.}
#' \item{\code{\link{KmknnParam}}:}{Exact nearest-neighbor search with the KMKNN algorithm.}
#' \item{\code{\link{VptreeParam}}:}{Exact nearest-neighbor search with the tree algorithm.}
#' \item{\code{\link{ExhaustiveParam}}:}{Exact nearest-neighbor search via brute-force.}
#' \item{\code{\link{AnnoyParam}}:}{Approximate nearest-neighbor search with the Annoy algorithm.}
#' \item{\code{\link{HnswParam}}:}{Approximate nearest-neighbor search with the HNSW algorithm.}
#' }
#'
#' These objects hold parameters specifying how each algorithm should be run on an arbitrary data set.
Expand Down Expand Up @@ -39,7 +40,7 @@
#' @aliases
#' BiocNeighborParam-class
#' show,BiocNeighborParam-method
#' bndistance,BiocNeighborParam-method
#' bndistance
#' [[,BiocNeighborParam-method
#' [[<-,BiocNeighborParam-method
#'
Expand Down
2 changes: 1 addition & 1 deletion R/ExhaustiveParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ExhaustiveParam <- function(distance=c("Euclidean", "Manhattan", "Cosine")) {

#' @export
#' @rdname ExhaustiveParam
setMethod("buildIndex", c("ANY", "ExhaustiveParam"), function(X, transposed = FALSE, ..., BNPARAM) {
setMethod("buildIndex", c("matrix", "ExhaustiveParam"), function(X, transposed = FALSE, ..., BNPARAM) {
X <- .coerce_matrix_build(X, transposed)
build_exhaustive(X, distance=BNPARAM@distance)
})
3 changes: 1 addition & 2 deletions R/HnswParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#'
#' @param nlinks Integer scalar, number of bi-directional links per element for index generation.
#' @param ef.construction Integer scalar, size of the dynamic list for index generation.
#' @param directory String specifying the directory in which to save the index.
#' @param ef.search Integer scalar, size of the dynamic list for neighbor searching.
#' @param distance A string specifying the distance metric to use.
#' @inheritParams ExhaustiveParam
Expand Down Expand Up @@ -89,7 +88,7 @@ setMethod("show", "HnswParam", function(object) {

#' @export
#' @rdname HnswParam
setMethod("buildIndex", c("ANY", "HnswParam"), function(X, transposed = FALSE, ..., BNPARAM) {
setMethod("buildIndex", c("matrix", "HnswParam"), function(X, transposed = FALSE, ..., BNPARAM) {
X <- .coerce_matrix_build(X, transposed)
build_hnsw(X, nlinks=BNPARAM@nlinks, ef_construct=BNPARAM@ef.construction, ef_search=BNPARAM@ef.search, distance=BNPARAM@distance)
})
3 changes: 1 addition & 2 deletions R/KmknnParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#'
#' A class to hold parameters for the k-means k-nearest-neighbors (KMKNN) algorithm for exact nearest neighbor identification.
#'
#' @param search.mult Numeric scalar, multiplier for the number of points to search.
#' @inheritParams ExhaustiveParam
#' @param BNPARAM A KmknnParam instance.
#'
Expand Down Expand Up @@ -48,7 +47,7 @@ KmknnParam <- function(..., distance=c("Euclidean", "Manhattan", "Cosine")) {

#' @export
#' @rdname KmknnParam
setMethod("buildIndex", c("ANY", "KmknnParam"), function(X, transposed = FALSE, ..., BNPARAM) {
setMethod("buildIndex", c("matrix", "KmknnParam"), function(X, transposed = FALSE, ..., BNPARAM) {
X <- .coerce_matrix_build(X, transposed)
build_kmknn(X, distance=BNPARAM@distance)
})
2 changes: 1 addition & 1 deletion R/VptreeParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ VptreeParam <- function(distance=c("Euclidean", "Manhattan", "Cosine")) {

#' @export
#' @rdname VptreeParam
setMethod("buildIndex", c("ANY", "VptreeParam"), function(X, transposed=FALSE, ..., BNPARAM) {
setMethod("buildIndex", c("matrix", "VptreeParam"), function(X, transposed=FALSE, ..., BNPARAM) {
X <- .coerce_matrix_build(X, transposed)
build_vptree(X, BNPARAM@distance)
})
8 changes: 4 additions & 4 deletions R/buildIndex.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#' Aaron Lun
#'
#' @seealso
#' \code{\link{buildIndex,KmknnParam-method}},
#' \code{\link{buildIndex,VptreeParam-method}},
#' \code{\link{buildIndex,AnnoyParam-method}}
#' and \code{\link{buildIndex,HnswParam-method}} for specific methods.
#' \code{\link{buildIndex,matrix,KmknnParam-method}},
#' \code{\link{buildIndex,matrix,VptreeParam-method}},
#' \code{\link{buildIndex,matrix,AnnoyParam-method}}
#' and \code{\link{buildIndex,matrix,HnswParam-method}} for specific methods.
#'
#' @examples
#' Y <- matrix(rnorm(100000), ncol=20)
Expand Down
4 changes: 3 additions & 1 deletion R/findKNN.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' @param subset An integer, logical or character vector specifying the rows of \code{X} for which the nearest neighbors should be identified.
#' This yields the same result as (but is more efficient than) subsetting the output matrices after running \code{findKmknn} with \code{subset=NULL}.
#' @param ... Further arguments to pass to \code{\link{buildIndex}} when \code{X} is not an external pointer.
#' @param BNPARAM A \linkS4class{BiocNeighborsParam} object specifying how the index should be constructed.
#' @param BNPARAM A \linkS4class{BiocNeighborParam} object specifying how the index should be constructed.
#' If \code{NULL}, this defaults to a \linkS4class{KmknnParam}.
#' Ignored if \code{x} contains a prebuilt index.
#'
Expand Down Expand Up @@ -52,6 +52,8 @@
#' @aliases
#' findKNN,matrix,ANY-method
#' findKNN,externalptr,ANY-method
#' findKNN,matrix-method
#' findKNN,externalptr-method
#'
#' @examples
#' Y <- matrix(rnorm(100000), ncol=20)
Expand Down
2 changes: 2 additions & 0 deletions R/findNeighbors.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#' @aliases
#' findNeighbors,matrix,ANY-method
#' findNeighbors,externalptr,ANY-method
#' findNeighbors,matrix-method
#' findNeighbors,externalptr-method
#'
#' @name findNeighbors
NULL
Expand Down
2 changes: 2 additions & 0 deletions R/queryKNN.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#' @aliases
#' queryKNN,matrix,ANY-method
#' queryKNN,externalptr,ANY-method
#' queryKNN,matrix-method
#' queryKNN,externalptr-method
#'
#' @examples
#' Y <- matrix(rnorm(100000), ncol=20)
Expand Down
4 changes: 3 additions & 1 deletion R/queryNeighbors.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@
#' @aliases
#' queryNeighbors,matrix,ANY-method
#' queryNeighbors,externalptr,ANY-method
#' queryNeighbors,matrix-method
#' queryNeighbors,externalptr-method
#'
#' @name queryNeighbors
NULL

#' @export
setMethod("queryNeighbors", c("ANY", "ANY"), function(X, query, threshold, get.index=TRUE, get.distance=TRUE, num.threads=1, subset=NULL, transposed=FALSE, ..., BPPARAM=NULL, BNPARAM=NULL) {
setMethod("queryNeighbors", c("matrix", "ANY"), function(X, query, threshold, get.index=TRUE, get.distance=TRUE, num.threads=1, subset=NULL, transposed=FALSE, ..., BPPARAM=NULL, BNPARAM=NULL) {
ptr <- buildIndex(X, transposed=transposed, ..., BNPARAM=BNPARAM)
callGeneric(ptr, query=query, threshold=threshold, get.index=get.index, get.distance=get.distance, num.threads=num.threads, subset=subset, transposed=transposed, ..., BPPARAM=BPPARAM)
})
Expand Down
4 changes: 2 additions & 2 deletions man/AnnoyParam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions man/BiocNeighborParam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/ExhaustiveParam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/HnswParam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/KmknnParam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/VptreeParam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/buildIndex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/findKNN.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/findNeighbors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/queryKNN.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/queryNeighbors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 448186c

Please sign in to comment.