[Rcpp-devel] Loops, iterators and accumulate

Romain Francois romain at r-enthusiasts.com
Thu Nov 15 15:17:37 CET 2012


Le 15/11/12 15:14, Hadley Wickham a écrit :
> On Thu, Nov 15, 2012 at 8:11 AM, Romain Francois
> <romain at r-enthusiasts.com> wrote:
>> I'm not getting the same results, so I might not make the same conclusions:
>>
>>
>> Unit: microseconds
>>        expr    min     lq  median      uq    max
>> 1   sum(x) 16.072 16.161 16.2090 16.3110 21.721
>> 2  sum1(x) 10.771 10.954 11.0445 11.1910 16.163
>> 3  sum2(x) 48.438 48.567 48.6650 48.8425 61.116
>> 4 sum2a(x) 10.806 10.965 11.0695 11.2080 17.401
>> 5  sum3(x) 10.835 10.967 11.0490 11.1875 23.943
>> 6  sum4(x) 10.847 10.989 11.0690 11.2160 16.331
>>
>> For me that makes more sense.
>
> I just discovered the problem with my accumulate.  I was doing:
>
> double total = std::accumulate(x.begin(), x.end(), 0);
>
> instead of
>
> double total = std::accumulate(x.begin(), x.end(), 0.0);
>
> Hadley

Ah. Interesting. That makes sense, lots of conversion from double to int 
to accumulate into an int.

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com
`- http://bit.ly/SweN1Z : SuperStorm Sandy

blog:            http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible



More information about the Rcpp-devel mailing list