BLAS { public static void gemv(double alpha, DenseMatrix matA, boolean transA, Vector x, double beta, DenseVector y) { if(x instanceof SparseVector){ gemv(alpha, matA, transA, (SparseVector)x, beta, y); }else{ gemv(alpha, matA, transA, (DenseVector)x, beta, y); } }  static double asum(int n, double[] x, int offset); static double asum(DenseVector x); static double asum(SparseVector x); static void axpy(double a, double[] x, double[] y); static void axpy(double a, DenseVector x, DenseVector y); static void axpy(double a, SparseVector x, DenseVector y); static void axpy(double a, Vector x, DenseVector y); static void axpy(double a, DenseMatrix x, DenseMatrix y); static void axpy(int n, double a, double[] x, int xOffset, double[] y, int yOffset); static double dot(double[] x, double[] y); static double dot(DenseVector x, DenseVector y); static void scal(double a, double[] x); static void scal(double a, double[] x, int xOffset, int length); static void scal(double a, DenseVector x); static void scal(double a, SparseVector x); static void scal(double a, DenseMatrix x); static void gemm(double alpha, DenseMatrix matA, boolean transA, DenseMatrix matB, boolean transB,
                            double beta, DenseMatrix matC); static void gemv(double alpha, DenseMatrix matA, boolean transA,
                            Vector x, double beta, DenseVector y); static void gemv(double alpha, DenseMatrix matA, boolean transA,
                            DenseVector x, double beta, DenseVector y); static void gemv(double alpha, DenseMatrix matA, boolean transA,
                            SparseVector x, double beta, DenseVector y);  }
@Test public void testGemvDense() throws Exception { DenseVector y1 = DenseVector.ones(2); BLAS.gemv(2.0, mat, false, dv2, 0., y1); Assert.assertArrayEquals(new double[]{28, 64}, y1.data, TOL); DenseVector y2 = DenseVector.ones(2); BLAS.gemv(2.0, mat, false, dv2, 1., y2); Assert.assertArrayEquals(new double[]{29, 65}, y2.data, TOL); }
@Test public void testGemvDenseTranspose() throws Exception { DenseVector y1 = DenseVector.ones(3); BLAS.gemv(1.0, mat, true, dv1, 0., y1); Assert.assertArrayEquals(new double[]{9, 12, 15}, y1.data, TOL); DenseVector y2 = DenseVector.ones(3); BLAS.gemv(1.0, mat, true, dv1, 1., y2); Assert.assertArrayEquals(new double[]{10, 13, 16}, y2.data, TOL); }
@Test public void testGemvSparse() throws Exception { DenseVector y1 = DenseVector.ones(2); BLAS.gemv(2.0, mat, false, spv2, 0., y1); Assert.assertArrayEquals(new double[]{20, 44}, y1.data, TOL); DenseVector y2 = DenseVector.ones(2); BLAS.gemv(2.0, mat, false, spv2, 1., y2); Assert.assertArrayEquals(new double[]{21, 45}, y2.data, TOL); }
@Test public void testGemvSparseTranspose() throws Exception { DenseVector y1 = DenseVector.ones(3); BLAS.gemv(2.0, mat, true, spv1, 0., y1); Assert.assertArrayEquals(new double[]{18, 24, 30}, y1.data, TOL); DenseVector y2 = DenseVector.ones(3); BLAS.gemv(2.0, mat, true, spv1, 1., y2); Assert.assertArrayEquals(new double[]{19, 25, 31}, y2.data, TOL); }
@Test public void testGemvSizeCheck() throws Exception { thrown.expect(IllegalArgumentException.class); DenseVector y = DenseVector.ones(2); BLAS.gemv(2.0, mat, false, dv1, 0., y); }
@Test public void testGemvTransposeSizeCheck() throws Exception { thrown.expect(IllegalArgumentException.class); DenseVector y = DenseVector.ones(2); BLAS.gemv(2.0, mat, true, dv1, 0., y); }