private static void kahanSum(double value, DoubleArray values, DoubleArray compensations, long bucket) { // Compute the sum of double values with Kahan summation algorithm which is more // accurate than naive summation. double sum = values.get(bucket); double compensation = compensations.get(bucket); if (Double.isFinite(value) == false) { sum += value; } else if (Double.isFinite(sum)) { double corrected = value - compensation; double newSum = sum + corrected; compensation = (newSum - sum) - corrected; sum = newSum; } values.set(bucket, sum); compensations.set(bucket, compensation); }
@Override void copyCurrent(int slot) { values = bigArrays.grow(values, slot+1); if (missingBucket && missingCurrentValue) { bits.clear(slot); } else { assert missingCurrentValue == false; if (missingBucket) { bits.set(slot); } values.set(slot, currentValue); } }
/** Resize the array to the exact provided size. */ public DoubleArray resize(DoubleArray array, long size) { if (array instanceof BigDoubleArray) { return resizeInPlace((BigDoubleArray) array, size); } else { AbstractArray arr = (AbstractArray) array; final DoubleArray newArray = newDoubleArray(size, arr.clearOnResize); for (long i = 0, end = Math.min(size, array.size()); i < end; ++i) { newArray.set(i, array.get(i)); } array.close(); return newArray; } }
@Override public void collect(int doc, long bucket) throws IOException { if (bucket >= mins.size()) { long from = mins.size(); mins = bigArrays.grow(mins, bucket + 1); mins.fill(from, mins.size(), Double.POSITIVE_INFINITY); } if (values.advanceExact(doc)) { final double value = values.doubleValue(); double min = mins.get(bucket); min = Math.min(min, value); mins.set(bucket, min); } }
@Override public void collect(int doc, long bucket) throws IOException { if (bucket >= maxes.size()) { long from = maxes.size(); maxes = bigArrays.grow(maxes, bucket + 1); maxes.fill(from, maxes.size(), Double.NEGATIVE_INFINITY); } if (values.advanceExact(doc)) { final double value = values.doubleValue(); double max = maxes.get(bucket); max = Math.max(max, value); maxes.set(bucket, max); } }
@Override public void collect(int doc, long bucket) throws IOException { sums = bigArrays.grow(sums, bucket + 1); compensations = bigArrays.grow(compensations, bucket + 1); if (values.advanceExact(doc)) { final int valuesCount = values.docValueCount(); // Compute the sum of double values with Kahan summation algorithm which is more // accurate than naive summation. double sum = sums.get(bucket); double compensation = compensations.get(bucket); for (int i = 0; i < valuesCount; i++) { double value = values.nextValue(); if (Double.isFinite(value) == false) { sum += value; } else if (Double.isFinite(sum)) { double corrected = value - compensation; double newSum = sum + corrected; compensation = (newSum - sum) - corrected; sum = newSum; } } compensations.set(bucket, compensation); sums.set(bucket, sum); } } };
mins.set(0, min);
@Override public void collect(int doc, long bucket) throws IOException { counts = bigArrays.grow(counts, bucket + 1); sums = bigArrays.grow(sums, bucket + 1); compensations = bigArrays.grow(compensations, bucket + 1); if (values.advanceExact(doc)) { final int valueCount = values.docValueCount(); counts.increment(bucket, valueCount); // Compute the sum of double values with Kahan summation algorithm which is more // accurate than naive summation. double sum = sums.get(bucket); double compensation = compensations.get(bucket); for (int i = 0; i < valueCount; i++) { double value = values.nextValue(); if (Double.isFinite(value) == false) { sum += value; } else if (Double.isFinite(sum)) { double corrected = value - compensation; double newSum = sum + corrected; compensation = (newSum - sum) - corrected; sum = newSum; } } sums.set(bucket, sum); compensations.set(bucket, compensation); } } };
double max = maxes.get(0); max = Math.max(max, segMax.doubleValue()); maxes.set(0, max);
@Override public double set(long index, double value) { return in.set(index, value); }
@Override void copyCurrent(int slot) { values = bigArrays.grow(values, slot+1); if (missingBucket && missingCurrentValue) { bits.clear(slot); } else { assert missingCurrentValue == false; if (missingBucket) { bits.set(slot); } values.set(slot, currentValue); } }
@Override void copyCurrent(int slot) { values = bigArrays.grow(values, slot+1); if (missingBucket && missingCurrentValue) { bits.clear(slot); } else { assert missingCurrentValue == false; if (missingBucket) { bits.set(slot); } values.set(slot, currentValue); } }
@Override public void collect(int doc, long bucket) throws IOException { if (bucket >= mins.size()) { long from = mins.size(); mins = bigArrays.grow(mins, bucket + 1); mins.fill(from, mins.size(), Double.POSITIVE_INFINITY); } if (values.advanceExact(doc)) { final double value = values.doubleValue(); double min = mins.get(bucket); min = Math.min(min, value); mins.set(bucket, min); } }
@Override public void collect(int doc, long bucket) throws IOException { if (bucket >= maxes.size()) { long from = maxes.size(); maxes = bigArrays.grow(maxes, bucket + 1); maxes.fill(from, maxes.size(), Double.NEGATIVE_INFINITY); } final double value = values.get(doc); double max = maxes.get(bucket); max = Math.max(max, value); maxes.set(bucket, max); }
@Override public void collect(int doc, long bucket) throws IOException { if (bucket >= mins.size()) { long from = mins.size(); mins = bigArrays.grow(mins, bucket + 1); mins.fill(from, mins.size(), Double.POSITIVE_INFINITY); } final double value = values.get(doc); double min = mins.get(bucket); min = Math.min(min, value); mins.set(bucket, min); }
@Override public void collect(int doc, long bucket) throws IOException { if (bucket >= mins.size()) { long from = mins.size(); mins = bigArrays.grow(mins, bucket + 1); mins.fill(from, mins.size(), Double.POSITIVE_INFINITY); } final double value = values.get(doc); double min = mins.get(bucket); min = Math.min(min, value); mins.set(bucket, min); }
@Override public void collect(int doc, long bucket) throws IOException { if (bucket >= maxes.size()) { long from = maxes.size(); maxes = bigArrays.grow(maxes, bucket + 1); maxes.fill(from, maxes.size(), Double.NEGATIVE_INFINITY); } final double value = values.get(doc); double max = maxes.get(bucket); max = Math.max(max, value); maxes.set(bucket, max); }