[ 
https://issues.apache.org/jira/browse/NUMBERS-163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17362908#comment-17362908
 ] 

Alex Herbert commented on NUMBERS-163:
--------------------------------------

{quote}There is (surprisingly perhaps) no performance loss (on the contrary, 
for the simple cases).
{quote}
Thanks for testing. I have no other issues with the builder type API and that 
is more flexible. Maintaining the static methods when performance is no 
different is not necessary.
{quote}As far as making LinearCombination itself implement DoubleSupplier, I do 
not see the utility.
{quote}
You can have different implementations of LinearCombination. dot2s is a 2-fold 
precision algorithm. The generic extension is the dotK family for k-fold 
precision. There is also the unlimited precision method (within the bounds of 
the range of a double).

But this would also work for the accumulator class you are describing. The 
accumulator can have sub-class implementations.

The algorithm should be specified in the constructor:
{code:java}
double x1 = LinearCombination.of(LinearCombination.DOT_2S)
    .add(1e300, 1)
    .add(1e100, 1)
    .add(1, 1)
    .add(-1e300, 1)
    .add(-1e100, 1)
    .getAsDouble();

assert x1 == 1;
{code}
I think this fails for the dot2s algorithm. But it would work for DOT_3 
algorithm.

This would allow code to switch the accuracy by just putting in a different 
enum specified algorithm.

 

> Summation and LinearCombination Accumulators
> --------------------------------------------
>
>                 Key: NUMBERS-163
>                 URL: https://issues.apache.org/jira/browse/NUMBERS-163
>             Project: Commons Numbers
>          Issue Type: New Feature
>            Reporter: Matt Juntunen
>            Priority: Major
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> It would be useful to have simple accumulator classes in {{Summation}} and 
> {{LinearCombination}} to perform extended precision operations on arbitrary 
> collections of values without requiring conversion to {{double[]}}. Ex:
> {code:java}
> Summation.Accumulator sum= Summation.accumulator(1d);
> sum.add(x)
>     .add(y)
>     .add(z)
>    .add(w);
> double sumResult = sum.get();
> LinearCombination.Accumulator comb = LinearCombination.accumulator(1d);
> comb.add(x, scale)
>     .add(y, scale)
>     .add(z, scale)
>     .add(w, scale);
> double combResult = comb.get();
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to