private static void innerDiagonalMultAddBlockTransA_vector(RowD1Matrix64F a, D1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d, int rowStart, int colStart) { if (a.numRows != c.numRows) throw new MatrixDimensionException("The 'b' and 'c' matrices do not have compatible dimensions"); for (int i = 0; i < a.numCols; i++) { for (int j = 0; j < c.numCols; j++) { int indexA = i; int indexB = 0; int indexC = j; int end = indexC + c.numRows * c.numCols; double total = 0; // loop for k for (; indexC < end; indexC += c.numCols) { total += a.data[indexA] * c.data[indexC] * b.data[indexB]; indexA += a.numCols; indexB++; } int dIndex = (i + rowStart) * d.numCols + j + colStart; d.data[dIndex] += total; } } }
private static void multInner_matrix(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c) { if (a.numRows != b.numCols) throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); for (int i = 0; i < a.numCols; i++) { for (int j = i; j < a.numCols; j++) { int indexC1 = i * c.numCols + j; int indexC2 = j * c.numCols + i; int indexA = i; int indexB = j; int indexC = 0; double sum = 0; int end = indexA + a.numRows * a.numCols; for (; indexA < end; indexA += a.numCols, indexB += a.numCols, indexC += (b.numCols + 1)) { sum += a.data[indexA] * a.data[indexB] * b.data[indexC]; } c.data[indexC1] = c.data[indexC2] = sum; } } }
private static void multOuter_matrix(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c) { if (a.numCols != b.numCols) throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); for (int i = 0; i < a.numRows; i++) { int indexC1 = i * c.numCols + i; int indexC2 = indexC1; for (int j = i; j < a.numRows; j++, indexC2 += c.numCols) { int indexA = i * a.numCols; int indexB = j * a.numCols; int indexC = 0; double sum = 0; int end = indexA + a.numCols; for (; indexA < end; indexA++, indexB++, indexC += (b.numCols + 1)) { sum += a.data[indexA] * a.data[indexB] * b.data[indexC]; } c.data[indexC2] = c.data[indexC1++] = sum; } } }
private static void innerDiagonalMultAddTransA_matrix(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d) { if (b.numCols != c.numRows) throw new MatrixDimensionException("The 'b' and 'c' matrices do not have compatible dimensions"); int dIndex = 0; for (int i = 0; i < a.numCols; i++) { for (int j = 0; j < c.numCols; j++) { int indexA = i; int indexB = 0; int indexC = j; int end = indexC + c.numRows * c.numCols; double total = 0; // loop for k for (; indexC < end; indexC += c.numCols) { total += a.data[indexA] * c.data[indexC] * b.data[indexB]; indexA += a.numCols; indexB += b.numCols + 1; } d.data[dIndex++] += total; } } }
private static void innerDiagonalMult_vector(RowD1Matrix64F a, D1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d) { if (a.numCols != c.numRows) throw new MatrixDimensionException("The 'a' and 'c' matrices do not have compatible dimensions"); int aIndexStart = 0; int dIndex = 0; for (int i = 0; i < a.numRows; i++) { for (int j = 0; j < c.numCols; j++) { double total = 0; int indexA = aIndexStart; int indexC = j; int indexB = 0; int end = indexA + c.numRows; while (indexA < end) { total += a.data[indexA++] * c.data[indexC] * b.data[indexB]; indexC += c.numCols; indexB++; } d.data[dIndex++] = total; } aIndexStart += a.numCols; } }
private static void innerDiagonalMultAddTransA_vector(RowD1Matrix64F a, D1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d) { if (a.numRows != c.numRows) throw new MatrixDimensionException("The 'b' and 'c' matrices do not have compatible dimensions"); int dIndex = 0; for (int i = 0; i < a.numCols; i++) { for (int j = 0; j < c.numCols; j++) { int indexA = i; int indexB = 0; int indexC = j; int end = indexC + c.numRows * c.numCols; double total = 0; // loop for k for (; indexC < end; indexC += c.numCols) { total += a.data[indexA] * c.data[indexC] * b.data[indexB]; indexA += a.numCols; indexB++; } d.data[dIndex++] += total; } } }
throw new MatrixDimensionException("The 'c' and 'd' matrices do not have compatible dimensions");
private static void innerDiagonalMultAddBlockTransA_matrix(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d, int rowStart, int colStart) { if (b.numCols != c.numRows) throw new MatrixDimensionException("The 'b' and 'c' matrices do not have compatible dimensions"); for (int i = 0; i < a.numCols; i++) { for (int j = 0; j < c.numCols; j++) { int indexA = i; int indexB = 0; int indexC = j; int end = indexC + c.numRows * c.numCols; double total = 0; // loop for k for (; indexC < end; indexC += c.numCols) { total += a.data[indexA] * c.data[indexC] * b.data[indexB]; indexA += a.numCols; indexB += b.numCols + 1; } int dIndex = (i + rowStart) * d.numCols + j + colStart; d.data[dIndex] += total; } } }
private static void innerDiagonalMultTransA_matrix(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d) { if (b.numCols != c.numRows) throw new MatrixDimensionException("The 'b' and 'c' matrices do not have compatible dimensions"); int dIndex = 0; for (int i = 0; i < a.numCols; i++) { for (int j = 0; j < c.numCols; j++) { int indexA = i; int indexB = 0; int indexC = j; int end = indexC + c.numRows * c.numCols; double total = 0; // loop for k for (; indexC < end; indexC += c.numCols) { total += a.data[indexA] * c.data[indexC] * b.data[indexB]; indexA += a.numCols; indexB += b.numCols + 1; } d.data[dIndex++] = total; } } }
private static void innerDiagonalMultTransA_vector(RowD1Matrix64F a, D1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d) { if (a.numRows != c.numRows) throw new MatrixDimensionException("The 'a' and 'c' matrices do not have compatible dimensions"); int dIndex = 0; for (int i = 0; i < a.numCols; i++) { for (int j = 0; j < c.numCols; j++) { int indexA = i; int indexB = 0; int indexC = j; int end = indexC + c.numRows * c.numCols; double total = 0; // loop for k for (; indexC < end; indexC += c.numCols) { total += a.data[indexA] * c.data[indexC] * b.data[indexB]; indexA += a.numCols; indexB++; } d.data[dIndex++] = total; } } }
private static void innerDiagonalMult_matrix(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d) { if (b.numCols != c.numRows) throw new MatrixDimensionException("The 'b' and 'c' matrices do not have compatible dimensions"); int aIndexStart = 0; int dIndex = 0; for (int i = 0; i < a.numRows; i++) { for (int j = 0; j < c.numCols; j++) { double total = 0; int indexA = aIndexStart; int indexC = j; int indexB = 0; int end = indexA + c.numRows; while (indexA < end) { total += a.data[indexA++] * c.data[indexC] * b.data[indexB]; indexC += c.numCols; indexB += b.numCols + 1; } d.data[dIndex++] = total; } aIndexStart += a.numCols; } }
private static void innerDiagonalMultAddBlockTransA_matrix(double a, RowD1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d, RowD1Matrix64F e, int rowStart, int colStart) { if (c.numCols != d.numRows) throw new MatrixDimensionException("The 'c' and 'd' matrices do not have compatible dimensions"); for (int i = 0; i < b.numCols; i++) { for (int j = 0; j < d.numCols; j++) { int indexA = i; int indexB = 0; int indexC = j; int end = indexC + d.numRows * d.numCols; double total = 0; // loop for k for (; indexC < end; indexC += d.numCols) { total += b.data[indexA] * d.data[indexC] * c.data[indexB]; indexA += b.numCols; indexB += c.numCols + 1; } int dIndex = (i + rowStart) * e.numCols + j + colStart; e.data[dIndex] += a * total; } } }
private static void postMultTransA_matrix(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c) { if (a.numCols != c.numRows || b.numCols != c.numCols) throw new MatrixDimensionException("The results matrix does not have the desired dimensions"); int index = 0; int bIndex = 0; int maxValue = Math.min(b.numRows, b.numCols); for (int i = 0; i < maxValue; i++) { int index2 = i; int end = index + a.numCols; while (index < end) { c.data[index2] = b.data[bIndex] * a.data[index++]; index2 += c.numCols; } bIndex += b.numCols + 1; } }
private static void postMultTransA_vector(RowD1Matrix64F a, D1Matrix64F b, RowD1Matrix64F c) { if (a.numCols != c.numRows) throw new MatrixDimensionException("The results matrix does not have the desired dimensions"); int index = 0; int bIndex = 0; int maxValue = Math.min(c.numCols, b.numRows); // fix this for (int i = 0; i < maxValue; i++) { int index2 = i; int end = index + a.numCols; while (index < end) { c.data[index2] = b.data[bIndex] * a.data[index++]; index2 += c.numCols; } bIndex ++; } }
throw new IllegalArgumentException("Neither 'a' or 'b' can be the same matrix as 'c'"); else if( a.numRows != b.numCols ) { throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); } else if( a.numCols != c.numRows || b.numRows != c.numCols ) { throw new MatrixDimensionException("The results matrix does not have the desired dimensions");
private static void postMult_matrix(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c) { if (a.numCols != b.numRows) throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); else if (b.numCols != c.numCols) throw new MatrixDimensionException("The results matrix does not have the desired dimensions"); for (int row = 0; row < a.numRows; row++) { for (int col = 0; col < Math.min(b.numRows, b.numCols); col++) { c.unsafe_set(row, col, b.unsafe_get(col, col) * a.unsafe_get(row, col)); } } }
/** * <p>Performs the following operation:<br> * <br> * c = a * b * c * </br> * </p> * <p> where we assume that matrix 'b' is a diagonal matrix. </p> * <p> The 'b' matrix can also be passed in as a vector of the diagonal elements </p> * @param a The left matrix in the multiplication operation. Not modified. * @param b The middle matrix in the multiplication operation. Not modified. Assumed to be diagonal. * @param c The right matrix in the multiplication operation. Not modified. * @param d Where the results of the operation are stored. Modified. */ public static void innerDiagonalMult(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d) { if (a == c || b == c || c == d) throw new IllegalArgumentException("Neither 'a', 'b', or 'c' can be the same matrix as 'd'"); else if (a.numCols != b.numRows) throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); else if (a.numRows != d.numRows || c.numCols != d.numCols) throw new MatrixDimensionException("The results matrix does not have the desired dimensions"); if (b.numCols > 1) innerDiagonalMult_matrix(a, b, c, d); else innerDiagonalMult_vector(a, b, c, d); }
/** * <p>Performs the following operation:<br> * <br> * d = a<sup>T</sup> * b * c * </br> * </p> * <p> where we assume that matrix 'b' is a diagonal matrix. </p> * <p> The 'b' matrix can also be passed in as a vector of the diagonal elements </p> * @param a The left matrix in the multiplication operation. Not modified. * @param b The middle matrix in the multiplication operation. Not modified. Assumed to be diagonal. * @param c The right matrix in the multiplication operation. Not modified. * @param d Where the results of the operation are stored. Modified. */ public static void innerDiagonalMultTransA(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d) { if (a == c || b == c || c == d) throw new IllegalArgumentException("Neither 'a', 'b', or 'c' can be the same matrix as 'd'"); else if (a.numRows != b.numRows) throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); else if (a.numCols != d.numRows || c.numCols != d.numCols) throw new MatrixDimensionException("The results matrix does not have the desired dimensions"); if (b.numCols > 1) innerDiagonalMultTransA_matrix(a, b, c, d); else innerDiagonalMultTransA_vector(a, b, c, d); }
/** * <p>Performs the following operation:<br> * <br> * d = d + a<sup>T</sup> * b * c * </br> * </p> * <p> where we assume that matrix 'b' is a diagonal matrix. </p> * <p> The 'b' matrix can also be passed in as a vector of the diagonal elements </p> * @param a The left matrix in the multiplication operation. Not modified. * @param b The middle matrix in the multiplication operation. Not modified. Assumed to be diagonal. * @param c The right matrix in the multiplication operation. Not modified. * @param d Where the results of the operation are stored. Modified. * @param rowStart the start row to write to of the 'd' matrix. * @param colStart the start column to write to fo the 'd' matrix. */ public static void innerDiagonalMultAddBlockTransA(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d, int rowStart, int colStart) { if (a == c || b == c || c == d) throw new IllegalArgumentException("Neither 'a', 'b', or 'c' can be the same matrix as 'd'"); else if (a.numRows != b.numRows) throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); else if (a.numCols + rowStart > d.numRows || c.numCols + colStart > d.numCols) throw new MatrixDimensionException("The results matrix does not have the desired dimensions"); if (b.numCols > 1) innerDiagonalMultAddBlockTransA_matrix(a, b, c, d, rowStart, colStart); else innerDiagonalMultAddBlockTransA_vector(a, b, c, d, rowStart, colStart); }
/** * <p>Performs the following operation:<br> * <br> * d = d + a<sup>T</sup> * b * c * </br> * </p> * <p> where we assume that matrix 'b' is a diagonal matrix. </p> * <p> The 'b' matrix can also be passed in as a vector of the diagonal elements </p> * @param a The left matrix in the multiplication operation. Not modified. * @param b The middle matrix in the multiplication operation. Not modified. Assumed to be diagonal. * @param c The right matrix in the multiplication operation. Not modified. * @param d Where the results of the operation are stored. Modified. */ public static void innerDiagonalMultAddTransA(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, RowD1Matrix64F d) { if (a == c || b == c || c == d) throw new IllegalArgumentException("Neither 'a', 'b', or 'c' can be the same matrix as 'd'"); else if (a.numRows != b.numRows) throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); else if (a.numCols != d.numRows || c.numCols != d.numCols) throw new MatrixDimensionException("The results matrix does not have the desired dimensions"); if (b.numCols > 1) innerDiagonalMultAddTransA_matrix(a, b, c, d); else innerDiagonalMultAddTransA_vector(a, b, c, d); }