@Test public void testPrefix() throws Exception { SparseVector prefixed = v1.prefix(0.2); Assert.assertArrayEquals(prefixed.getIndices(), new int[]{0, 2, 4, 6, 8}); Assert.assertArrayEquals(prefixed.getValues(), new double[]{0.2, 2, 2, 2, 2}, 0); }
@Override public SparseVector prefix(double d) { int[] indices = new int[this.indices.length + 1]; double[] values = new double[this.values.length + 1]; int n = (this.n >= 0) ? this.n + 1 : this.n; indices[0] = 0; values[0] = d; for (int i = 0; i < this.indices.length; i++) { indices[i + 1] = this.indices[i] + 1; values[i + 1] = this.values[i]; } return new SparseVector(n, indices, values); }
SparseVector extends Vector { @Override public SparseVector prefix(double d) { int[] indices = new int[this.indices.length + 1]; double[] values = new double[this.values.length + 1]; int n = (this.n >= 0) ? this.n + 1 : this.n; indices[0] = 0; values[0] = d; for (int i = 0; i < this.indices.length; i++) { indices[i + 1] = this.indices[i] + 1; values[i + 1] = this.values[i]; } return new SparseVector(n, indices, values); } }
SparseVector extends Vector { @Override public SparseVector prefix(double d) { int[] indices = new int[this.indices.length + 1]; double[] values = new double[this.values.length + 1]; int n = (this.n >= 0) ? this.n + 1 : this.n; indices[0] = 0; values[0] = d; for (int i = 0; i < this.indices.length; i++) { indices[i + 1] = this.indices[i] + 1; values[i + 1] = this.values[i]; } return new SparseVector(n, indices, values); } SparseVector();  SparseVector(int n);  SparseVector(int n, int[] indices, double[] values);  SparseVector(int n, Map<Integer, Double> kv); }
SparseVector extends Vector { @Override public SparseVector prefix(double d) { int[] indices = new int[this.indices.length + 1]; double[] values = new double[this.values.length + 1]; int n = (this.n >= 0) ? this.n + 1 : this.n; indices[0] = 0; values[0] = d; for (int i = 0; i < this.indices.length; i++) { indices[i + 1] = this.indices[i] + 1; values[i + 1] = this.values[i]; } return new SparseVector(n, indices, values); } 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(); }
SparseVector extends Vector { @Override public SparseVector prefix(double d) { int[] indices = new int[this.indices.length + 1]; double[] values = new double[this.values.length + 1]; int n = (this.n >= 0) ? this.n + 1 : this.n; indices[0] = 0; values[0] = d; for (int i = 0; i < this.indices.length; i++) { indices[i + 1] = this.indices[i] + 1; values[i + 1] = this.values[i]; } return new SparseVector(n, indices, values); } 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();  }