SparseVector extends Vector { public DenseVector toDenseVector() { if (n >= 0) { DenseVector r = new DenseVector(n); for (int i = 0; i < this.indices.length; i++) { r.set(this.indices[i], this.values[i]); } return r; } else { if (this.indices.length == 0) { return new DenseVector(); } else { int n = this.indices[this.indices.length - 1] + 1; DenseVector r = new DenseVector(n); for (int i = 0; i < this.indices.length; i++) { r.set(this.indices[i], this.values[i]); } return r; } } } SparseVector();  SparseVector(int n);  SparseVector(int n, int[] indices, double[] values);  SparseVector(int n, Map<Integer, Double> kv); @Override SparseVector clone(); @Override SparseVector prefix(double d); @Override SparseVector append(double d); int[] getIndices(); double[] getValues(); @Override int size(); @Override double get(int i); void setSize(int n); int numberOfValues(); @Override void set(int i, double val); @Override void add(int i, double val); @Override String toString(); @Override double normL2(); @Override double normL1(); @Override double normInf(); @Override double normL2Square(); @Override SparseVector slice(int[] indices); @Override Vector plus(Vector vec); @Override Vector minus(Vector vec); @Override SparseVector scale(double d); @Override void scaleEqual(double d); void removeZeroValues(); @Override double dot(Vector other); @Override DenseMatrix outer(); DenseMatrix outer(SparseVector other); DenseVector toDenseVector(); @Override void standardizeEqual(double mean, double stdvar); @Override void normalizeEqual(double p); @Override boolean equals(Object o); @Override int hashCode(); void forEach(BiConsumer<Integer, Double> action); @Override VectorIterator iterator();  }
@Test public void testToDenseVector() throws Exception { int[] indices = new int[]{1, 3, 5}; double[] values = new double[]{1.0, 3.0, 5.0}; SparseVector v = new SparseVector(-1, indices, values); DenseVector dv = v.toDenseVector(); Assert.assertEquals(dv.size(), 6); Assert.assertArrayEquals(dv.getData(), new double[]{0, 1, 0, 3, 0, 5}, TOL); }