[ https://issues.apache.org/jira/browse/STATISTICS-90?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17936557#comment-17936557 ]
Alex Herbert commented on STATISTICS-90: ---------------------------------------- This API change will add a new method to each statistic implementation. Options are e.g: # ofRange(double[] x, int from, int to) # of(double[] x, int from, int to) I suggest {{ofRange(x, from, to)}} as the method name to follow the trend of the JDK's {{{}Arrays.copyOfRange(x, from, to){}}}. The change is mostly a lot of boiler plate addition to each implementation to loop over only part of the input array rather then the entire array. I've completed the conversion for the double[] statistics in a proof-of-concept branch in my fork and the changes were mostly straight forward. One design decision is what to throw when the input range is invalid. There two options are: # Like [Arrays.copyOfRange|https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Arrays.html#copyOfRange(double%5B%5D,int,int)]: ArrayIndexOutOfBoundsException - if from < 0 or from > original.length and IllegalArgumentException - if from > to # Like [Objects.checkFromToIndex (JDK 9+)|https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Objects.html#checkFromToIndex(int,int,int)]: IndexOutOfBoundsException - if the sub-range is out of bounds I suggest using only the IndexOutOfBoundsException for all range errors. This makes it simple to use Objects.checkFromToIndex in the future. > Support statistic creation using an array range > ----------------------------------------------- > > Key: STATISTICS-90 > URL: https://issues.apache.org/jira/browse/STATISTICS-90 > Project: Commons Statistics > Issue Type: New Feature > Components: descriptive > Affects Versions: 1.1 > Reporter: Alex Herbert > Priority: Minor > > Add support for using part of an array to create statistics: > {code:java} > double[] x = ... > int from = ... > int to = ... > Min.ofRange(x, from, to); > DoubleStatistics.ofRange(EnumSet.of(Statistic.MIN), x, from, to);{code} > This change should have no impact on performance for full length arrays and > improve memory consumption by avoiding array copies on sub-ranges. Results > from STATISTICS-89 indicate a non-negligible performance gain for fast > computing statistics. > Note: Support for sub-ranges is present in the Commons Math > UnivariateStatistic interface. This change will allow supporting replacement > of the Math API with Statistics. -- This message was sent by Atlassian Jira (v8.20.10#820010)