[ https://issues.apache.org/jira/browse/NUMBERS-163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17366238#comment-17366238 ]
Matt Juntunen commented on NUMBERS-163: --------------------------------------- Looks good to me. Thanks. I thought about it some more and your proposal of having an enum to select the summation algorithm no longer seems like such a major leap. I sketched it out in code just now and this is what I came up with. {code:java} // interface abstraction of the current Sum class with additional methods // to add and return BigDecimal public interface Sum extends DoubleSupplier, DoubleConsumer { Sum add(double v); Sum add(double... arr); Sum add(BigDecimal d); Sum add(BigDecimal... arr); Sum add(Sum s); Sum addProduct(double a, double b); Sum addProducts(double[] a, double[] b); BigDecimal getExact(); } // enum for selecting the algorithm and creating instances public enum Summation { // standard double operations STANDARD(...), // Current dot2s algorithm DOT2S(...), // DotK(x) algorithm in examples-jmh with k = 3 DOTK3(...), // other dotk implementations, eg DOTK4, DOTK5, ... ? ... // exact computation using BigDecimal EXACT(...); // create a new sum instance public Sum create() { ... } // create a new sum instance initialized with the given value public Sum create(double val) { ... } public Sum create(BigDecimal val) { ... } } {code} The majority of the work here would be unit tests. Also, the name {{Summation}} for the enum isn't striking me as quite right, although it works. I'd like it to be {{Sum.DOT2S.create()}} but {{Sum}} works best for the interface name. [~erans], [~aherbert], 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 > Attachments: FMA.java, Sum.java > > Time Spent: 1h 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)