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

Gilles Sadowski commented on NUMBERS-163:
-----------------------------------------

bq. performance impact should be checked.

I've adapted {{LinearCombinationPerformance.java}}.  E.g.
{code}
    @Benchmark
    public void twoDStatic(Factors factors, Blackhole bh) {
        for (int i = 0; i < factors.getSize(); i++) {
            final double[] a = factors.getA(i);
            final double[] b = factors.getB(i);
            bh.consume(LinearCombination.value(a[0], b[0], a[1], b[1]));
        }
    }

    @Benchmark
    public void twoDInstance(Factors factors, Blackhole bh) {
        for (int i = 0; i < factors.getSize(); i++) {
            final double[] a = factors.getA(i);
            final double[] b = factors.getB(i);
            bh.consume(LinearCombinationInstance.of(a[0], b[0], a[1], 
b[1]).getAsDouble());
        }
    }
{code}

Benchmark (c) (length) (size) Mode Cnt Score Error Units
 StaticVsInstancePerfTest.fourDInstance 1e20 N/A 1000 avgt 5 31512.374 ± 62.728 
ns/op
 StaticVsInstancePerfTest.fourDStatic 1e20 N/A 1000 avgt 5 31614.226 ± 9.056 
ns/op
 StaticVsInstancePerfTest.nDInstance 1e20 2 1000 avgt 5 20752.786 ± 133.433 
ns/op
 StaticVsInstancePerfTest.nDInstance 1e20 3 1000 avgt 5 27923.824 ± 64.643 ns/op
 StaticVsInstancePerfTest.nDInstance 1e20 4 1000 avgt 5 35315.521 ± 63.024 ns/op
 StaticVsInstancePerfTest.nDInstance 1e20 8 1000 avgt 5 64917.926 ± 7542.116 
ns/op
 StaticVsInstancePerfTest.nDInstance 1e20 16 1000 avgt 5 119683.016 ± 108.595 
ns/op
 StaticVsInstancePerfTest.nDInstance 1e20 32 1000 avgt 5 235226.364 ± 82.889 
ns/op
 StaticVsInstancePerfTest.nDInstance 1e20 64 1000 avgt 5 454769.978 ± 4762.963 
ns/op
 StaticVsInstancePerfTest.nDStatic 1e20 2 1000 avgt 5 20615.813 ± 55.909 ns/op
 StaticVsInstancePerfTest.nDStatic 1e20 3 1000 avgt 5 27732.619 ± 11.160 ns/op
 StaticVsInstancePerfTest.nDStatic 1e20 4 1000 avgt 5 35240.831 ± 32.135 ns/op
 StaticVsInstancePerfTest.nDStatic 1e20 8 1000 avgt 5 64602.804 ± 7745.583 ns/op
 StaticVsInstancePerfTest.nDStatic 1e20 16 1000 avgt 5 119715.009 ± 116.848 
ns/op
 StaticVsInstancePerfTest.nDStatic 1e20 32 1000 avgt 5 235239.053 ± 1996.640 
ns/op
 StaticVsInstancePerfTest.nDStatic 1e20 64 1000 avgt 5 453945.774 ± 312.060 
ns/op
 StaticVsInstancePerfTest.threeDInstance 1e20 N/A 1000 avgt 5 24793.222 ± 
30.967 ns/op
 StaticVsInstancePerfTest.threeDStatic 1e20 N/A 1000 avgt 5 25110.065 ± 162.728 
ns/op
 StaticVsInstancePerfTest.twoDInstance 1e20 N/A 1000 avgt 5 18087.386 ± 6.255 
ns/op
 StaticVsInstancePerfTest.twoDStatic 1e20 N/A 1000 avgt 5 18447.334 ± 15.277 
ns/op

bq. There is no need to instantiate an object to perform the computation in the 
simple cases.

There is (surprisingly perhaps) no performance loss (on the contrary, for the 
simple cases).


> 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
>
> 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