@Override public byte[] serialize(DoubleArrayList doubleArrayList) { int size = doubleArrayList.size(); byte[] bytes = new byte[Integer.BYTES + size * Double.BYTES]; ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.putInt(size); double[] values = doubleArrayList.elements(); for (int i = 0; i < size; i++) { byteBuffer.putDouble(values[i]); } return bytes; }
@Override public void sortAscending() { DoubleArrays.parallelQuickSort(data.elements()); }
@Override public void sortDescending() { DoubleArrays.parallelQuickSort(data.elements(), descendingComparator); }
@Nonnull @Override public Double extractFinalResult(@Nonnull DoubleArrayList intermediateResult) { int size = intermediateResult.size(); if (size == 0) { return DEFAULT_FINAL_RESULT; } else { double[] values = intermediateResult.elements(); Arrays.sort(values, 0, size); if (_percentile == 100) { return values[size - 1]; } else { return values[(int) ((long) size * _percentile / 100)]; } } }
/** * Returns a new DoubleColumn containing a value for each value in this column. * * No information is lost in converting from the floats to doubles * * A missing value in the receiver is converted to a missing value in the result */ @Override public DoubleColumn asDoubleColumn() { DoubleArrayList values = new DoubleArrayList(); for (float d : data) { values.add(d); } values.trim(); return DoubleColumn.create(this.name(), values.elements()); } }
/** * Returns a new DoubleColumn containing a value for each value in this column, truncating if necessary. * * A widening primitive conversion from an int to a double does not lose information about the overall magnitude * of a numeric value. It may, however, result in loss of precision - that is, the result may lose some of the * least significant bits of the value. In this case, the resulting floating-point value will be a correctly * rounded version of the integer value, using IEEE 754 round-to-nearest mode. * * Despite the fact that a loss of precision may occur, a widening primitive conversion never results in a * run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public DoubleColumn asDoubleColumn() { DoubleArrayList values = new DoubleArrayList(); for (int d : data) { values.add(d); } values.trim(); return DoubleColumn.create(this.name(), values.elements()); }
/** * Returns a new DoubleColumn containing a value for each value in this column * * A widening primitive conversion from a long to a double does not lose information about the overall magnitude * of a numeric value. It may, however, result in loss of precision - that is, the result may lose some of the * least significant bits of the value. In this case, the resulting floating-point value will be a correctly * rounded version of the integer value, using IEEE 754 round-to-nearest mode. * * Despite the fact that a loss of precision may occur, a widening primitive conversion never results in a * run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public DoubleColumn asDoubleColumn() { DoubleArrayList values = new DoubleArrayList(); for (long d : data) { values.add(d); } values.trim(); return DoubleColumn.create(this.name(), values.elements()); } }
/** * Returns a new DoubleColumn containing a value for each value in this column, truncating if necessary. * * A widening primitive conversion from an int to a double does not lose information about the overall magnitude * of a numeric value. It may, however, result in loss of precision - that is, the result may lose some of the * least significant bits of the value. In this case, the resulting floating-point value will be a correctly * rounded version of the integer value, using IEEE 754 round-to-nearest mode. * * Despite the fact that a loss of precision may occur, a widening primitive conversion never results in a * run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public DoubleColumn asDoubleColumn() { DoubleArrayList values = new DoubleArrayList(); for (int d : data) { values.add(d); } values.trim(); return DoubleColumn.create(this.name(), values.elements()); } }
private static Long2DoubleMap extractVector(Iterator<? extends Rating> ratings, IdExtractor dimension, int n) { LongArrayList ids = new LongArrayList(n > 0 ? n : LongArrayList.DEFAULT_INITIAL_CAPACITY); DoubleArrayList values = new DoubleArrayList(n > 0 ? n : DoubleArrayList.DEFAULT_INITIAL_CAPACITY); while (ratings.hasNext()) { Rating r = ratings.next(); assert ids.size() == values.size(); long id = dimension.getId(r); ids.add(id); values.add(r.getValue()); } ids.trim(); values.trim(); assert ids.elements().length == ids.size(); assert values.elements().length == values.size(); return Long2DoubleSortedArrayMap.wrapUnsorted(ids.elements(), values.elements()); }
@SuppressWarnings("unchecked") private TypedChannelStorage(TypedSymbol<T> sym, T dft) { symbol = sym; defaultValue = dft; values = new ArrayList<T>(scores.elements().length); for (int i = size() - 1; i >= 0; i--) { values.add(defaultValue); } } }
@Override public void sortAscending() { DoubleArrays.parallelQuickSort(data.elements()); }
@Override public void sortAscending() { Arrays.parallelSort(data.elements()); }
@Override public void sortDescending() { DoubleArrays.parallelQuickSort(data.elements(), reverseFloatComparator); }
@Override public void sortDescending() { DoubleArrays.parallelQuickSort(data.elements(), descendingComparator); }
@VisibleForTesting DoubleArrayColumnView buildDouble() { return new DoubleArrayColumnView(values.elements(), values.size()); } }
@Override public int indexOf(Object o) { double val = parse((String) o); if (o instanceof String) val = parse((String) o); else val = (Double) o; double[] elements = ((DoubleArrayList) _innerList).elements(); return Arrays.binarySearch(elements, val); }
/** * Builds a double variable as a wrapper around the array of double values * from a DoubleArrayList variable. * * @param values double array list of doubles * @return new instance of numeric values */ public static VarDouble wrap(DoubleArrayList values) { VarDouble numeric = new VarDouble(0, 0, 0); numeric.data = values.elements(); numeric.rows = values.size(); return numeric; }
public ChannelStorage(Symbol sym, double dft) { symbol = sym; defaultValue = dft; values = new DoubleArrayList(scores.elements().length); for (int i = size() - 1; i >= 0; i--) { values.add(defaultValue); } } }
/** * Wrap key and value array lists in a mutable sparse vector. Don't modify * the original lists once this has been called! There must be at least * as many values as keys. The value list will be truncated to the length * of the key list. * * @param keyList The list of keys * @param valueList The list of values * @return A backed by the backing stores of the provided lists. */ public static MutableSparseVector wrap(LongArrayList keyList, DoubleArrayList valueList) { long[] keys = keyList.elements(); double[] values = valueList.elements(); return MutableSparseVector.wrap(keys, values, keyList.size()); }
private static Long2DoubleMap extractVector(Iterator<? extends Rating> ratings, IdExtractor dimension, int n) { LongArrayList ids = new LongArrayList(n > 0 ? n : LongArrayList.DEFAULT_INITIAL_CAPACITY); DoubleArrayList values = new DoubleArrayList(n > 0 ? n : DoubleArrayList.DEFAULT_INITIAL_CAPACITY); while (ratings.hasNext()) { Rating r = ratings.next(); assert ids.size() == values.size(); long id = dimension.getId(r); ids.add(id); values.add(r.getValue()); } ids.trim(); values.trim(); assert ids.elements().length == ids.size(); assert values.elements().length == values.size(); return Long2DoubleSortedArrayMap.wrapUnsorted(ids.elements(), values.elements()); }