@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); } }
/** 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; } }
protected GeoBoundsAggregator(String name, SearchContext aggregationContext, Aggregator parent, ValuesSource.GeoPoint valuesSource, boolean wrapLongitude, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { super(name, aggregationContext, parent, pipelineAggregators, metaData); this.valuesSource = valuesSource; this.wrapLongitude = wrapLongitude; if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); tops = bigArrays.newDoubleArray(1, false); tops.fill(0, tops.size(), Double.NEGATIVE_INFINITY); bottoms = bigArrays.newDoubleArray(1, false); bottoms.fill(0, bottoms.size(), Double.POSITIVE_INFINITY); posLefts = bigArrays.newDoubleArray(1, false); posLefts.fill(0, posLefts.size(), Double.POSITIVE_INFINITY); posRights = bigArrays.newDoubleArray(1, false); posRights.fill(0, posRights.size(), Double.NEGATIVE_INFINITY); negLefts = bigArrays.newDoubleArray(1, false); negLefts.fill(0, negLefts.size(), Double.POSITIVE_INFINITY); negRights = bigArrays.newDoubleArray(1, false); negRights.fill(0, negRights.size(), Double.NEGATIVE_INFINITY); } }
@Override public void collect(int doc, long bucket) throws IOException { if (bucket >= counts.size()) { final long from = counts.size(); final long overSize = BigArrays.overSize(bucket + 1); counts = bigArrays.resize(counts, overSize); sums = bigArrays.resize(sums, overSize); mins = bigArrays.resize(mins, overSize); maxes = bigArrays.resize(maxes, overSize); mins.fill(from, overSize, Double.POSITIVE_INFINITY); maxes.fill(from, overSize, Double.NEGATIVE_INFINITY); } values.setDocument(doc); final int valuesCount = values.count(); counts.increment(bucket, valuesCount); double sum = 0; double min = mins.get(bucket); double max = maxes.get(bucket); for (int i = 0; i < valuesCount; i++) { double value = values.valueAt(i); sum += value; min = Math.min(min, value); max = Math.max(max, value); } sums.increment(bucket, sum); mins.set(bucket, min); maxes.set(bucket, max); } };
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); }
mins = bigArrays.resize(mins, overSize); maxes = bigArrays.resize(maxes, overSize); mins.fill(from, overSize, Double.POSITIVE_INFINITY); maxes.fill(from, overSize, Double.NEGATIVE_INFINITY); final int valuesCount = values.docValueCount(); counts.increment(bucket, valuesCount); double min = mins.get(bucket); double max = maxes.get(bucket); double sum = sums.get(bucket); double compensation = compensations.get(bucket); max = Math.max(max, value); sums.set(bucket, sum); compensations.set(bucket, compensation); mins.set(bucket, min); maxes.set(bucket, max);
while ((term = iter.next()) != null) { values = BigArrays.NON_RECYCLING_INSTANCE.grow(values, numTerms + 1); values.set(numTerms++, NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(term))); RandomAccessOrds ordinals = build.ordinals(); if (FieldData.isMultiValued(ordinals) || CommonSettings.getMemoryStorageHint(fieldDataType) == CommonSettings.MemoryStorageFormat.ORDINALS) { final long ramBytesUsed = build.ramBytesUsed() + values.ramBytesUsed(); data = new AtomicDoubleFieldData(ramBytesUsed) { long uniqueValuesArraySize = values.ramBytesUsed(); long ordinalsSize = build.ramBytesUsed(); if (uniqueValuesArraySize + ordinalsSize < singleValuesArraySize) { final long ramBytesUsed = build.ramBytesUsed() + values.ramBytesUsed(); success = true; return data = new AtomicDoubleFieldData(ramBytesUsed) { final long ordinal = ordinals.nextOrd(); if (ordinal != SortedSetDocValues.NO_MORE_ORDS) { sValues.set(i, values.get(ordinal)); assert sValues.size() == maxDoc; final long ramBytesUsed = sValues.ramBytesUsed() + (set == null ? 0 : set.ramBytesUsed()); data = new AtomicDoubleFieldData(ramBytesUsed) {
@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 fill(long fromIndex, long toIndex, double value) { in.fill(fromIndex, toIndex, value); }
@Override public double increment(long index, double inc) { return in.increment(index, inc); }
/** Grow an array to a size that is larger than <code>minSize</code>, * preserving content, and potentially reusing part of the provided array. */ public DoubleArray grow(DoubleArray array, long minSize) { if (minSize <= array.size()) { return array; } final long newSize = overSize(minSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); return resize(array, newSize); }
@Override public long ramBytesUsed() { return Integer.BYTES/*size*/ + lon.ramBytesUsed() + lat.ramBytesUsed(); }
public StatsAggregator(String name, ValuesSource.Numeric valuesSource, DocValueFormat format, SearchContext context, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { super(name, context, parent, pipelineAggregators, metaData); this.valuesSource = valuesSource; if (valuesSource != null) { final BigArrays bigArrays = context.bigArrays(); counts = bigArrays.newLongArray(1, true); sums = bigArrays.newDoubleArray(1, true); compensations = bigArrays.newDoubleArray(1, true); mins = bigArrays.newDoubleArray(1, false); mins.fill(0, mins.size(), Double.POSITIVE_INFINITY); maxes = bigArrays.newDoubleArray(1, false); maxes.fill(0, maxes.size(), Double.NEGATIVE_INFINITY); } this.format = format; }
maxes = bigArrays.resize(maxes, overSize); sumOfSqrs = bigArrays.resize(sumOfSqrs, overSize); mins.fill(from, overSize, Double.POSITIVE_INFINITY); maxes.fill(from, overSize, Double.NEGATIVE_INFINITY); double sum = 0; double sumOfSqr = 0; double min = mins.get(bucket); double max = maxes.get(bucket); for (int i = 0; i < valuesCount; i++) { double value = values.valueAt(i); max = Math.max(max, value); sums.increment(bucket, sum); sumOfSqrs.increment(bucket, sumOfSqr); mins.set(bucket, min); 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); } } };
sumOfSqrs = bigArrays.resize(sumOfSqrs, overSize); compensationOfSqrs = bigArrays.resize(compensationOfSqrs, overSize); mins.fill(from, overSize, Double.POSITIVE_INFINITY); maxes.fill(from, overSize, Double.NEGATIVE_INFINITY); final int valuesCount = values.docValueCount(); counts.increment(bucket, valuesCount); double min = mins.get(bucket); double max = maxes.get(bucket); double sum = sums.get(bucket); double compensation = compensations.get(bucket); double sumOfSqr = sumOfSqrs.get(bucket); double compensationOfSqr = compensationOfSqrs.get(bucket); for (int i = 0; i < valuesCount; i++) { double value = values.nextValue(); max = Math.max(max, value); sums.set(bucket, sum); compensations.set(bucket, compensation); sumOfSqrs.set(bucket, sumOfSqr); compensationOfSqrs.set(bucket, compensationOfSqr); mins.set(bucket, min); maxes.set(bucket, max);