RfastOfficial/Rfast

Faster `colCumSums` in `matrixStats`

Opened this issue · 1 comments

Describe the speed issue
colCumSums is slower than expected.

To Reproduce

library(Rfast)
library(matrixStats)
set.seed(1618532146)
x <- matrix(runif(1e4), 100, 100)
y <- matrix(runif(1e6), 1e3, 1e3)
microbenchmark::microbenchmark(
  colCumsums(x), # matrixStats
  colCumSums(x), # Rfast
  check = "identical",
  unit = "relative"
)
#> Unit: relative
#>           expr      min       lq     mean  median       uq      max neval
#>  colCumsums(x) 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000   100
#>  colCumSums(x) 1.417582 1.466667 1.444478 1.45679 1.441109 1.893491   100

microbenchmark::microbenchmark(
  colCumsums(y), # matrixStats
  colCumSums(y), # Rfast
  check = "identical",
  unit = "relative"
)
#> Unit: relative
#>           expr      min       lq     mean   median       uq      max neval
#>  colCumsums(y) 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000   100
#>  colCumSums(y) 1.943892 1.892468 1.648744 1.824067 2.484606 1.775137   100

Expected behavior
matrixStats::colCumsums is faster.

Desktop:

  • OS: Windows 10 64-bit
  • R-Version 4.3.0
  • Rfast-Version 2.1.0

It seems that I must change the algorithm. Thanks for the observation.