Initial request for review of JDK-8006572 DoubleStream.sum()/average() implementations that reduce numerical errors
Mike Duigou
mike.duigou at oracle.com
Wed Nov 20 18:31:34 UTC 2013
- Collectors averagingDouble could use the same @implNote as in DoublePipeline.
- DoublePipeline implementation could document the usage of the double array indices.
- @summary in test.
- I agree with Paul that refactoring as a testNG test would be nice.
- I wondered at the mechanism for combining compensation values. Do you have a reference which explains the correctness? I thought perhaps directly adding the compensations together before doing compensated addition of the two sums might be better.
Mike
On Nov 20 2013, at 00:21 , Joe Darcy <joe.darcy at oracle.com> wrote:
> Hi Paul,
>
> On 11/18/2013 07:38 AM, Paul Sandoz wrote:
>> Hi Joe,
>>
>> You can use the three arg form of collect for DoublePipeline.sum/average impls, which is already used for average:
>>
>> public final OptionalDouble average() {
>> double[] avg = collect(() -> new double[2],
>> (ll, i) -> {
>> ll[0]++;
>> ll[1] += i;
>> },
>> (ll, rr) -> {
>> ll[0] += rr[0];
>> ll[1] += rr[1];
>> });
>> return avg[0] > 0
>> ? OptionalDouble.of(avg[1] / avg[0])
>> : OptionalDouble.empty();
>> }
>>
>> That would be the most expedient way.
>
> Thanks for the tip. For the moment, I'm feeling a bit expedient and used the array-based approach in an iteration of the change:
>
> http://cr.openjdk.java.net/~darcy/8006572.3/
More information about the core-libs-dev
mailing list