@Override public int getKeyForIndex(int rowIndex) { return values.getInt(rowIndex); }
@Override public int getIntInternal(int index) { return data.getInt(index); }
@Override public int getIntInternal(int index) { return data.getInt(index); }
/** * Returns the value at the given index. The actual value is returned if the ColumnType is INTEGER. Otherwise the * value is rounded as described below. * * Returns the closest {@code int} to the argument, with ties * rounding to positive infinity. * * <p> * Special cases: * <ul> * <li>If the argument is NaN, the result is 0. * <li>If the argument is positive infinity or any value greater than or * equal to the value of {@code Integer.MAX_VALUE}, an error will be thrown * </ul> * * @param row the index of the value to be rounded to an integer. * @return the value of the argument rounded to the nearest * {@code int} value. * @throws ClassCastException if the absolute value of the value to be rounded is too large to be cast to an int */ public int getInt(int row) { return data.getInt(row); }
@Override public String getValueForIndex(int rowIndex) { int k = values.getInt(rowIndex); return getValueForKey(k); }
@Override public double getDouble(int row) { int value = data.getInt(row); if (isMissingValue(value)) { return DoubleColumnType.missingValueIndicator(); } return value; }
public double[] asDoubleArray() { double[] doubles = new double[size()]; for (int i = 0; i < size(); i++) { doubles[i] = data.getInt(i); } return doubles; }
public double[] asDoubleArray() { double[] doubles = new double[data.size()]; for (int i = 0; i < size(); i++) { doubles[i] = data.getInt(i); } return doubles; }
default Selection eval(IntPredicate predicate) { Selection selection = new BitmapBackedSelection(); for (int idx = 0; idx < size(); idx++) { int next = data().getInt(idx); if (predicate.test(next)) { selection.add(idx); } } return selection; }
@Override public int countUnique() { IntSet ints = new IntOpenHashSet(size()); for (int i = 0; i < size(); i++) { ints.add(data.getInt(i)); } return ints.size(); }
default Selection eval(IntBiPredicate predicate, int value) { Selection selection = new BitmapBackedSelection(); for (int idx = 0; idx < size(); idx++) { int next = data().getInt(idx); if (predicate.test(next, value)) { selection.add(idx); } } return selection; }
default Selection eval(IntBiPredicate predicate, int value) { Selection selection = new BitmapBackedSelection(); for (int idx = 0; idx < data().size(); idx++) { int next = data().getInt(idx); if (predicate.test(next, value)) { selection.add(idx); } } return selection; }
@Override public Selection selectIsIn(Collection<String> strings) { IntOpenHashSet keys = new IntOpenHashSet(strings.size()); for (String string : strings) { int key = getKeyForValue(string); if (key != DEFAULT_RETURN_VALUE) { keys.add(key); } } Selection results = new BitmapBackedSelection(); for (int i = 0; i < values.size(); i++) { if (keys.contains(values.getInt(i))) { results.add(i); } } return results; }
l.putScalar(i, Math.abs(labels.getInt(i)), 1.0);
/** * Construct the VectorBasedSequentialSparseVector by a int indices and double values. * * @param cardinality * @param indices * @param doubleValues */ public VectorBasedSequentialSparseVector(int cardinality, IntArrayList indices, DoubleArrayList doubleValues) { this(cardinality, indices.size()); int entryCount = indices.size(); OrderedVectorElement[] sortableEntries = new OrderedVectorElement[entryCount]; int elementIndex = 0; for (int index = 0; index < entryCount; index++) { sortableEntries[elementIndex++] = new OrderedVectorElement(indices.getInt(index), doubleValues.getDouble(index)); } Arrays.sort(sortableEntries); int[] tmpIndices = new int[sortableEntries.length]; double[] tmpDoubleValues = new double[sortableEntries.length]; for (int index = 0; index < sortableEntries.length; index++) { tmpIndices[index] = sortableEntries[index].getIndex(); tmpDoubleValues[index] = sortableEntries[index].getValue(); } values = new OrderedIntDoubleMapping(tmpIndices, tmpDoubleValues); }
/** * This version operates on predicates that treat the given IntPredicate as operating on a packed local time * This is much more efficient that using a LocalTimePredicate, but requires that the developer understand the * semantics of packedLocalTimes */ default Selection eval(IntPredicate predicate) { Selection selection = new BitmapBackedSelection(); for (int idx = 0; idx < data().size(); idx++) { int next = data().getInt(idx); if (predicate.test(next)) { selection.add(idx); } } return selection; }
private void constructColumnIndices(RowSequentialAccessSparseMatrix rowMatrix) { IntArrayList[] columnIndicesList = new IntArrayList[rowMatrix.columnSize()]; for (int columnIndex = 0; columnIndex < rowMatrix.columnSize(); columnIndex++) { columnIndicesList[columnIndex] = new IntArrayList(); } for (MatrixEntry matrixEntry : rowMatrix) { int rowIndex = matrixEntry.row(); int columnIndex = matrixEntry.column(); columnIndicesList[columnIndex].add(rowIndex); } columnIndices = new int[rowMatrix.columnSize()][]; for (int columnIndex = 0; columnIndex < rowMatrix.columnSize(); columnIndex++) { int size = columnIndicesList[columnIndex].size(); columnIndices[columnIndex] = new int[size]; Collections.sort(columnIndicesList[columnIndex]); for (int position = 0; position < size; position++) { columnIndices[columnIndex][position] = columnIndicesList[columnIndex].getInt(position); } } }
@Override public Selection selectIsIn(String... strings) { IntOpenHashSet keys = new IntOpenHashSet(strings.length); for (String string : strings) { int key = getKeyForValue(string); if (key != DEFAULT_RETURN_VALUE) { keys.add(key); } } Selection results = new BitmapBackedSelection(); for (int i = 0; i < values.size(); i++) { if (keys.contains(values.getInt(i))) { results.add(i); } } return results; }
@Override public DateColumn unique() { IntSet ints = new IntOpenHashSet(data.size()); for (int i = 0; i < size(); i++) { ints.add(data.getInt(i)); } DateColumn copy = emptyCopy(ints.size()); copy.setName(name() + " Unique values"); copy.data = IntArrayList.wrap(ints.toIntArray()); return copy; }