Skip to content

Commit

Permalink
#76 umap_transform crash with 0 rows
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmelville committed Apr 14, 2022
1 parent be493ed commit 43e76ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ umap_transform <- function(X = NULL, model = NULL,
X <- as.matrix(X[, indexes])
}
n_vertices <- nrow(X)
if (n_vertices < 1) {
stop("Not enough rows in X")
}
if (!is.null(row.names(X))) {
Xnames <- row.names(X)
}
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test_errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ nnsp10_nbr0 <- nnsp10
nnsp10_nbr0[, 5] <- 0
nnsp10_nbr0 <- Matrix::drop0(nnsp10_nbr0)
expect_error(umap(X = NULL, n_neighbors = 4, nn_method = nnsp10_nbr0), "at least one neighbor")

# 76: umap_transform does not validate input sufficiently
model <- umap(iris[1:10, ], n_neighbors = 4, n_epochs = 0, ret_model = TRUE)
expect_error(trans <- umap_transform(iris[0, ], model = model), "Not enough rows")

0 comments on commit 43e76ab

Please sign in to comment.