RfastOfficial / Rfast

A collection of Rfast functions for data analysis. Note 1: The vast majority of the functions accept matrices only, not data.frames. Note 2: Do not have matrices or vectors with have missing data (i.e NAs). We do no check about them and C++ internally transforms them into zeros (0), so you may get wrong results. Note 3: In general, make sure you give the correct input, in order to get the correct output. We do no checks and this is one of the many reasons we are fast.
139 stars 19 forks source link

mat.mult fails for long matrices #9

Closed aljabadi closed 4 years ago

aljabadi commented 4 years ago

Thanks for the great package. Just wondering why mat.mult with long matrices crashes my RStudio:

library(Rfast)
## ----- works
x <- matrnorm(200, 199)
y <- matrnorm(199, 200)
mat.mult(x, y)

## ----- crashes
x <- matrnorm(200, 201)
y <- matrnorm(201, 200)
mat.mult(x, y)
sessionInfo()
#> R version 3.6.1 (2019-07-05)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Catalina 10.15
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] magrittr_1.5
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_3.6.1      BiocManager_1.30.10 tools_3.6.1        
#>  [4] htmltools_0.4.0     yaml_2.2.0          Rcpp_1.0.3         
#>  [7] stringi_1.4.5       rmarkdown_1.18      highr_0.8          
#> [10] knitr_1.26          stringr_1.4.0       xfun_0.11          
#> [13] digest_0.6.23       rlang_0.4.2         evaluate_0.14

Created on 2020-01-23 by the reprex package (v0.3.0)

Best,

Al

aljabadi commented 4 years ago

I think I've misunderstood what mat.mult actually does. What kind of matrix multiplication is it that results in the following? Am I missing something?

library(Rfast)
#> Loading required package: Rcpp
#> Loading required package: RcppZiggurat
X <- matrix(1:4, ncol = 2)
Y <- matrix(4:1, ncol = 2)
X
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
Y
#>      [,1] [,2]
#> [1,]    4    2
#> [2,]    3    1
mat.mult(X, Y)
#>                [,1]           [,2]
#> [1,]  -3.276909e+10  -1.638455e+10
#> [2,]  2.780271e-309  1.390124e-309

Created on 2020-01-23 by the reprex package (v0.3.0)

ManosPapadakis95 commented 4 years ago

Which rfast version do you use? There was a bug in mat.mult once. Maybe I forgot to remove it... I will make some tests...

ManosPapadakis95 commented 4 years ago

There was a bug in mat.mult. I have fixed it for the next version.