@Test public void testMm() { System.out.println("mm"); float[][] A = { { 0.7220180f, 0.07121225f, 0.6881997f}, {-0.2648886f, -0.89044952f, 0.3700456f}, {-0.6391588f, 0.44947578f, 0.6240573f} }; float[][] B = { {0.6881997f, -0.07121225f, 0.7220180f}, {0.3700456f, 0.89044952f, -0.2648886f}, {0.6240573f, -0.44947578f, -0.6391588f} }; float[][] C = { { 0.9527204f, -0.2973347f, 0.06257778f}, {-0.2808735f, -0.9403636f, -0.19190231f}, { 0.1159052f, 0.1652528f, -0.97941688f} }; float[][] D = { { 0.9887140f, 0.1482942f, -0.0212965f}, { 0.1482942f, -0.9889421f, -0.0015881f}, {-0.0212965f, -0.0015881f, -0.9997719f} }; float[][] E = { {0.0000f, 0.0000f, 1.0000f}, {0.0000f, -1.0000f, 0.0000f}, {1.0000f, 0.0000f, 0.0000f} }; FloatMatrix a = new FloatMatrix(A); FloatMatrix b = new FloatMatrix(B); float[][] F = b.mm(a).transpose().toArray(); assertTrue(MathEx.equals(a.mm(b).toArray(), C, 1E-6f)); assertTrue(MathEx.equals(a.mt(b).toArray(), D, 1E-6f)); assertTrue(MathEx.equals(a.tm(b).toArray(), E, 1E-6f)); assertTrue(MathEx.equals(a.tt(b).toArray(), F, 1E-6f)); }
public void mm(Transpose transA, Transpose transB, float alpha, FloatMatrix B, float beta, FloatMatrix 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); } }
FloatMatrix extends SMatrix { public void mm(Transpose transA, Transpose transB, float alpha, FloatMatrix B, float beta, FloatMatrix 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); } } }
FloatMatrix extends SMatrix { public void mm(Transpose transA, Transpose transB, float alpha, FloatMatrix B, float beta, FloatMatrix 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); } } FloatMatrix(int m, int n);  FloatMatrix(int m, int n, float a);  FloatMatrix(int m, int n, float[][] A);  FloatMatrix(float[][] A);  FloatMatrix(float[] A);  FloatMatrix(float[] A, int offset, int length);  FloatMatrix(int m, int n, int ld, FloatBuffer A); }
FloatMatrix extends SMatrix { public void mm(Transpose transA, Transpose transB, float alpha, FloatMatrix B, float beta, FloatMatrix 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); } } FloatMatrix(int m, int n);  FloatMatrix(int m, int n, float a);  FloatMatrix(int m, int n, float[][] A);  FloatMatrix(float[][] A);  FloatMatrix(float[] A);  FloatMatrix(float[] A, int offset, int length);  FloatMatrix(int m, int n, int ld, FloatBuffer A); static FloatMatrix of(Layout layout, int m, int n); static FloatMatrix of(Layout layout, int m, int n, int ld, FloatBuffer A); static FloatMatrix eye(int n); static FloatMatrix eye(int m, int n); static FloatMatrix randn(int m, int n); static FloatMatrix rand(int m, int n, Distribution distribution); static FloatMatrix rand(int m, int n, float lo, float hi); static FloatMatrix diag(float[] diag); static FloatMatrix toeplitz(float[] a); static FloatMatrix toeplitz(float[] kl, float[] ku); @Override int nrows(); @Override int ncols(); @Override long size(); Layout layout(); int ld(); boolean isSubmatrix(); boolean isSymmetric(); FloatMatrix uplo(UPLO uplo); UPLO uplo(); FloatMatrix triangular(Diag diag); Diag triangular(); @Override FloatMatrix clone(); float[][] toArray(); FloatMatrix submatrix(int i, int j, int k, int l); void fill(float x); FloatMatrix transpose(); @Override boolean equals(Object o); boolean equals(FloatMatrix o, float eps); @Override float get(int i, int j); @Override FloatMatrix set(int i, int j, float x); FloatMatrix set(int i, int j, FloatMatrix B); float add(int i, int j, float b); float sub(int i, int j, float b); float mul(int i, int j, float b); float div(int i, int j, float b); FloatMatrix add(float b); FloatMatrix sub(float b); FloatMatrix mul(float b); FloatMatrix div(float b); FloatMatrix add(int i, int j, float alpha, FloatMatrix B); FloatMatrix sub(int i, int j, float alpha, FloatMatrix B); FloatMatrix mul(int i, int j, float alpha, FloatMatrix B); FloatMatrix div(int i, int j, float alpha, FloatMatrix B); FloatMatrix add(float alpha, FloatMatrix B); FloatMatrix sub(float alpha, FloatMatrix B); FloatMatrix mul(float alpha, FloatMatrix B); FloatMatrix div(float alpha, FloatMatrix B); FloatMatrix add(float alpha, FloatMatrix A, float beta, FloatMatrix B); FloatMatrix sub(float alpha, FloatMatrix A, float beta, FloatMatrix B); FloatMatrix mul(float alpha, FloatMatrix A, FloatMatrix B); FloatMatrix div(float alpha, FloatMatrix A, FloatMatrix B); double add(int i, int j, float alpha, float beta); FloatMatrix add(int i, int j, float alpha, float beta, FloatMatrix B); FloatMatrix add(float alpha, float beta, FloatMatrix B); FloatMatrix add(float alpha, float[] x, float[] y); FloatMatrix replaceNaN(float x); float sum(); float norm1(); float norm2(); float norm(); float normInf(); float normFro(); float xAx(float[] x); float[] rowSums(); float[] rowMeans(); float[] rowSds(); float[] colSums(); float[] colMeans(); float[] colSds(); FloatMatrix scale(); FloatMatrix scale(float[] center, float[] scale); FloatMatrix inverse(); void mv(Transpose trans, float alpha, FloatBuffer x, float beta, FloatBuffer y); @Override void mv(Transpose trans, float alpha, float[] x, float beta, float[] y); @Override void mv(float[] work, int inputOffset, int outputOffset); @Override void tv(float[] work, int inputOffset, int outputOffset); void mm(Transpose transA, Transpose transB, float alpha, FloatMatrix B, float beta, FloatMatrix C); FloatMatrix ata(); FloatMatrix aat(); FloatMatrix adb(Transpose transA, Transpose transB, FloatMatrix B, float[] diag); FloatMatrix mm(FloatMatrix B); FloatMatrix mt(FloatMatrix B); FloatMatrix tm(FloatMatrix B); FloatMatrix tt(FloatMatrix 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); }
FloatMatrix extends SMatrix { public void mm(Transpose transA, Transpose transB, float alpha, FloatMatrix B, float beta, FloatMatrix 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); } } FloatMatrix(int m, int n);  FloatMatrix(int m, int n, float a);  FloatMatrix(int m, int n, float[][] A);  FloatMatrix(float[][] A);  FloatMatrix(float[] A);  FloatMatrix(float[] A, int offset, int length);  FloatMatrix(int m, int n, int ld, FloatBuffer A); static FloatMatrix of(Layout layout, int m, int n); static FloatMatrix of(Layout layout, int m, int n, int ld, FloatBuffer A); static FloatMatrix eye(int n); static FloatMatrix eye(int m, int n); static FloatMatrix randn(int m, int n); static FloatMatrix rand(int m, int n, Distribution distribution); static FloatMatrix rand(int m, int n, float lo, float hi); static FloatMatrix diag(float[] diag); static FloatMatrix toeplitz(float[] a); static FloatMatrix toeplitz(float[] kl, float[] ku); @Override int nrows(); @Override int ncols(); @Override long size(); Layout layout(); int ld(); boolean isSubmatrix(); boolean isSymmetric(); FloatMatrix uplo(UPLO uplo); UPLO uplo(); FloatMatrix triangular(Diag diag); Diag triangular(); @Override FloatMatrix clone(); float[][] toArray(); FloatMatrix submatrix(int i, int j, int k, int l); void fill(float x); FloatMatrix transpose(); @Override boolean equals(Object o); boolean equals(FloatMatrix o, float eps); @Override float get(int i, int j); @Override FloatMatrix set(int i, int j, float x); FloatMatrix set(int i, int j, FloatMatrix B); float add(int i, int j, float b); float sub(int i, int j, float b); float mul(int i, int j, float b); float div(int i, int j, float b); FloatMatrix add(float b); FloatMatrix sub(float b); FloatMatrix mul(float b); FloatMatrix div(float b); FloatMatrix add(int i, int j, float alpha, FloatMatrix B); FloatMatrix sub(int i, int j, float alpha, FloatMatrix B); FloatMatrix mul(int i, int j, float alpha, FloatMatrix B); FloatMatrix div(int i, int j, float alpha, FloatMatrix B); FloatMatrix add(float alpha, FloatMatrix B); FloatMatrix sub(float alpha, FloatMatrix B); FloatMatrix mul(float alpha, FloatMatrix B); FloatMatrix div(float alpha, FloatMatrix B); FloatMatrix add(float alpha, FloatMatrix A, float beta, FloatMatrix B); FloatMatrix sub(float alpha, FloatMatrix A, float beta, FloatMatrix B); FloatMatrix mul(float alpha, FloatMatrix A, FloatMatrix B); FloatMatrix div(float alpha, FloatMatrix A, FloatMatrix B); double add(int i, int j, float alpha, float beta); FloatMatrix add(int i, int j, float alpha, float beta, FloatMatrix B); FloatMatrix add(float alpha, float beta, FloatMatrix B); FloatMatrix add(float alpha, float[] x, float[] y); FloatMatrix replaceNaN(float x); float sum(); float norm1(); float norm2(); float norm(); float normInf(); float normFro(); float xAx(float[] x); float[] rowSums(); float[] rowMeans(); float[] rowSds(); float[] colSums(); float[] colMeans(); float[] colSds(); FloatMatrix scale(); FloatMatrix scale(float[] center, float[] scale); FloatMatrix inverse(); void mv(Transpose trans, float alpha, FloatBuffer x, float beta, FloatBuffer y); @Override void mv(Transpose trans, float alpha, float[] x, float beta, float[] y); @Override void mv(float[] work, int inputOffset, int outputOffset); @Override void tv(float[] work, int inputOffset, int outputOffset); void mm(Transpose transA, Transpose transB, float alpha, FloatMatrix B, float beta, FloatMatrix C); FloatMatrix ata(); FloatMatrix aat(); FloatMatrix adb(Transpose transA, Transpose transB, FloatMatrix B, float[] diag); FloatMatrix mm(FloatMatrix B); FloatMatrix mt(FloatMatrix B); FloatMatrix tm(FloatMatrix B); FloatMatrix tt(FloatMatrix 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);  }