Skip to content

Commit

Permalink
#39: check for non-integer n_threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmelville committed Dec 2, 2019
1 parent 0158291 commit 98f8edd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/uwot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1161,12 +1161,20 @@ uwot <- function(X, n_neighbors = 15, n_components = 2, metric = "euclidean",
if (n_threads < 0) {
stop("n_threads cannot be < 0")
}
if (n_threads %% 1 != 0) {
n_threads <- round(n_threads)
message("Non-integer 'n_threads' provided. Setting to ", n_threads)
}
if (n_sgd_threads == "auto") {
n_sgd_threads <- n_threads
}
if (n_sgd_threads < 0) {
stop("n_sgd_threads cannot be < 0")
}
if (n_sgd_threads %% 1 != 0) {
n_sgd_threads <- round(n_sgd_threads)
message("Non-integer 'n_sgd_threads' provided. Setting to ", n_sgd_threads)
}
if (n_threads > 0) {
RcppParallel::setThreadOptions(numThreads = n_threads)
}
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,12 @@ res <- umap(iris10, pcg_rand = FALSE,
)
expect_ok_matrix(res)

# https://github.com/jlmelville/uwot/issues/39
res <- umap(iris10, n_neighbors = 4, n_threads = 0.5)
expect_ok_matrix(res)
res <- umap(iris10, n_neighbors = 4, n_threads = 1.5)
expect_ok_matrix(res)
res <- umap(iris10, n_neighbors = 4, n_sgd_threads = 0.5)
expect_ok_matrix(res)
res <- umap(iris10, n_neighbors = 4, n_sgd_threads = 1.5)
expect_ok_matrix(res)

0 comments on commit 98f8edd

Please sign in to comment.