List of utility methods to do Matrix Multiply
void | matrix4x4f_Mult(float[] result, float[] a, float[] b) matrixx Mult result[0] = a[0] * b[0] + a[1] * b[4] + a[2] * b[8] + a[3] * b[12]; result[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[9] + a[3] * b[13]; result[2] = a[0] * b[2] + a[1] * b[6] + a[2] * b[10] + a[3] * b[14]; result[3] = a[0] * b[3] + a[1] * b[7] + a[2] * b[11] + a[3] * b[15]; result[4] = a[4] * b[0] + a[5] * b[4] + a[6] * b[8] + a[7] * b[12]; result[5] = a[4] * b[1] + a[5] * b[5] + a[6] * b[9] + a[7] * b[13]; result[6] = a[4] * b[2] + a[5] * b[6] + a[6] * b[10] + a[7] * b[14]; result[7] = a[4] * b[3] + a[5] * b[7] + a[6] * b[11] + a[7] * b[15]; ... |
void | matrix_matrix_mult(double ad[][], double ad1[][], double ad2[][]) matrimatrimult for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) ad2[i][j] = ad[i][0] * ad1[0][j] + ad[i][1] * ad1[1][j] + ad[i][2] * ad1[2][j]; |
void | matrixMult(final float[] result, float[] m1, float[] m2) matrix Mult if (result == m1) { m1 = m1.clone(); if (result == m2) { m2 = m2.clone(); int i = 0; for (int j = 0; j < 16; j += 4) { ... |
double[][] | matrixMultiplication(double[][] w, double[][] v) results = w*v int w1 = w.length; int w2 = w[0].length; int v1 = v.length; int v2 = v[0].length; if (w2 != v1) { System.out.println("Matrix dimensions do not agree..."); System.exit(-1); double[][] result = new double[w1][v2]; for (int w_i1 = 0; w_i1 < w1; w_i1++) { for (int v_i2 = 0; v_i2 < v2; v_i2++) { double sum = 0; for (int w_i2 = 0; w_i2 < w2; w_i2++) { sum += w[w_i1][w_i2] * v[w_i2][v_i2]; result[w_i1][v_i2] = sum; return result; |
void | matrixMultiply(double[][] A, double[][] B, int aHeight, int bWidth, int comm, int bz, double[][] C) matrix Multiply 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) { ... |
double[][] | matrixMultiply(double[][] A, double[][] B, int n) matrix Multiply double nMatrix[][] = new double[n][n]; int t = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { t = 0; for (int k = 0; k < n; k++) { t += A[i][k] * B[k][j]; nMatrix[i][j] = t; return nMatrix; |
float[] | matrixMultiply(double[][] M, float[] V) matrix Multiply int rows = M.length; int cols = V.length; float[] out = new float[rows]; for (int i = 0; i < rows; i++) { double total = 0.0; double[] matrixRow = M[i]; for (int j = 0; j < cols; j++) { total += V[j] * matrixRow[j]; ... |
double[][] | matrixMultiply(double[][] M1, double[][] M2) multiplies two 3x3 - matrixes NOT TESTED!! double[][] M = new double[3][3]; M[0][0] = M1[0][0] * M2[0][0] + M1[0][1] * M2[1][0] + M1[0][2] * M2[2][0]; M[0][1] = M1[0][0] * M2[0][1] + M1[0][1] * M2[1][1] + M1[0][2] * M2[2][1]; M[0][2] = M1[0][0] * M2[0][2] + M1[0][1] * M2[1][2] + M1[0][2] * M2[2][2]; M[1][0] = M1[1][0] * M2[0][0] + M1[1][1] * M2[1][0] + M1[1][2] * M2[2][0]; M[1][1] = M1[1][0] * M2[0][1] + M1[1][1] * M2[1][1] + M1[1][2] * M2[2][1]; M[1][2] = M1[1][0] * M2[0][2] + M1[1][1] * M2[1][2] + M1[1][2] * M2[2][2]; M[2][0] = M1[2][0] * M2[0][0] + M1[2][1] * M2[1][0] + M1[2][2] * M2[2][0]; ... |
double[] | matrixmultiply(final double[][] A, final double[] b) Multiply matrix A with vector b. double[] answer = new double[b.length]; for (int row = 0; row < answer.length; ++row) for (int col = 0; col < b.length; ++col) answer[row] += A[row][col] * b[col]; return answer; |
double[][] | matrixMultiplyTwo(final double[][] first, final double[][] second) matrix Multiply Two final int firstRows = first.length; final int firstCols = first[0].length; final int secondRows = second.length; final int secondCols = second[0].length; if (firstCols != secondRows) throw new ArrayIndexOutOfBoundsException("Trying to multiply matrices of different dimensions?!"); final double ret[][] = new double[firstRows][secondCols]; final double err[][] = new double[firstRows][secondCols]; ... |