[Rcpp-devel] Struggling with Rcpp sugar
Hadley Wickham
h.wickham at gmail.com
Sun Nov 18 16:12:56 CET 2012
>> microbenchmark(
>> pdist1(0.5, ys),
>> pdist2(0.5, ys),
>> pdist3(0.5, ys)
>> )
>> # 10-fold slower?? Maybe it's because I'm using a double instead of
>> # a numeric vector?
>
> That's weird. Not sure where the ineffiency is. Some hunting.
> My guess is that sugar pow needs a refresh.
Ok, thanks.
>> cppFunction('
>> NumericVector pdist4(NumericVector x, NumericVector ys) {
>> return pow((x - ys), 2);
>> }
>> ')
>> all.equal(pdist1(0.5, ys), pdist4(0.5, ys))
>>
>> # Is this a bug in sugar? Should recycle to length of longest vector.
>> # Let's try flipping the order of operations:
>
>
> There's no recycling. We pick the size of "x" and consider that y is of the
> same length. Something worth mentionning in documentation. Recycling would
> add some expense.
I think that should be called in large bold print somewhere! If you
don't do it automatically - could it at least be an error when the
sizes don't match? That doesn't seem like it should be an expensive
operation.
> I would prefer to keep it that way and document it that vector should have
> the same size, ... rather than introduce the extra cost of recyling.
I might also be nice to have some capabilities for explicit recycling.
I don't know if it would be possible to get it to work, but it would
be nice to have some sort of declarative syntax like:
recycle(x, y, z);
Hadley
--
RStudio / Rice University
http://had.co.nz/
More information about the Rcpp-devel
mailing list