DenseVector extends Vector { @Override public DenseVector slice(int[] indices) { double[] values = new double[indices.length]; for (int i = 0; i < indices.length; ++i) { if (indices[i] >= data.length) { throw new IllegalArgumentException("Index is larger than vector size."); } values[i] = data[indices[i]]; } return new DenseVector(values); } DenseVector();  DenseVector(int n);  DenseVector(double[] data); double[] getData(); void setData(double[] data); static DenseVector ones(int n); static DenseVector zeros(int n); static DenseVector rand(int n); @Override DenseVector clone(); @Override String toString(); @Override int size(); @Override double get(int i); @Override void set(int i, double d); @Override void add(int i, double d); @Override double normL1(); @Override double normL2(); @Override double normL2Square(); @Override double normInf(); @Override DenseVector slice(int[] indices); @Override DenseVector prefix(double d); @Override DenseVector append(double d); @Override void scaleEqual(double d); @Override DenseVector plus(Vector other); @Override DenseVector minus(Vector other); @Override DenseVector scale(double d); @Override double dot(Vector vec); @Override void standardizeEqual(double mean, double stdvar); @Override void normalizeEqual(double p); void setEqual(DenseVector other); void plusEqual(Vector other); void minusEqual(Vector other); void plusScaleEqual(Vector other, double alpha); @Override DenseMatrix outer(); DenseMatrix outer(DenseVector other); @Override boolean equals(Object o); @Override int hashCode(); @Override VectorIterator iterator();  }
@Test public void testSlice() throws Exception { DenseVector vec = new DenseVector(new double[]{1, 2, -3}); DenseVector sliced = vec.slice(new int[]{0, 2}); Assert.assertArrayEquals(new double[]{1, -3}, sliced.getData(), 0); }