Skip to content

Commit

Permalink
Fix: load failed when number of cores == 1 (#6)
Browse files Browse the repository at this point in the history
* Fix: load failed when number of cores == 1
When the number of cores was 1, `round(parallel::detectCores() / 2)`
returned 0, which caused .onLoad to fail.
This fixes issue #4

* cran version 0.3.5

* added CRAN-SUBMISSION file
  • Loading branch information
aviezerl authored Aug 29, 2022
1 parent 3a68d62 commit 4ef35ef
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.3.4
Date: 2022-04-19 07:36:07 UTC
SHA: 7069dbd5ba09a7199386c2691768f135fc407183
Version: 0.3.5
Date: 2022-08-27 20:16:58 UTC
SHA: a22572c46cf5291dc364afc5415806ca30b5814e
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tglkmeans
Title: Efficient Implementation of K-Means++ Algorithm
Version: 0.3.4
Version: 0.3.5
Authors@R:
c(person(given = "Aviezer",
family = "Lifshitz",
Expand Down Expand Up @@ -35,10 +35,11 @@ Suggests:
knitr,
rlang,
rmarkdown,
testthat
testthat,
withr
LinkingTo:
Rcpp
VignetteBuilder:
VignetteBuilder:
knitr
Encoding: UTF-8
NeedsCompilation: yes
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# tglkmeans (development version)
# tglkmeans 0.3.5

* Changed errors from cpp to 1 based indexing.
* fix: loading the package failed on machines with a single core.

# tglkmeans 0.3.4

* First CRAN release.

# tglkmeans 0.3.3

* Set NA values to zeros in correlation matrix when reordering clusters
Expand Down
2 changes: 1 addition & 1 deletion R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' }
#' @export
tglkmeans.set_parallel <- function(thread_num) {
if (1 == thread_num) {
if (thread_num <= 1) {
options(tglkmeans.parallel = FALSE)
} else {
doFuture::registerDoFuture()
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.onLoad <- function(libname, pkgname) {
tglkmeans.set_parallel(round(parallel::detectCores() / 2))
tglkmeans.set_parallel(pmax(1, round(parallel::detectCores() / 2)))
utils::suppressForeignCheck(c("clust", "new_clust", "true_clust", "intra_clust_order", "idx"))
utils::globalVariables(c("clust", "new_clust", "true_clust", "intra_clust_order", "idx"))
}
8 changes: 2 additions & 6 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

0 errors | 0 warnings | 0 notes

## DESCRIPTION changes
# Fix

* Added Weizmann Institute of Science as cph
* Added references of the original algorithm to the description part.
* loading the package failed on machines with a single core.

## Regarding the use of cores in the examples

* Added \donttest clause wrapping `tglmeans.set_parallel` examples section. The other examples work with a single core.
28 changes: 23 additions & 5 deletions tests/testthat/test-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,30 @@ test_that("onLoad does not fail", {
})

context("number of threads")
test_that("parallel is turned off when number of threads is 1", {
tglkmeans.set_parallel(1)
expect_false(getOption("tglkmeans.parallel"))
test_that("parallel is turned off when number of threads <= 1", {
withr::with_options(
list(tglkmeans.parallel = TRUE),
{
tglkmeans.set_parallel(1)
expect_false(getOption("tglkmeans.parallel"))
}
)

withr::with_options(
list(tglkmeans.parallel = TRUE),
{
tglkmeans.set_parallel(0)
expect_false(getOption("tglkmeans.parallel"))
}
)
})

test_that("parallel is turned on when number of threads is not 1", {
tglkmeans.set_parallel(2)
expect_true(getOption("tglkmeans.parallel"))
withr::with_options(
list(tglkmeans.parallel = FALSE),
{
tglkmeans.set_parallel(2)
expect_true(getOption("tglkmeans.parallel"))
}
)
})

0 comments on commit 4ef35ef

Please sign in to comment.