@Test public void testMm() { System.out.println("mm"); double[][] A = { { 0.7220180, 0.07121225, 0.6881997f}, {-0.2648886, -0.89044952, 0.3700456f}, {-0.6391588, 0.44947578, 0.6240573f} }; double[][] B = { {0.6881997, -0.07121225, 0.7220180f}, {0.3700456, 0.89044952, -0.2648886f}, {0.6240573, -0.44947578, -0.6391588f} }; double[][] C = { { 0.9527204, -0.2973347, 0.06257778f}, {-0.2808735, -0.9403636, -0.19190231f}, { 0.1159052, 0.1652528, -0.97941688f} }; double[][] D = { { 0.9887140, 0.1482942, -0.0212965f}, { 0.1482942, -0.9889421, -0.0015881f}, {-0.0212965, -0.0015881, -0.9997719f} }; double[][] E = { {0.0000, 0.0000, 1.0000f}, {0.0000, -1.0000, 0.0000f}, {1.0000, 0.0000, 0.0000f} }; Matrix a = new Matrix(A); Matrix b = new Matrix(B); double[][] F = b.mm(a).transpose().toArray(); assertTrue(MathEx.equals(a.mm(b).toArray(), C, 1E-7f)); assertTrue(MathEx.equals(a.mt(b).toArray(), D, 1E-7f)); assertTrue(MathEx.equals(a.tm(b).toArray(), E, 1E-7f)); assertTrue(MathEx.equals(a.tt(b).toArray(), F, 1E-7f)); }
public void mm(Transpose transA, Transpose transB, double alpha, Matrix B, double beta, Matrix C) { if (isSymmetric() && transB == NO_TRANSPOSE && B.layout() == C.layout()) { BLAS.engine.symm(C.layout(), LEFT, uplo, C.m, C.n, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } else if (B.isSymmetric() && transA == NO_TRANSPOSE && layout() == C.layout()) { BLAS.engine.symm(C.layout(), RIGHT, B.uplo, C.m, C.n, alpha, B.A, B.ld, A, ld, beta, C.A, C.ld); } else { if (C.layout() != layout()) transA = flip(transA); if (C.layout() != B.layout()) transB = flip(transB); int k = transA == NO_TRANSPOSE ? n : m; BLAS.engine.gemm(layout(), transA, transB, C.m, C.n, k, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } }
Matrix extends DMatrix { public void mm(Transpose transA, Transpose transB, double alpha, Matrix B, double beta, Matrix C) { if (isSymmetric() && transB == NO_TRANSPOSE && B.layout() == C.layout()) { BLAS.engine.symm(C.layout(), LEFT, uplo, C.m, C.n, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } else if (B.isSymmetric() && transA == NO_TRANSPOSE && layout() == C.layout()) { BLAS.engine.symm(C.layout(), RIGHT, B.uplo, C.m, C.n, alpha, B.A, B.ld, A, ld, beta, C.A, C.ld); } else { if (C.layout() != layout()) transA = flip(transA); if (C.layout() != B.layout()) transB = flip(transB); int k = transA == NO_TRANSPOSE ? n : m; BLAS.engine.gemm(layout(), transA, transB, C.m, C.n, k, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } } }
Matrix extends DMatrix { public void mm(Transpose transA, Transpose transB, double alpha, Matrix B, double beta, Matrix C) { if (isSymmetric() && transB == NO_TRANSPOSE && B.layout() == C.layout()) { BLAS.engine.symm(C.layout(), LEFT, uplo, C.m, C.n, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } else if (B.isSymmetric() && transA == NO_TRANSPOSE && layout() == C.layout()) { BLAS.engine.symm(C.layout(), RIGHT, B.uplo, C.m, C.n, alpha, B.A, B.ld, A, ld, beta, C.A, C.ld); } else { if (C.layout() != layout()) transA = flip(transA); if (C.layout() != B.layout()) transB = flip(transB); int k = transA == NO_TRANSPOSE ? n : m; BLAS.engine.gemm(layout(), transA, transB, C.m, C.n, k, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } } Matrix(int m, int n);  Matrix(int m, int n, double a);  Matrix(int m, int n, double[][] A);  Matrix(double[][] A);  Matrix(double[] A);  Matrix(double[] A, int offset, int length);  Matrix(int m, int n, int ld, DoubleBuffer A); }
Matrix extends DMatrix { public void mm(Transpose transA, Transpose transB, double alpha, Matrix B, double beta, Matrix C) { if (isSymmetric() && transB == NO_TRANSPOSE && B.layout() == C.layout()) { BLAS.engine.symm(C.layout(), LEFT, uplo, C.m, C.n, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } else if (B.isSymmetric() && transA == NO_TRANSPOSE && layout() == C.layout()) { BLAS.engine.symm(C.layout(), RIGHT, B.uplo, C.m, C.n, alpha, B.A, B.ld, A, ld, beta, C.A, C.ld); } else { if (C.layout() != layout()) transA = flip(transA); if (C.layout() != B.layout()) transB = flip(transB); int k = transA == NO_TRANSPOSE ? n : m; BLAS.engine.gemm(layout(), transA, transB, C.m, C.n, k, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } } Matrix(int m, int n);  Matrix(int m, int n, double a);  Matrix(int m, int n, double[][] A);  Matrix(double[][] A);  Matrix(double[] A);  Matrix(double[] A, int offset, int length);  Matrix(int m, int n, int ld, DoubleBuffer A); static Matrix of(Layout layout, int m, int n); static Matrix of(Layout layout, int m, int n, int ld, DoubleBuffer A); static Matrix eye(int n); static Matrix eye(int m, int n); static Matrix randn(int m, int n); static Matrix rand(int m, int n, Distribution distribution); static Matrix rand(int m, int n, double lo, double hi); static Matrix diag(double[] diag); static Matrix toeplitz(double[] a); static Matrix toeplitz(double[] kl, double[] ku); @Override int nrows(); @Override int ncols(); @Override long size(); Layout layout(); int ld(); boolean isSubmatrix(); boolean isSymmetric(); Matrix uplo(UPLO uplo); UPLO uplo(); Matrix triangular(Diag diag); Diag triangular(); @Override Matrix clone(); double[][] toArray(); Matrix submatrix(int i, int j, int k, int l); void fill(double x); Matrix transpose(); @Override boolean equals(Object o); boolean equals(Matrix o, double eps); @Override double get(int i, int j); @Override Matrix set(int i, int j, double x); Matrix set(int i, int j, Matrix B); double add(int i, int j, double b); double sub(int i, int j, double b); double mul(int i, int j, double b); double div(int i, int j, double b); Matrix add(double b); Matrix sub(double b); Matrix mul(double b); Matrix div(double b); Matrix add(int i, int j, double alpha, Matrix B); Matrix sub(int i, int j, double alpha, Matrix B); Matrix mul(int i, int j, double alpha, Matrix B); Matrix div(int i, int j, double alpha, Matrix B); Matrix add(double alpha, Matrix B); Matrix sub(double alpha, Matrix B); Matrix mul(double alpha, Matrix B); Matrix div(double alpha, Matrix B); Matrix add(double alpha, Matrix A, double beta, Matrix B); Matrix sub(double alpha, Matrix A, double beta, Matrix B); Matrix mul(double alpha, Matrix A, Matrix B); Matrix div(double alpha, Matrix A, Matrix B); double add(int i, int j, double alpha, double beta); Matrix add(int i, int j, double alpha, double beta, Matrix B); Matrix add(double alpha, double beta, Matrix B); Matrix add(double alpha, double[] x, double[] y); Matrix replaceNaN(double x); double sum(); double norm1(); double norm2(); double norm(); double normInf(); double normFro(); double xAx(double[] x); double[] rowSums(); double[] rowMeans(); double[] rowSds(); double[] colSums(); double[] colMeans(); double[] colSds(); Matrix scale(); Matrix scale(double[] center, double[] scale); Matrix inverse(); void mv(Transpose trans, double alpha, DoubleBuffer x, double beta, DoubleBuffer y); @Override void mv(Transpose trans, double alpha, double[] x, double beta, double[] y); @Override void mv(double[] work, int inputOffset, int outputOffset); @Override void tv(double[] work, int inputOffset, int outputOffset); void mm(Transpose transA, Transpose transB, double alpha, Matrix B, double beta, Matrix C); Matrix ata(); Matrix aat(); Matrix adb(Transpose transA, Transpose transB, Matrix B, double[] diag); Matrix mm(Matrix B); Matrix mt(Matrix B); Matrix tm(Matrix B); Matrix tt(Matrix B); LU lu(); LU lu(boolean overwrite); Cholesky cholesky(); Cholesky cholesky(boolean overwrite); QR qr(); QR qr(boolean overwrite); SVD svd(); SVD svd(boolean vectors, boolean overwrite); EVD eigen(); EVD eigen(boolean vl, boolean vr, boolean overwrite); }
Matrix extends DMatrix { public void mm(Transpose transA, Transpose transB, double alpha, Matrix B, double beta, Matrix C) { if (isSymmetric() && transB == NO_TRANSPOSE && B.layout() == C.layout()) { BLAS.engine.symm(C.layout(), LEFT, uplo, C.m, C.n, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } else if (B.isSymmetric() && transA == NO_TRANSPOSE && layout() == C.layout()) { BLAS.engine.symm(C.layout(), RIGHT, B.uplo, C.m, C.n, alpha, B.A, B.ld, A, ld, beta, C.A, C.ld); } else { if (C.layout() != layout()) transA = flip(transA); if (C.layout() != B.layout()) transB = flip(transB); int k = transA == NO_TRANSPOSE ? n : m; BLAS.engine.gemm(layout(), transA, transB, C.m, C.n, k, alpha, A, ld, B.A, B.ld, beta, C.A, C.ld); } } Matrix(int m, int n);  Matrix(int m, int n, double a);  Matrix(int m, int n, double[][] A);  Matrix(double[][] A);  Matrix(double[] A);  Matrix(double[] A, int offset, int length);  Matrix(int m, int n, int ld, DoubleBuffer A); static Matrix of(Layout layout, int m, int n); static Matrix of(Layout layout, int m, int n, int ld, DoubleBuffer A); static Matrix eye(int n); static Matrix eye(int m, int n); static Matrix randn(int m, int n); static Matrix rand(int m, int n, Distribution distribution); static Matrix rand(int m, int n, double lo, double hi); static Matrix diag(double[] diag); static Matrix toeplitz(double[] a); static Matrix toeplitz(double[] kl, double[] ku); @Override int nrows(); @Override int ncols(); @Override long size(); Layout layout(); int ld(); boolean isSubmatrix(); boolean isSymmetric(); Matrix uplo(UPLO uplo); UPLO uplo(); Matrix triangular(Diag diag); Diag triangular(); @Override Matrix clone(); double[][] toArray(); Matrix submatrix(int i, int j, int k, int l); void fill(double x); Matrix transpose(); @Override boolean equals(Object o); boolean equals(Matrix o, double eps); @Override double get(int i, int j); @Override Matrix set(int i, int j, double x); Matrix set(int i, int j, Matrix B); double add(int i, int j, double b); double sub(int i, int j, double b); double mul(int i, int j, double b); double div(int i, int j, double b); Matrix add(double b); Matrix sub(double b); Matrix mul(double b); Matrix div(double b); Matrix add(int i, int j, double alpha, Matrix B); Matrix sub(int i, int j, double alpha, Matrix B); Matrix mul(int i, int j, double alpha, Matrix B); Matrix div(int i, int j, double alpha, Matrix B); Matrix add(double alpha, Matrix B); Matrix sub(double alpha, Matrix B); Matrix mul(double alpha, Matrix B); Matrix div(double alpha, Matrix B); Matrix add(double alpha, Matrix A, double beta, Matrix B); Matrix sub(double alpha, Matrix A, double beta, Matrix B); Matrix mul(double alpha, Matrix A, Matrix B); Matrix div(double alpha, Matrix A, Matrix B); double add(int i, int j, double alpha, double beta); Matrix add(int i, int j, double alpha, double beta, Matrix B); Matrix add(double alpha, double beta, Matrix B); Matrix add(double alpha, double[] x, double[] y); Matrix replaceNaN(double x); double sum(); double norm1(); double norm2(); double norm(); double normInf(); double normFro(); double xAx(double[] x); double[] rowSums(); double[] rowMeans(); double[] rowSds(); double[] colSums(); double[] colMeans(); double[] colSds(); Matrix scale(); Matrix scale(double[] center, double[] scale); Matrix inverse(); void mv(Transpose trans, double alpha, DoubleBuffer x, double beta, DoubleBuffer y); @Override void mv(Transpose trans, double alpha, double[] x, double beta, double[] y); @Override void mv(double[] work, int inputOffset, int outputOffset); @Override void tv(double[] work, int inputOffset, int outputOffset); void mm(Transpose transA, Transpose transB, double alpha, Matrix B, double beta, Matrix C); Matrix ata(); Matrix aat(); Matrix adb(Transpose transA, Transpose transB, Matrix B, double[] diag); Matrix mm(Matrix B); Matrix mt(Matrix B); Matrix tm(Matrix B); Matrix tt(Matrix B); LU lu(); LU lu(boolean overwrite); Cholesky cholesky(); Cholesky cholesky(boolean overwrite); QR qr(); QR qr(boolean overwrite); SVD svd(); SVD svd(boolean vectors, boolean overwrite); EVD eigen(); EVD eigen(boolean vl, boolean vr, boolean overwrite);  }