/** * @param A * @param B * @return */ public static Matrix vstack(Matrix A, Matrix B) { int aLen = A.m * A.n; int bLen = B.m * B.n; float[] C = new float[aLen + bLen]; System.arraycopy(A.getData(), 0, C, 0, aLen); System.arraycopy(B.getData(), 0, C, aLen, bLen); return new Matrix(C, A.m + B.m, Math.max(A.n, B.n)); }
/** * @param A * @param B * @return */ public static Matrix mmul(final Matrix A, final Matrix B) { try { if (A.n != B.m) throw new Matrix.WrongDimensionsException(); } catch (Matrix.WrongDimensionsException e) { e.printStackTrace(); System.exit(1); } float[] result = new float[A.m * B.n]; Level3.sgemm( BlasOrder.ROW_MAJOR, BlasTrans.NO_TRANS, BlasTrans.NO_TRANS, A.m, B.n, A.n, 1f, A.getData(), A.ld, B.getData(), B.ld, 1f, result, B.ld); return new Matrix(result, A.m, B.n); }
/** * @param A * @param B * @return */ public static float dot(Matrix A, Matrix B) { int aLen = A.m * A.n; int bLen = B.m * B.n; try { if (bLen != aLen) throw new Matrix.WrongDimensionsException(); } catch (Matrix.WrongDimensionsException e) { e.printStackTrace(); System.exit(1); } float[] dotP = new float[1]; Level1.sdot(aLen, dotP, A.getData(), B.getData()); return dotP[0]; }