
rsparse is an R package for statistical learningprimarily onsparse matrices -matrixfactorizations, factorization machines, out-of-core regression.Many of the implemented algorithms are particularly useful forrecommender systems andNLP.
We’ve paid some attention to the implementation details - we try toavoid data copies, utilize multiple threads via OpenMP and use SIMDwhere appropriate. Packageallows to work on datasets withmillions of rows and millions of columns.
Matrix::RsparseMatrix. However common RMatrix::CsparseMatrix (dgCMatrix) will beconverted automatically.WRMF class andconstructor optionfeedback = "explicit". Original paperwhich indroduced MMMF could be foundhere.
WRMF class andconstructor optionfeedback = "implicit". We provide 2solvers:




Note: the optimized matrix operations whichrparseused to offer have been moved to aseparatepackage
Most of the algorithms benefit from OpenMP and many of them couldutilize high-performance implementations of BLAS. If you want to makethe maximum out of this package, please read the section belowcarefully.
It is recommended to:
~/.R/Makevars. For example on recent processors (with AVXsupport) and compiler with OpenMP support, the following lines could bea good option:CXX11FLAGS += -O3 -march=native -fopenmpCXXFLAGS += -O3 -march=native -fopenmpIf you are onMac follow the instructions athttps://mac.r-project.org/openmp/.Afterclang configuration, additionally put aPKG_CXXFLAGS += -DARMA_USE_OPENMP line in your~/.R/Makevars. After that, installrsparse inthe usual way.
Also we recommend to usevecLib- Apple’s implementations of BLAS.
ln-sf /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylibOn Linux, it’s enough to just create this file if it doesn’t exist(~/.R/Makevars).
If using OpenBLAS, it is highly recommended to use theopenmp variant rather than thepthreadsvariant. On Linux, it is usually available as a separate package intypical distribution package managers (e.g. for Debian, it can beobtained by installinglibopenblas-openmp-dev, which is notthe default version), and if there are multiple BLASes installed, can beset as the default through theDebianalternatives system - which can also be usedfor MKL.
By default, R for Windows comes with unoptimized BLAS and LAPACKlibraries, andrsparse will prefer using Armadillo’sreplacements instead. In order to use BLAS,installrsparse from source (not from CRAN), removing theoption-DARMA_DONT_USE_BLAS fromsrc/Makevars.win and ideally adding-march=native (underPKG_CXXFLAGS). Seethistutorial for instructions on getting R for Windows to use OpenBLAS.Alternatively, Microsoft’s MRAN distribution for Windows comes withMKL.
Note that syntax is these posts/slides is not up to datesince package was under active development
Here is example ofrsparse::WRMF onlastfm360k dataset incomparison with other good implementations:

We followmlapiconventions.
Don’t forget to addDARMA_NO_DEBUG toPKG_CXXFLAGS to skip bound checks (this has significantimpact on NNLS solver)
PKG_CXXFLAGS = ... -DARMA_NO_DEBUGGenerate configure:
autoconf configure.ac> configure&&chmod +x configure