Publications by romain francois
A taste of functional programmming in Rcpp11
@kevinushey requested some functional programming in Rcpp11 and provided initial versions of map and filter. map is actually doing exactly the same thing as mapply so I added map as a synonym to mapply so that we can do (see this previous post for details): // [[Rcpp::export]] NumericVector mapply_example(NumericVector x, NumericVector y, double...
1471 sym R (2314 sym/7 pcs)
Reduce in Rcpp11
And now for something completely difference, the reduce function, doing something similar to what the Reduce function does in R: #include <Rcpp.h> using namespace Rcpp ; // [[Rcpp::export]] double reduce_example(NumericVector x ){ auto add = [](double a, double b){ return a + b ;} ; return reduce(x, add ) ; } /*** R x <- 1:10 re...
548 sym R (310 sym/2 pcs)
Vectorized vs Devectorized
This gist from @hadley has been on my mind for some time. This was already a follow up of this post from @johnmyleswhite. The problem was that sugar vectorised code suffered a performance penalty compared to devectorised code. This is particularly troubling me because the whole point of sugar is to have nice syntax without paying the price of the...
4526 sym R (4882 sym/13 pcs) 1 tbl
Disambiguating Rcpp11 and Rcpp
I pushed some code this morning to allow us to use this alternative syntax to use Rcpp11. #include <Rcpp11> using namespace Rcpp11 ; Of course the usual code will continue to work, and might even be preferable if you write code that needs to be compatible with both Rcpp11 and Rcpp, e.g. when doing comparative benchmarks … #include <Rcpp.h> u...
755 sym R (88 sym/2 pcs)
Modernizing sugar in Rcpp11
I’m in the process of modernizing the implementation of sugar in Rcpp11. Previous work already improved performance of sugar by allowing sugar classes themselves to implement how to apply themselves into their target vector. For example the sugar class SeqLen leverages std::iota instead of a manual for loop. template <typename Target> inline ...
3553 sym R (2678 sym/14 pcs) 2 img
sapply with variadic trailing arguments (…)
Motivation In R, we can pass further arguments to sapply. The arguments are then passed the function to be applied over. x <- seq(-3, 3, by=.2 ) sapply( x, dnorm, 0, 4, FALSE ) Conceptually this does something like: sapply( x, function(.){ dnorm(.,0,4,FALSE) } ) Implementation in Rcpp11 sapply has been part of sugar for a long time, a...
1451 sym R (3717 sym/10 pcs)
subset vectors in Rcpp11
[ ] Under the impulsion of @kevin_ushey who already did something similar for Rcpp, we’ve been adding subsetting behavior into Rcpp11. The idea is given a vector y and a vector x we want to give meaning to y[x]. The first legitimate question is what kind of x do we want to allow. This has been discussed since january. So far, we’ve s...
1934 sym R (1602 sym/6 pcs)
useR!2014 Rcpp11 tutorial
We are getting close to useR!2014. I hope I’ll see some of you at my tutorial about Rcpp11 in the morning. There are some other pretty useful tutorials as well, so no hard feeling if you don’t come, but if you do want to know about modern R and C++, please join me. Personally I’m happy I’m doing a tutorial because it would have been hard ...
3490 sym R (295 sym/4 pcs)
sugar in parallel
I’ve been playing with parallelising Rcpp11 implementation of sugar. For example, we have a NumericVector variable x and we want to compute e.g. sqrt(exp(x)) + 2.0. With sugar, we can do: NumericVector y = sqrt(exp(x)) + 2.0 ; and this does not generate useless temporaries as what R would do. This pitch has sailed already. Here are some ben...
2709 sym R (2763 sym/8 pcs) 2 img
Keep calm and #include <Rcpp11>
Following up on this post, I have just commited some code that makes the using namespace Rcpp11 ; automatic, I was just tired of typing it. So now, you can just do : #include <Rcpp11> If however, for some weird reason (some people love littering their code with Rcpp::) you don’t want the using namespace Rcpp11; to be automatically added, you ...
1076 sym R (262 sym/4 pcs)