[Rcpp-devel] Wrapping uBlas vectors into Rcpp Vectors.

Cedric Ginestet c.ginestet05 at googlemail.com
Wed Jun 1 12:24:05 CEST 2011


Dear Rcpp experts,

I have started to use the uBlas library, and I am trying to ensure that 
I can pass from uBlas vectors to Rcpp vectors relatively easily. So far, 
I have tried the following templated function:

///////////////////////////////////////////////////////////////////////
using namespace Rcpp;
using namespace boost::numeric::ublas;

template <class T1, class T2>
T1 ublas2rcpp(T2& uVec){
     T1 rcppVec;
     for(int i=0; i<uVec.size(); ++i) rcppVec.push_back(uVec(i));
return rcppVec;
}//ublas2rcpp.

////////
SEXP foo(vector<int> &y){
   ...
   IntegerVector rcppY=ublas2rcpp<IntegerVector,vector<int> >(y);
   ....
return rcppY;
}
///////////////////////////////////////////////////////////////////////

I have got two questions:
a. This templated function doesn't work. It compiles fine, but hangs 
when I try to run it in R. What do you think is faulty in the codes above?
b. Is there a better way to wrap uBlas vectors into Rcpp ones? Is that 
something that you are planning to implement (or have already 
implemented) within the Rcpp suite?

Thank you very much for your help,

-- 
Cedric Ginestet, PhD
Centre for Neuroimaging Sciences (L3.04)
NIHR Biomedical Research Centre
Department of Neuroimaging
Institute of Psychiatry, Box P089
King's College London
De Crespigny Park
London
SE5 8AF
http://arxiv.org/find/q-bio/1/au:+Ginestet_C/0/1/0/all/0/1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110601/df6e5aa3/attachment.htm>


More information about the Rcpp-devel mailing list