/** * Adds the given double to this column */ public DoubleColumn append(double d) { data.add(d); return this; }
/** * Adds the given float to this column */ public DoubleColumn append(final float f) { data.add(f); return this; }
public DoubleColumn append(int i) { data.add(i); return this; }
@Override public DoubleArrayList deserialize(ByteBuffer byteBuffer) { int numValues = byteBuffer.getInt(); DoubleArrayList doubleArrayList = new DoubleArrayList(numValues); for (int i = 0; i < numValues; i++) { doubleArrayList.add(byteBuffer.getDouble()); } return doubleArrayList; } };
@Override public void aggregateGroupBySV(int length, @Nonnull int[] groupKeyArray, @Nonnull GroupByResultHolder groupByResultHolder, @Nonnull BlockValSet... blockValSets) { double[] valueArray = blockValSets[0].getDoubleValuesSV(); for (int i = 0; i < length; i++) { DoubleArrayList valueList = getValueList(groupByResultHolder, groupKeyArray[i]); valueList.add(valueArray[i]); } }
@Override public void aggregateGroupBySV(int length, @Nonnull int[] groupKeyArray, @Nonnull GroupByResultHolder groupByResultHolder, @Nonnull BlockValSet... blockValSets) { double[][] valuesArray = blockValSets[0].getDoubleValuesMV(); for (int i = 0; i < length; i++) { DoubleArrayList valueList = getValueList(groupByResultHolder, groupKeyArray[i]); for (double value : valuesArray[i]) { valueList.add(value); } } }
@Override public void aggregateGroupByMV(int length, @Nonnull int[][] groupKeysArray, @Nonnull GroupByResultHolder groupByResultHolder, @Nonnull BlockValSet... blockValSets) { double[] valueArray = blockValSets[0].getDoubleValuesSV(); for (int i = 0; i < length; i++) { double value = valueArray[i]; for (int groupKey : groupKeysArray[i]) { DoubleArrayList valueList = getValueList(groupByResultHolder, groupKey); valueList.add(value); } } }
@Override public void aggregate(int length, @Nonnull AggregationResultHolder aggregationResultHolder, @Nonnull BlockValSet... blockValSets) { double[][] valuesArray = blockValSets[0].getDoubleValuesMV(); DoubleArrayList valueList = getValueList(aggregationResultHolder); for (int i = 0; i < length; i++) { for (double value : valuesArray[i]) { valueList.add(value); } } }
@Override public void aggregate(int length, @Nonnull AggregationResultHolder aggregationResultHolder, @Nonnull BlockValSet... blockValSets) { DoubleArrayList valueList = getValueList(aggregationResultHolder); double[] valueArray = blockValSets[0].getDoubleValuesSV(); for (int i = 0; i < length; i++) { valueList.add(valueArray[i]); } }
@Override public void aggregateGroupByMV(int length, @Nonnull int[][] groupKeysArray, @Nonnull GroupByResultHolder groupByResultHolder, @Nonnull BlockValSet... blockValSets) { double[][] valuesArray = blockValSets[0].getDoubleValuesMV(); for (int i = 0; i < length; i++) { double[] values = valuesArray[i]; for (int groupKey : groupKeysArray[i]) { DoubleArrayList valueList = getValueList(groupByResultHolder, groupKey); for (double value : values) { valueList.add(value); } } } } }
@Test public void testDoubleArrayList() { for (int i = 0; i < NUM_ITERATIONS; i++) { int size = RANDOM.nextInt(100); DoubleArrayList expected = new DoubleArrayList(size); for (int j = 0; j < size; j++) { expected.add(RANDOM.nextDouble()); } byte[] bytes = ObjectSerDeUtils.serialize(expected); DoubleArrayList actual = ObjectSerDeUtils.deserialize(bytes, ObjectSerDeUtils.ObjectType.DoubleArrayList); assertEquals(actual, expected, ERROR_MESSAGE); } }
@Override public DoubleColumn bottom(final int n) { DoubleArrayList bottom = new DoubleArrayList(); double[] values = data.toDoubleArray(); DoubleArrays.parallelQuickSort(values); for (int i = 0; i < n && i < values.length; i++) { bottom.add(values[i]); } return new DoubleColumn(name() + "[Bottoms " + n + "]", bottom); }
@Override public DoubleColumn top(int n) { DoubleArrayList top = new DoubleArrayList(); double[] values = data.toDoubleArray(); DoubleArrays.parallelQuickSort(values, descendingComparator); for (int i = 0; i < n && i < values.length; i++) { top.add(values[i]); } return new DoubleColumn(name() + "[Top " + n + "]", top); }
/** * 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, 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()); } }
/** * Puts the element into the priority queue. * <ul> * <li> If key does not exist, it is added to the priority queue. </li> * <li> If key exists, then the value is updated, and the priority queue ordering is maintained. </li> * <li> Runtime complexity of {@code O(log(n)}). </li> * </ul> * @param key Integer key for the value * @param value Double value of the key */ public void put(int key, double value) { if (!_keyToIndexMap.containsKey(key)) { _values.add(value); int last = _values.size() - 1; updateKeyIndexMap(key, last); siftUp(last); } else { int index = _keyToIndexMap.get(key); _values.set(index, value); // Sift the value up or down, as the case may be. if (!siftDown(index)) { siftUp(index); } } }
public RowSequentialAccessSparseMatrix(int rows, int columns, DataFrame df, DataFrameIndex rowDataFrameIndex, int itemColumn, int valueColumn) { super(rows, columns); rowVectors = new VectorBasedSequentialSparseVector[rows]; for (int rowIndex = 0; rowIndex < rows; rowIndex++) { IntArrayList positions = rowDataFrameIndex.getIndices(rowIndex); IntArrayList indices = new IntArrayList(positions.size()); DoubleArrayList doubleValues = new DoubleArrayList(positions.size()); for (int position : positions) { indices.add((int) df.get(itemColumn,position)); doubleValues.add((double) df.get(valueColumn,position)); } rowVectors[rowIndex] = new VectorBasedSequentialSparseVector( columns, indices, doubleValues); } }
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()); }