RcppArmadillo 0.2.1

May 19, 2010
By

(This article was first published on Romain Francois, Professional R Enthusiast, and kindly contributed to R-bloggers)

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

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

To leave a comment for the author, please follow the link and comment on his blog: Romain Francois, Professional R Enthusiast.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , ,

Comments are closed.