public static DMatrixRMaj copyTriangle ( DMatrixRMaj src , DMatrixRMaj dst , boolean upper ) { if ( dst == null ) { dst = new DMatrixRMaj ( src . numRows , src . numCols ) ; } else if ( src . numRows != dst . numRows || src . numCols != dst . numCols ) { throw new IllegalArgumentException ( "src and dst must have the same dimensions." ) ; } if ( upper ) { int N = Math . min ( src . numRows , src . numCols ) ; for ( int i = 0 ; i < N ; i ++ ) { int index = i * src . numCols + i ; System . arraycopy ( src . data , index , dst . data , index , src . numCols - i ) ; } } else { for ( int i = 0 ; i < src . numRows ; i ++ ) { int length = Math . min ( i + 1 , src . numCols ) ; int index = i * src . numCols ; System . arraycopy ( src . data , index , dst . data , index , length ) ; } } return dst ; }
Copies just the upper or lower triangular portion of a matrix .