Re: [Rcpp-devel] Dispatching based on SEXPTYPE

2012-11-20 Thread Hadley Wickham
> switch(x.sexp_type()) { > case REALSXP: > return wrap(unique1(as(x))); > break; > case INTSXP: > return wrap(unique1(as(x))); > break; > case CHARSXP: That should be STRSXP, of course. Hadley -- RStudio / Rice University http://had.co.nz/

[Rcpp-devel] Dispatching based on SEXPTYPE

2012-11-20 Thread Hadley Wickham
Hi all, I've attached a simple implementation of unique for numeric, integer, logical, and character vectors. To do that I have four C++ function, along the lines of : std::tr1::unordered_set unique1(NumericVector x) { return std::tr1::unordered_set(x.begin(), x.end()); } and then one exporte

Re: [Rcpp-devel] R vectorisation vs. C++ vectorisation

2012-11-20 Thread Hadley Wickham
>> I don't think they _have_to - my understanding is that the expression >> template approach is general enough that you could compile away those >> intermediates. It may be extremely difficult to do though! > > That's the issue in delayed evaluation. You do a lot of template magic to > discover

Re: [Rcpp-devel] R vectorisation vs. C++ vectorisation

2012-11-20 Thread Hadley Wickham
> In my case, informed by interesting benchmarks such as yours, I now tend > to write my R functions with optimizing to C++ in mind. In other words, > I've stopped being ashamed of having loops in my R code. > > If my R script completes Quick Enough I don't care. But when it takes > Too Long, I kno

Re: [Rcpp-devel] R vectorisation vs. C++ vectorisation

2012-11-20 Thread Douglas Bates
On Tue, Nov 20, 2012 at 9:54 AM, Hadley Wickham wrote: > > P.S. I don't think the sugar versions can be made any quicker, because > > they have to allocate intermediate vectors, and do more memory copies. > > I don't think they _have_to - my understanding is that the expression > template approac

Re: [Rcpp-devel] R vectorisation vs. C++ vectorisation

2012-11-20 Thread Dirk Eddelbuettel
On 20 November 2012 at 09:40, Douglas Bates wrote: | I'd reply to your questions that yes Sebastian Villemot and Elliot Saba are | working on the Debian packaging (last weekend there was a big commit that | reorganized the files to facilitate this) and Jeff has announced comprehensions | on distr

Re: [Rcpp-devel] R vectorisation vs. C++ vectorisation

2012-11-20 Thread Hadley Wickham
>> 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

Re: [Rcpp-devel] R vectorisation vs. C++ vectorisation

2012-11-20 Thread Hadley Wickham
> P.S. I don't think the sugar versions can be made any quicker, because > they have to allocate intermediate vectors, and do more memory copies. I don't think they _have_to - my understanding is that the expression template approach is general enough that you could compile away those intermediate

Re: [Rcpp-devel] R vectorisation vs. C++ vectorisation

2012-11-20 Thread Douglas Bates
On Mon, Nov 19, 2012 at 11:36 AM, Hadley Wickham 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

Re: [Rcpp-devel] R vectorisation vs. C++ vectorisation

2012-11-20 Thread Douglas Bates
I'd reply to your questions that yes Sebastian Villemot and Elliot Saba are working on the Debian packaging (last weekend there was a big commit that reorganized the files to facilitate this) and Jeff has announced comprehensions on distributed arrays, although I haven't tried using it yet. Howeve