Simone Giannerini
2020-May-18 15:23 UTC
[Rd] parRapply and parCapply return a list in corner cases
According to ?parCapply: parRapply and parCapply always return a vector. This appears not to be the case in the following minimal reproducible example:> library(parallel) > nslaves <- 2 > cl <- makeCluster(nslaves) > X <- matrix(2,nrow=3,ncol=4) > X <- rbind(c(1,1,0,1),X) > tv <- parCapply(cl,X,FUN=function(x){+ ind <- x[1] + y <- x[-1] + if(ind==1){ + r1 <- sum(y) + }else{ + r1 <- logical(0) + } + return(unlist(as.numeric(c(ind,r1)))) + })> tv[[1]] [1] 1 [[2]] [1] 6 [[3]] [1] 1 [[4]] [1] 6 [[5]] [1] 0 [[6]] [1] 1 6> class(tv)[1] "list"> sessionInfo()R version 4.0.0 (2020-04-24) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363) Matrix products: default locale: [1] LC_COLLATE=Italian_Italy.1252 LC_CTYPE=Italian_Italy.1252 [3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C [5] LC_TIME=Italian_Italy.1252 attached base packages: [1] parallel stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_4.0.0 -- _________________________________________________________________ PHILOSOPHICAL TRANSACTIONS OF THE ROYAL SOCIETY A Theme issue ?DNA as information? edited by Julyan H.E. Cartwright, Simone Giannerini and Diego L. Gonz?lez _________________________________________________________________ Simone Giannerini Dipartimento di Scienze Statistiche "Paolo Fortunati" Universita' di Bologna Via delle belle arti 41 - 40126 Bologna, ITALY Tel: +39 051 2098262 Fax: +39 051 232153 https://www.unibo.it/sitoweb/simone.giannerini/
Simone Giannerini
2020-Sep-12 09:11 UTC
[Rd] parRapply and parCapply return a list in corner cases
For the record: I filed a bug report here
https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17807
and this is a more polished minimal example
library(parallel)
nslaves <- 2
cl <- makeCluster(nslaves)
X <- matrix(c(1,0,1),1,3)
res <- parCapply(cl,X,FUN=function(x){
y <- x[1]
if(y==1){
out <- y
}else{
out <- double(0)
}
return(out)
})
> res
[[1]]
[1] 1
[[2]]
numeric(0)
[[3]]
[1] 1
Simone
On Mon, May 18, 2020 at 5:23 PM Simone Giannerini <sgiannerini at
gmail.com> wrote:>
> According to ?parCapply:
>
> parRapply and parCapply always return a vector.
>
> This appears not to be the case in the following minimal reproducible
example:
>
> > library(parallel)
> > nslaves <- 2
> > cl <- makeCluster(nslaves)
> > X <- matrix(2,nrow=3,ncol=4)
> > X <- rbind(c(1,1,0,1),X)
> > tv <- parCapply(cl,X,FUN=function(x){
> + ind <- x[1]
> + y <- x[-1]
> + if(ind==1){
> + r1 <- sum(y)
> + }else{
> + r1 <- logical(0)
> + }
> + return(unlist(as.numeric(c(ind,r1))))
> + })
> > tv
> [[1]]
> [1] 1
>
> [[2]]
> [1] 6
>
> [[3]]
> [1] 1
>
> [[4]]
> [1] 6
>
> [[5]]
> [1] 0
>
> [[6]]
> [1] 1 6
>
> > class(tv)
> [1] "list"
> > sessionInfo()
> R version 4.0.0 (2020-04-24)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 10 x64 (build 18363)
>
> Matrix products: default
>
> locale:
> [1] LC_COLLATE=Italian_Italy.1252 LC_CTYPE=Italian_Italy.1252
> [3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C
> [5] LC_TIME=Italian_Italy.1252
>
> attached base packages:
> [1] parallel stats graphics grDevices utils datasets
> methods base
>
> loaded via a namespace (and not attached):
> [1] compiler_4.0.0
>
> --
> _________________________________________________________________
>
> PHILOSOPHICAL TRANSACTIONS OF THE ROYAL SOCIETY A
> Theme issue ?DNA as information?
> edited by Julyan H.E. Cartwright, Simone Giannerini and Diego L. Gonz?lez
> _________________________________________________________________
>
> Simone Giannerini
> Dipartimento di Scienze Statistiche "Paolo Fortunati"
> Universita' di Bologna
> Via delle belle arti 41 - 40126 Bologna, ITALY
> Tel: +39 051 2098262 Fax: +39 051 232153
> https://www.unibo.it/sitoweb/simone.giannerini/
> ______________________________________________________
--
___________________________________________________
Simone Giannerini
Dipartimento di Scienze Statistiche "Paolo Fortunati"
Universita' di Bologna
Via delle belle arti 41 - 40126 Bologna, ITALY
Tel: +39 051 2098262 Fax: +39 051 232153
https://simonegiannerini.net/
Seemingly Similar Threads
- Under Windows, Rgui and Rterm crash if one tries to close the graphic device while identify or locator are running
- Under Windows, Rgui and Rterm crash if one tries to close the graphic device while identify or locator are running
- bug in plot.ts?
- quantile(), IQR() and median() for factors
- parApply vs parCapply