From sokol at insa-toulouse.fr  Thu Apr 26 11:31:47 2018
From: sokol at insa-toulouse.fr (Serguei Sokol)
Date: Thu, 26 Apr 2018 11:31:47 +0200
Subject: [Rd] mean(x) for ALTREP
Message-ID: <f54570f6-d2c6-e835-9d00-7a50cfda8a90@insa-toulouse.fr>

Hi,

By looking at a doc about ALTREP 
https://svn.r-project.org/R/branches/ALTREP/ALTREP.html (by the way 
congratulations for that and for R-3.5.0 in general), I was a little bit 
surprised by the following example:

 > x <- 1:1e10
 > system.time(print(mean(x)))
[1] 5e+09
 ?? user? system elapsed
 ?38.520?? 0.008? 38.531

Taking 38.520 s to calculate a mean value of an arithmetic sequence 
seemed a lot to me. It probably means that calculations are made by 
running into a for loop while in the case of arithmetic sequence a mean 
value can simply be calculated as (b+e)/2 where b and e are the begin 
and end value respectively. Is it planned to take benefit of ALTREP for 
functions like mean(), sum(), min(), max() and some others to avoid 
running a for loop wherever possible? It seems so natural to me but 
after all some implementation details preventing this can escape to me.

Best,
Serguei.



[Rd] mean(x) for ALTREP
Serguei Sokol