[Rcpp-devel] experimental operators code
romain at r-enthusiasts.com
romain at r-enthusiasts.com
Fri Jun 11 15:39:34 CEST 2010
Hello,
Somewhat motivated from Doug's recent question:
http://permalink.gmane.org/gmane.comp.lang.r.rcpp/412
I added some experimental code in Rcpp to allow this:
code <- '
NumericVector xx(x) ;
NumericVector ll(lowerBd) ;
return any( xx < ll ) ;
'
chkfun4 <- cxxfunction( signature( x = "numeric", lowerBd = "numeric" ),
code, plugin = "Rcpp" )
chkfun4(1, 0)
chkfun4(c(1, 0, 1), c(0, -Inf, 0))
This uses lazy evaluation so that "xx < ll " is not evaluated at this point, but each xx[i] < ll[i] is evaluated later (if and when they are needed). So for example :
xx <- c( 1, rep( 0, 100000 ) )
yy <- c( 2, rep( 0, 100000 ) )
chkfun4( xx, yy )
only has to compare 1 and 2. This should be as fast as Dirk's version, but it takes care of missing values. so
> chkfun4( NA, 1 )
[1] NA
Obviously, this will need some more abstraction so that we can have more operators (>, >=, <=, ==) and more functions (all, etc ...), but you get the idea.
Romain
More information about the Rcpp-devel
mailing list