[Rcpp-devel] RcppArmadillo and sugar

Romain Francois romain at r-enthusiasts.com
Tue Aug 17 12:26:15 CEST 2010


Hello,

After the last thread, I looked again at armadillo and came up with a 
way to make it aware of Rcpp sugar, so that we can create an armadillo 
matrix from an Rcpp sugar expression, without having to assign the 
expression into an Rcpp vector.

For example :

	NumericVector xx(x) ;
	arma::mat m = forward( xx + xx ) ;

But also for complex expressions : (expressions that make complex 
vectors ) :

	ComplexVector xx(x) ;
	arma::cx_mat m = forward( exp( xx ) ) ;
	

It needs the svn version of both Rcpp and RcppArmadillo to work.
It does not deal with dimensions at the moment, it just makes a arma 
matrix with one column, I'll deal with that later.


The name forward might not be the right verb here, I was also thinking 
about "melt" so that we melt sugar into caramel, but I'd like to hear 
what others do with sugar.




BTW, one thing this gives is the construct :

arma::mat m = forward( NumericVector(x) ) ;

which I believe will be more efficient than

arma::mat m = Rcpp::as< arma::mat >( x ) ;

because it makes less copies. However I have not yet found a way to make 
it "borrow" the memory as in the advanced constructor in armadillo.


Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/bzoWrs : Rcpp svn revision 2000
|- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th
`- http://bit.ly/aAyra4 : highlight 0.2-2



More information about the Rcpp-devel mailing list