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

Dirk Eddelbuettel edd at debian.org
Mon Nov 19 17:54:03 CET 2012


On 19 November 2012 at 10:47, Douglas Bates wrote:
| Sigh.  Speaking as one of the "Julia guys" I should point out two things (not
| that they will change Dirk's "cold, dead hands" attitude towards Julia :-)

No, just "lazy apt-get-able awaiting" hands.
 
| 1. Comprehensions provide what I feel is a clean syntax for sugar-like
| operations in Julia
| 
| 2. A problem with vectorization is the issue of multiple loops, hence the
| number of attempts at implementing delayed evaluation in compiled code (Eigen)
| and in add-on's to R.
| 
| A translation of Hadley's vacc3 into Julia could be
| 
| function vacc3a(age::Float64, female::Bool, ily::Float64){
|   p = 0.25 + 0.3 * 1 / (1 - exp(0.04 * age)) + 0.1 * ily
|   p *= female ? 1.25 : 0.75
|   min(max(0., p), 1.)
| }
| 
| out = [vacc3a(age[i], female[i], ily[i]) for i in 1:length(age)]
| 
| The comprehension collapses the
|  1. Determine the length of the output vector
|  2. Allocate the result
|  3. Loop over indices populating the result
|  4. Return the result
| 
| to a single syntactic element that, in my opinion, is quite readable.

Does that already give you parallel processing?  That is the one element
missing here and I was thinking that in order completely push Hadley over the
C++ cliff I should introduce him to OpenMP :)

The next real trick will be to get these things done transparently on all cores.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list