Blas { public static void spr(Double alpha, DenseVector v, DenseVector u) { nativeBlas.dspr("U", v.size(), alpha, v.getStorage().data(), 1, u.getStorage().data()); }  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 testSprDenseDense() { double alpha = 3.0; DenseVector v = new DenseVector(new double[] {1.0, 2.0}); DenseVector u = new DenseVector(new double[] {3.0, 13.0, 20.0, 0.0}); DenseMatrix m = (DenseMatrix)new DenseMatrix(new double[][] { {1.0, 0.0}, {2.0, 4.0}}, StorageConstants.COLUMN_STORAGE_MODE).times(alpha); DenseMatrix a = new DenseMatrix(new double[][] {{3.0, 0.0}, {13.0, 20.0}}, StorageConstants.COLUMN_STORAGE_MODE); Blas.spr(alpha, v, u); DenseMatrix mu = fromVector(u, a.rowSize(), StorageConstants.COLUMN_STORAGE_MODE, (i, j) -> i >= j); Assert.assertEquals(m.plus(a), mu); }
@Test public void testSprSparseDense1() { double alpha = 3.0; SparseVector v = sparseFromArray(new double[] {1.0, 2.0}); DenseVector u = new DenseVector(new double[] {3.0, 13.0, 20.0, 0.0}); DenseMatrix a = new DenseMatrix(new double[][] {{3.0, 0.0}, {13.0, 20.0}}, StorageConstants.COLUMN_STORAGE_MODE); DenseMatrix exp = (DenseMatrix)new DenseMatrix(new double[][] { {1.0, 0.0}, {2.0, 4.0}}, StorageConstants.COLUMN_STORAGE_MODE).times(alpha).plus(a); Blas.spr(alpha, v, u); DenseMatrix mu = fromVector(u, a.rowSize(), StorageConstants.COLUMN_STORAGE_MODE, (i, j) -> i >= j); Assert.assertEquals(exp, mu); }
@Test public void testSprSparseDense2() { double alpha = 3.0; SparseVector v = new SparseVector(2); v.set(0, 1); DenseVector u = new DenseVector(new double[] {3.0, 13.0, 20.0, 0.0}); DenseMatrix m = (DenseMatrix)new DenseMatrix(new double[][] { {1.0, 0.0}, {0.0, 0.0}}, StorageConstants.COLUMN_STORAGE_MODE).times(alpha); DenseMatrix a = new DenseMatrix(new double[][] {{3.0, 0.0}, {13.0, 20.0}}, StorageConstants.COLUMN_STORAGE_MODE); Blas.spr(alpha, v, u); DenseMatrix mu = fromVector(u, a.rowSize(), StorageConstants.COLUMN_STORAGE_MODE, (i, j) -> i >= j); Assert.assertEquals(m.plus(a), mu); }