Skip to content
Prev 2397 / 10988 Next

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

Dear Romain,

Thank you very much for your help. I tried what you suggested by 
including the following templated function in templatedFunction.h, as 
follows:
template <typename T>
Rcpp::Vector< Rcpp::traits::r_sexptype_traits<T>::rtype >
ublas2rcpp( const vector<T>& x ){
return Rcpp::Vector< r_sexptype_traits<T>::rtype >(
x.begin(), x.end()
) ;
}
In addition, I have tested the function using in subgraph.cpp:
Rcpp::Vector<int> xY = ublas2rcpp(Y);

And I got the following error messages:
templatedFunction.h: In function 
?Rcpp::Vector<Rcpp::traits::r_sexptype_traits<T>::rtype> 
ublas2rcpp(const boost::numeric::ublas::vector<T>&)?:
templatedFunction.h:50:26: error: ?r_sexptype_traits? was not declared 
in this scope
templatedFunction.h:50:45: error: template argument 1 is invalid
subgraph.cpp: In function ?SEXPREC* cxx_Mask2Graph(SEXPREC*, SEXPREC*, 
SEXPREC*, SEXPREC*)?:
subgraph.cpp:32:19: error: type/value mismatch at argument 1 in template 
parameter list for ?template<int RTYPE> class Rcpp::Vector?
subgraph.cpp:32:19: error: expected a constant of type ?int?, got ?int?
subgraph.cpp:32:24: error: invalid type in declaration before ?=? token
subgraph.cpp:32:38: error: invalid conversion from ?SEXPREC*? to ?int?
subgraph.cpp:34:8: error: invalid conversion from ?int? to ?SEXPREC*?
...

Also, as an aside, I was wondering what I should use instead of 
push_back for Rcpp Vectors. Do I necessarily have to specify the size of 
the vector before I assign its elements to specific values?

Thanks a lot,
Cedric
On 01/06/11 11:44, Romain Francois wrote: