RcppArmadillo 0.2.1
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Armadillo
Armadillo is a C++ linear algebra library aiming towards a good balance between speed and ease of use. Integer, floating point and complex numbers are supported, as well as a subset of trigonometric and statistics functions. Various matrix decompositions are provided through optional integration with LAPACK and ATLAS libraries.
A delayed evaluation approach is employed (during compile time) to combine several operations into one and reduce (or eliminate) the need for temporaries. This is accomplished through recursive templates and template meta-programming.
This library is useful if C++ has been decided as the language of choice (due to speed and/or integration capabilities), rather than another language like Matlab or Octave. It is distributed under a license that is useful in both open-source and commercial contexts.
Armadillo is primarily developed by Conrad Sanderson at NICTA (Australia), with contributions from around the world.
RcppArmadillo
RcppArmadillo is an R package that facilitates using Armadillo classes in R packages through Rcpp. It achieves the integration by extending Rcpp’s data interchange concepts to Armadillo classes.
Example
Here is a simple implementation of a fast linear regression (provided by RcppArmadillo via the fastLm() function):
Note however that you may not want to compute a linear regression fit this way in order to protect from numerical inaccuracies on rank-deficient problems. The help page for fastLm() provides an example.
Using RcppArmadillo in other packages
RcppArmadillo is designed so that its classes can be used from other packages.
Using RcppArmadillo requires:
Using the header files provided by Rcpp and RcppArmadillo. This is typically achieved by adding this line in the DESCRIPTION file of the client package:
LinkingTo : Rcpp, RcppArmadillo
and the following line in the package code:
#include <RcppArmadillo.h>
Linking against Rcpp dynamic or shared library and librairies needed by Armadillo, which is achieved by adding this line in the src/Makevars file of the client package
PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" ) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
and this line in the file src/Makevars.win:
PKG_LIBS = $(shell Rscript.exe -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
RcppArmadillo contains a function RcppArmadillo.package.skeleton, modelled after package.skeleton from the utils package in base R, that creates a skeleton of a package using RcppArmadillo, including example code.
Quality Assurance
RcppArmadillo uses the RUnit package by Matthias Burger et al to provide unit testing. RcppArmadillo currently has 19 unit tests (called from 8 unit test functions).
Source code for unit test functions are stored in the unitTests directory of the installed package and the results are collected in the RcppArmadillo-unitTests vignette.
We run unit tests before sending the package to CRAN on as many systems as possible, including Mac OSX (Snow Leopard), Debian, Ubuntu, Fedora 12 (64bit), Win 32 and Win64.
Unit tests can also be run from the installed package by executing
RcppArmadillo:::test()
where an output directory can be provided as an optional first argument.
Links
- Armadillo : http://arma.sourceforge.net/
- RcppArmadillo main page: http://dirk.eddelbuettel.com/code/rcpp.armadillo.html
- R-forge Rcpp project page: http://r-forge.r-project.org/projects/rcpp/
- Dirk’s blog : http://dirk.eddelbuettel.com/blog/code/rcpp/
- Romain’s blog : http://romainfrancois.blog.free.fr/index.php?category/R-package/RcppArmadillo
Support
Questions about RcppArmadillo should be directed to the Rcpp-devel mailing list at https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Questions about Armadillo itself should be directed to its forum http://sourceforge.net/apps/phpbb/arma/
-- Romain Francois, Montpellier, France Dirk Eddelbuettel, Chicago, IL, USA Doug Bates, Madison, WI, USA May 2010
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.