Skip to content
Prev 2395 / 10988 Next

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

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,