Blas { public static void scal(Double a, Vector x) { if (x.isArrayBased()) f2jBlas.dscal(x.size(), a, x.getStorage().data(), 1); else if (x instanceof SparseVector) { Set<Integer> indexes = ((SparseVector)x).indexes(); for (Integer i : indexes) x.compute(i, (ind, v) -> v * a); } else throw new IllegalArgumentException(); }  static void axpy(Double a, Vector x, Vector y); static Double dot(Vector x, Vector y); void copy(Vector x, Vector y); static void scal(Double a, Vector x); static void spr(Double alpha, DenseVector v, DenseVector u); static void spr(Double alpha, SparseVector v, DenseVector u); static void syr(Double alpha, SparseVector x, DenseMatrix a); static void gemm(double alpha, Matrix a, Matrix b, double beta, Matrix c); static void gemv(double alpha, Matrix a, Vector x, double beta, Vector y); static void checkCardinality(Matrix a, Vector v);  }
@Test public void testScalDense() { double[] data = new double[] {1.0, 1.0}; double alpha = 2.0; DenseVector v = new DenseVector(data); Vector exp = new DenseVector(data, true).times(alpha); Blas.scal(alpha, v); Assert.assertEquals(v, exp); }
@Test public void testScalSparse() { double[] data = new double[] {1.0, 1.0}; double alpha = 2.0; SparseVector v = sparseFromArray(data); Vector exp = sparseFromArray(data).times(alpha); Blas.scal(alpha, v); Assert.assertEquals(v, exp); }