Question

I would like to utilize both RcppArmadillo and RcppGSL via sourceCpp. Basically I am interested in modifying the B-spline example

http://dirk.eddelbuettel.com/blog/2012/12/08/

so that the B-splines are functions of R^3 instead of only R^1. This entails working with 3-dimensional arrays which apparently is not supported in GSL (there is an extension here http://savannah.nongnu.org/projects/marray though). However, RcppArmadillo has the arma::cube type which I could use if only I could get RcppArmadillo and RcppGSL to "work together." This I am unfortunately not able to do. I have looked at

Multiple plugins in cxxfunction

but have not succeeded in creating the mentioned combined plugin. Any help is greatly appreciated!

Adam

Edit: It seems like it is actually possible to compile a .cpp file with sourceCpp containing the following sequence of commands at the top:

// [[Rcpp::depends(RcppGSL)]]
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
#include <RcppGSL.h>
#include <gsl/gsl_bspline.h>

Furthermore, it also seems possible to store values like

double gsl_vector_get (const gsl_vector * v, size_t i)

in an arma::cube structure.

Was it helpful?

Solution

RcppArmadillo.h and RcppGSL.h are modelled similarly. They first include RcppCommon.h, then some forward declarations, then they include Rcpp.h that uses those forward declarations, then implementations.

It is definitely possible to use them both if you come up with the right order of includes.

This is definitely an Rcpp question as what is preventing you from using them both is (good or bad) design decisions.

You need to study RcppArmadillo.h and RcppGSL.h and come up with the right include order, or wait for someone to follow these hints and give you the answer. I might not have time to do it myself in the next few days.

OTHER TIPS

Armadillo types and GSL types are not interchangeable.

You could rewrite the GSL algorithm for Armadillo, but it is not automatic but any means. I am also not sure if the theory behind splines extends just like that from the real line to three-dimensions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top