[Rcpp-devel] R vectorisation vs. C++ vectorisation
Douglas Bates
bates at stat.wisc.edu
Tue Nov 20 16:44:01 CET 2012
On Mon, Nov 19, 2012 at 11:36 AM, Hadley Wickham <h.wickham at gmail.com>wrote:
> > To be fair with the R language, I would have compare with the use of real
> > primitives :
> >
> > vaccBubu <- function(age, female, ily) {
> > gender <- female * 1.25
> > gender[!female] <- 0.75
> > p <- (0.25 + 0.3 * 1 / (1 - exp(0.04 * age)) + 0.1 * ily) * gender
> > p[p < 0] <- 0
> > p[p > 1] <- 1
> > p
> > }
> >
>
> I think you could do it a bit more elegantly with
>
> gender <- 0.75 + female * 0.5
>
> but pmin and pmax are "real" primitives, so I think it's fine to use them.
In the folklore ifelse, pmin and pmax are know to be slow. I know that
there was some work on pmin and pmax but I think they are still more
sluggish than desired.
In early work on generalized linear mixed models i did some profiling and
discovered that an inordinate amount of time was spent on evaluating the
inverse link, derivative and variance functions and a lot of that could be
traced to pmin and pmax.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121120/df404730/attachment.html>
More information about the Rcpp-devel
mailing list