private double[] computeStatistic(Statistic statistic, int[] sortedGroupArray, double[] sortedValueArray, int numSingleValuedGroups) { StatFunction stat = aggregationFunction(statistic); return Aggregation.aggregateSorted( stat, sortedGroupArray, sortedValueArray, sortedValueArray.length, numSingleValuedGroups); }
/** * Sorts the {@code group} and {@code values} array in tandem and calculates the statistic per group. * * <p>Note: the {@code group} and {@code values} array are sorted in place!</p> * * @param statistic the statistic to apply * @param groupId an array of at least length {@code numValues} containing group ids * @param values an array of at least length {@code numValues} containing the values to be aggregated * @param numValues number of values to aggregate. * @param numGroups number of groups present. The maximum value in the groupId values should be {@code numGroups-1} * @return an array of length {@code numGroups} containing the aggregated values. */ public static double[] sortAndAggregate(StatFunction statistic, int[] groupId, double[] values, int numValues, int numGroups) { if(numValues > 1) { HeapsortTandem.heapsortDescending(groupId, values, numValues); } return aggregateSorted(statistic, groupId, values, numValues, numGroups); }