Java Utililty Methods Matrix Multiply

List of utility methods to do Matrix Multiply

Description

The list of methods to do Matrix Multiply are organized into topic(s).

Method

voidmatrixMultiplyWithThreadOffset(double[] A, double[] Adiag, double[] B, int aHeight, int bWidth, int comm, int bz, int threadRowOffset, int rowOffset, double[] C)
matrix Multiply With Thread Offset
int aHeightBlocks = aHeight / bz; 
int aLastBlockHeight = aHeight - (aHeightBlocks * bz);
if (aLastBlockHeight > 0) {
    aHeightBlocks++;
int bWidthBlocks = bWidth / bz; 
int bLastBlockWidth = bWidth - (bWidthBlocks * bz);
if (bLastBlockWidth > 0) {
...
voidmatrixScalarMultiplication(double[][] w, double v)
w = w.*v
int w1 = w.length;
int w2 = w[0].length;
for (int w_i1 = 0; w_i1 < w1; w_i1++) {
    for (int w_i2 = 0; w_i2 < w2; w_i2++) {
        w[w_i1][w_i2] *= v;
boolean[][]multiply(boolean[][] m1, boolean[][] m2)
multiply
int mA = m1.length;
int nA = m1[0].length;
int mB = m2.length;
int nB = m2[0].length;
if (nA != mB) {
    throw new RuntimeException("Illegal matrix dimensions.");
boolean[][] toReturn = new boolean[mA][nB];
...
boolean[]multiply(boolean[][] matrix, boolean[] vector)
multiply
if (matrix == null || vector == null) {
    return null;
if (matrix[0].length != vector.length) {
    return null;
int n = matrix[0].length;
int m = matrix.length;
...
double[][]multiply(double[][] a, double[][] b)
Multiplies the two arrays.
int size = Math.min(a.length, b.length);
double[][] result = new double[size][];
for (int i = 0; i < size; i++)
    result[i] = multiply(a[i], b[i]);
return result;
double[][]multiply(double[][] a, double[][] x)
multiply
double[][] y = new double[a.length][x[0].length];
double[][] x_t = transpose(x);
for (int i = 0; i < a.length; i++) {
    for (int j = 0; j < x_t.length; j++) {
        y[i][j] = dotProduct(a[i], x_t[j]);
return y;
...
voidmultiply(double[][] dest, double[][] a, double[][] b)
multiply
for (int i = 0; i < dest.length; i++) {
    for (int j = 0; j < dest[i].length; j++) {
        dest[i][j] = a[i][j] * b[i][j];
double[]multiply(double[][] m, double[] x)
Multiply a square matrix and a vector.
assert (m[0].length == x.length);
double[] y = new double[m.length];
for (int i = 0; i < m.length; i++)
    for (int j = 0; j < x.length; j++) {
        y[i] += m[i][j] * x[j];
return y;
double[][]multiply(double[][] m1, double[][] m2)
multiply
int p1 = m1.length, p2 = m2.length, q2 = m2[0].length;
double[][] result = new double[p1][q2];
for (int i = 0; i < p1; i++)
    for (int j = 0; j < q2; j++)
        for (int k = 0; k < p2; k++)
            result[i][j] += m1[i][k] * m2[k][j];
return result;
double[][]multiply(double[][] p, double[][] q)
Multiply two matrices
double[][] m = new double[3][3];
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
        m[i][j] = 0;
        for (int k = 0; k < 3; k++) {
            m[i][j] += p[i][k] * q[k][j];
return m;