Le 18/08/10 06:56, Davor Cubranic a écrit :
On August 17, 2010 03:26:15 am Romain Francois wrote:
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.
[...]
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.

Can we use the same name that we already use for conversion of Rcpp
types to Armadillos? ('Rcpp::as'?) Conceptually, does it really matter
if we're melting a sugar expression or a plain old NumericVector?

Davor

It matters to the compiler.

The way as works, it has to know the target type because of its signature :

template <typename T> T as( SEXP m_sexp) throw(not_compatible)


And the target type here, the type that "forward" creates is not arma::mat, but rather something that the mat constructor will handle, and it depends on the input type of forward. For example :

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

forward makes an object of that type :

arma::Op<
Rcpp::VectorBase<REALSXP,true, Rcpp::sugar::Plus_Vector_Vector< REALSXP, true, Rcpp::NumericVector, true, Rcpp::NumericVector > > , Rcpp::RcppArmadillo::r_forward<REALSXP,true, Rcpp::sugar::Plus_Vector_Vector< REALSXP, true, Rcpp::NumericVector, true, Rcpp::NumericVector > >
>

you surely don't want to have this in the as angle brackets.





Now I suppose we could use overloading of as and make it coexists with another as with a different signature :

template <typename T>
template <typename U>
some_appropriate_lazy_type<T,U> as( const U& u )

but I am not sure how feasible this is.



Another way of course would be to hijack armadillo, which we can do as RcppArmadillo contains it, so that Mat has a constructor taking a sugar expression, so that w would simply do :

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

The problem (not an impossible situation, but still a problem) is that it will require manual intervention each time we upgrade to a new armadillo.

Plus I think I like to have at least something explicit.

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

_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to