[
https://issues.apache.org/jira/browse/NUMBERS-163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17363526#comment-17363526
]
Matt Juntunen commented on NUMBERS-163:
---------------------------------------
I've been thinking about this more and it seems to me that if we go the
instance route with {{LinearCombination}} and {{Summation}}, we could combine
them into a single {{Sum}} class. The class would represent a running sum of
terms, with some single terms and some products. I'm picturing something like
this:
{code:java}
// compute a + b + c
Sum s = Sum.create();
s.add(a)
.add(b)
.add(c);
double result = s.getAsDouble();
// compute a0*b0 + a1*b1 + a2*b2
Sum s = Sum.create();
s.addProduct(a0, b0)
.addProduct(a1, b1)
.addProduct(a2, b2);
double result = s.getAsDouble();
// compute a + b*c
double result = Sum.create().add(a).addProduct(b, c).getAsDouble();
// Implement DoubleConsumer for use with DoubleStream.
// compute sum of stream elements
Sum s = Sum.create();
doubleStream.forEach(s);
double result = s.getAsDouble();
// Provide convenience factory methods for supplying multiple values at once.
// compute a + b + c
Sum s = Sum.of(a, b, c);
double result = s.getAsDouble();
// compute a0*b0 + a1*b1
Sum s = Sum.linearCombination(a0, b0, a1, b1);
double result = s.getAsDouble();
// Perhaps provide convenience static methods for directly computing
// the double result. These could be implemented internally using the
// instance methods.
// compute a + b + c
double result = Sum.value(a, b, c);
// compute a0*b0 + a1*b1
double result = Sum.linearCombinationValue(a0, b0, a1, b1);
{code}
Thoughts?
> 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: 0.5h
> 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)