Skip to content
Prev 2396 / 10988 Next

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

Hi,

I've not used uBlas, but what you are trying to do is quite similar to 
what we do in RcppArmadillo.

You can probably manage to guess the output type from the input type, so 
you only have to parameterise your template on the input type. something 
like (untested) :

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()
	)  ;
}

This way you don't have to specify template parameter when you call 
ublas2rcpp because the compiler is smart enough.

Nicer than this would be to implement wrap and as for ublas vectors, the 
way to go is documented in the Rcpp-extended vignettes, with examples 
implementations in RcppArmadillo and RcppGSL.

As a side note, you don't want to use push_back on Rcpp types, because 
it creates a new vector each time, so this is HUGE memory waste.

Now, this could get much smarter as ublas has vector expressions, 
similar to armadillo, so I suppose someone could write something like 
RcppUBlas with nice goodies. This is not me, at least not now ;-)

Romain


Le 01/06/11 12:24, Cedric Ginestet a ?crit :