[Rcpp-devel] Loops, iterators and accumulate
Dale.Smith at Fiserv.com
Thu Nov 15 15:24:39 CET 2012
I'm not sure what compliers you are using out there, but gcc does have a way to enable warnings for this type of implicit conversion.
Warn for implicit conversions that may alter a value. This includes conversions between real and integer...
Please check this, as it's not entirely obvious from the description that it will pick up a warning in this case.
Dale Smith, Ph.D.
Senior Financial Quantitative Analyst
Risk & Compliance
107 Technology Park
Norcross, GA 30092
Mail: dale.smith at fiserv.com
From: rcpp-devel-bounces at r-forge.wu-wien.ac.at [mailto:rcpp-devel-bounces at r-forge.wu-wien.ac.at] On Behalf Of Romain Francois
Sent: Thursday, November 15, 2012 9:18 AM
To: Hadley Wickham
Subject: Re: [Rcpp-devel] Loops, iterators and accumulate
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);
Ah. Interesting. That makes sense, lots of conversion from double to int to accumulate into an int.
Professional R Enthusiast
+33(0) 6 28 91 30 30
R Graph Gallery: http://gallery.r-enthusiasts.com
`- http://bit.ly/SweN1Z : SuperStorm Sandy
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
More information about the Rcpp-devel