[Rcpp-devel] Question on syntactic sugar

Dirk Eddelbuettel edd at debian.org
Mon Jan 9 16:10:37 CET 2012


Hi Gregor,

On 9 January 2012 at 12:46, Gregor Kastner wrote:
| Thanks for the reply, Dirk.
| 
| > | I.e., is there a way to reproduce the following R code with Rcpp
| > (without | using loops)?
| > | 
| > | r <- c(1,11,111)
| > | index <- c(2,2,1)
| > | r[index]
| > 
| > That was just discussed _yesterday_ on this list.
| > 
| > And no, I don't think it is. Would be nice -- patches welcome.
| 
| I have caught up on older discussions - sorry, I just joined recently. Given
| my limited knowledge, the latest discussion about the convolution, and the
| digging I have been doing, I came up with the following rule of thumb. Am I
| right / do you agree?
| 
| Use native C/C++ data structures within loops whenever possible, paying
| attention to the "natural" storage order of objects if applicable.

That's almost too strong for me on the side of tuning.

As a first rule, go with Rcpp defaults, and Rcpp sugar if
applicable. Correctness first.

If profiling reveals bottlenecks, consider tricks as pointer / iterator
access. 

| Alternatively, use iterators or pay the - application dependent - price of
| operator overloading as discussed in your JSS article.

They are generally neglible, but there are times when they are seemingly
not. I don't think we ever really got back to Darren who found something odd
a few months ago (all discussed here on list).
 
| At the current point of development, "syntactic sugar indexing" can only be
| used for _assignment_ of a certain (consecutive) range, but not for
| extraction.

Yes, there is no Indexing class on top of the vectors at this point.
 
| Thanks for the comments and for this great piece of software.

Glad you like it!

Dirk

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list