public static void checkSvdMatrixSize ( DMatrixRMaj U , boolean tranU , DMatrixRMaj W , DMatrixRMaj V , boolean tranV ) { int numSingular = Math . min ( W . numRows , W . numCols ) ; boolean compact = W . numRows == W . numCols ; if ( compact ) { if ( U != null ) { if ( tranU && U . numRows != numSingular ) throw new IllegalArgumentException ( "Unexpected size of matrix U" ) ; else if ( ! tranU && U . numCols != numSingular ) throw new IllegalArgumentException ( "Unexpected size of matrix U" ) ; } if ( V != null ) { if ( tranV && V . numRows != numSingular ) throw new IllegalArgumentException ( "Unexpected size of matrix V" ) ; else if ( ! tranV && V . numCols != numSingular ) throw new IllegalArgumentException ( "Unexpected size of matrix V" ) ; } } else { if ( U != null && U . numRows != U . numCols ) throw new IllegalArgumentException ( "Unexpected size of matrix U" ) ; if ( V != null && V . numRows != V . numCols ) throw new IllegalArgumentException ( "Unexpected size of matrix V" ) ; if ( U != null && U . numRows != W . numRows ) throw new IllegalArgumentException ( "Unexpected size of W" ) ; if ( V != null && V . numRows != W . numCols ) throw new IllegalArgumentException ( "Unexpected size of W" ) ; } }
Checks to see if all the provided matrices are the expected size for an SVD . If an error is encountered then an exception is thrown . This automatically handles compact and non - compact formats