/** * Computes the product of the diagonal elements. For a diagonal or triangular * matrix this is the determinant. * * @param T A matrix. * @return product of the diagonal elements. */ public static double diagProd( RowD1Matrix64F T ) { double prod = 1.0; int N = Math.min(T.numRows,T.numCols); for( int i = 0; i < N; i++ ) { prod *= T.unsafe_get(i,i); } return prod; }
private static void preMultAddBlock_vector(double d, D1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, int startRow, int startCol) { for (int row = 0; row < Math.min(a.numRows, b.numRows); row++) { for (int col = 0; col < b.numCols; col++) { c.unsafe_set(startRow + row, startCol + col, c.unsafe_get(startRow + row, startCol + col) + d * a.data[row] * b.unsafe_get(row, col)); } } }
/** * Computes the product of the diagonal elements. For a diagonal or triangular * matrix this is the determinant. * * @param T A matrix. * @return product of the diagonal elements. */ public static double diagProd( RowD1Matrix64F T ) { double prod = 1.0; int N = Math.min(T.numRows,T.numCols); for( int i = 0; i < N; i++ ) { prod *= T.unsafe_get(i,i); } return prod; }
/** * Computes the product of the diagonal elements. For a diagonal or triangular * matrix this is the determinant. * * @param T A matrix. * @return product of the diagonal elements. */ public static double diagProd( RowD1Matrix64F T ) { double prod = 1.0; int N = Math.min(T.numRows,T.numCols); for( int i = 0; i < N; i++ ) { prod *= T.unsafe_get(i,i); } return prod; }
private static void preMultAddBlock_vector(D1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, int startRow, int startCol) { for (int row = 0; row < Math.min(a.numRows, b.numRows); row++) { for (int col = 0; col < b.numCols; col++) { c.unsafe_set(startRow + row, startCol + col, c.unsafe_get(startRow + row, startCol + col) + a.data[row] * b.unsafe_get(row, col)); } } }
private static void preMultAddBlock_matrix(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, int startRow, int startCol) { if (a.numCols != b.numRows) throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); for (int row = 0; row < Math.min(a.numRows, a.numCols); row++) { for (int col = 0; col < b.numCols; col++) { c.unsafe_set(startRow + row, startCol + col, c.unsafe_get(startRow + row, startCol + col) + a.unsafe_get(row, row) * b.unsafe_get(row, col)); } } }
private static void preMultAddBlock_matrix(double d, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c, int startRow, int startCol) { if (a.numCols != b.numRows) throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); for (int row = 0; row < Math.min(a.numRows, a.numCols); row++) { for (int col = 0; col < b.numCols; col++) { c.unsafe_set(startRow + row, startCol + col, c.unsafe_get(startRow + row, startCol + col) + d * a.unsafe_get(row, row) * b.unsafe_get(row, col)); } } }
private static void preMult_vector(D1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c) { for (int row = 0; row < Math.min(a.numRows, b.numRows); row++) { for (int col = 0; col < b.numCols; col++) { c.unsafe_set(row, col, a.data[row] * b.unsafe_get(row, col)); } } }
private static void preMult_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"); for (int row = 0; row < Math.min(a.numRows, a.numCols); row++) { for (int col = 0; col < b.numCols; col++) { c.unsafe_set(row, col, a.unsafe_get(row, row) * b.unsafe_get(row, col)); } } }
private static void postMult_vector(RowD1Matrix64F a, D1Matrix64F b, RowD1Matrix64F c) { for (int row = 0; row < a.numRows; row++) { for (int col = 0; col < Math.min(b.numRows, c.numCols); col++) { c.unsafe_set(row, col, b.data[col] * a.unsafe_get(row, col)); } } }
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)); } } }
public static void scaleInputDiag(final RowD1Matrix64F matrix, final RowD1Matrix64F diag) { for (int i = 0; i < matrix.numRows; i++) { matrix.unsafe_set(i, i, matrix.unsafe_get(i, i) + 1 / diag.get(i)); } }
/** * @see org.ejml.ops.CommonOps#multTransAB( org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F) */ public static void multTransAB_aux( RowD1Matrix64F a , RowD1Matrix64F b , RowD1Matrix64F c , double []aux ) { if( a == c || b == c ) 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"); } if( aux == null ) aux = new double[ a.numRows ]; int indexC = 0; for( int i = 0; i < a.numCols; i++ ) { for( int k = 0; k < b.numCols; k++ ) { aux[k] = a.unsafe_get(k,i); } for( int j = 0; j < b.numRows; j++ ) { double total = 0; for( int k = 0; k < b.numCols; k++ ) { total += aux[k] * b.unsafe_get(j,k); } c.set( indexC++ , total ); } } }
/** * @see org.ejml.ops.CommonOps#multAddTransAB( org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F) */ public static void multAddTransAB_aux( RowD1Matrix64F a , RowD1Matrix64F b , RowD1Matrix64F c , double []aux ) { if( a == c || b == c ) 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"); } if( aux == null ) aux = new double[ a.numRows ]; int indexC = 0; for( int i = 0; i < a.numCols; i++ ) { for( int k = 0; k < b.numCols; k++ ) { aux[k] = a.unsafe_get(k,i); } for( int j = 0; j < b.numRows; j++ ) { double total = 0; for( int k = 0; k < b.numCols; k++ ) { total += aux[k] * b.unsafe_get(j,k); } c.plus( indexC++ , total ); } } }
/** * @see org.ejml.ops.CommonOps#multTransAB(double, org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F) */ public static void multTransAB_aux( double alpha , RowD1Matrix64F a , RowD1Matrix64F b , RowD1Matrix64F c , double []aux ) { if( a == c || b == c ) 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"); } if( aux == null ) aux = new double[ a.numRows ]; int indexC = 0; for( int i = 0; i < a.numCols; i++ ) { for( int k = 0; k < b.numCols; k++ ) { aux[k] = a.unsafe_get(k,i); } for( int j = 0; j < b.numRows; j++ ) { double total = 0; for( int k = 0; k < b.numCols; k++ ) { total += aux[k] * b.unsafe_get(j,k); } c.set( indexC++ , alpha*total ); } } }
/** * @see org.ejml.ops.CommonOps#multAddTransAB(double, org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F) */ public static void multAddTransAB_aux( double alpha , RowD1Matrix64F a , RowD1Matrix64F b , RowD1Matrix64F c , double []aux ) { if( a == c || b == c ) 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"); } if( aux == null ) aux = new double[ a.numRows ]; int indexC = 0; for( int i = 0; i < a.numCols; i++ ) { for( int k = 0; k < b.numCols; k++ ) { aux[k] = a.unsafe_get(k,i); } for( int j = 0; j < b.numRows; j++ ) { double total = 0; for( int k = 0; k < b.numCols; k++ ) { total += aux[k] * b.unsafe_get(j,k); } c.plus( indexC++ , alpha*total ); } } }
for( int i = 0; i < a.numCols; i++ ) { for( int k = 0; k < b.numCols; k++ ) { aux[k] = a.unsafe_get(k,i); total += aux[k] * b.unsafe_get(j,k);
for( int i = 0; i < a.numCols; i++ ) { for( int k = 0; k < b.numCols; k++ ) { aux[k] = a.unsafe_get(k,i); total += aux[k] * b.unsafe_get(j,k);
/** * @see org.ejml.ops.CommonOps#multAdd( org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F, org.ejml.data.RowD1Matrix64F) */ public static void multAdd_aux( RowD1Matrix64F a , RowD1Matrix64F b , RowD1Matrix64F c , double []aux ) { if( a == c || b == c ) throw new IllegalArgumentException("Neither 'a' or 'b' can be the same matrix as 'c'"); else if( a.numCols != b.numRows ) { throw new MatrixDimensionException("The 'a' and 'b' matrices do not have compatible dimensions"); } else if( a.numRows != c.numRows || b.numCols != c.numCols ) { throw new MatrixDimensionException("The results matrix does not have the desired dimensions"); } if( aux == null ) aux = new double[ b.numRows ]; for( int j = 0; j < b.numCols; j++ ) { // create a copy of the column in B to avoid cache issues for( int k = 0; k < b.numRows; k++ ) { aux[k] = b.unsafe_get(k,j); } int indexA = 0; for( int i = 0; i < a.numRows; i++ ) { double total = 0; for( int k = 0; k < b.numRows; ) { total += a.get(indexA++)*aux[k++]; } c.plus( i*c.numCols+j , total ); } } }
/** * Finds the inverse of a diagonal matrix * @param matrixToInvertAndPack matrix to compute inverse of */ public static void invertDiagonalMatrix(RowD1Matrix64F matrixToInvertAndPack) { if (matrixToInvertAndPack.numRows != matrixToInvertAndPack.numCols) { throw new MatrixDimensionException( "Diagonal matrix to invert is not square. Number of rows in matrix: " + matrixToInvertAndPack.getNumRows() + ", number of" + " cols in matrix: " + matrixToInvertAndPack.getNumCols() + "."); } int size = matrixToInvertAndPack.getNumRows(); for (int index = 0; index < size; index++) matrixToInvertAndPack.unsafe_set(index, index, 1.0 / matrixToInvertAndPack.unsafe_get(index, index)); }