code: private static Matrix permuteMatrix(Matrix mat, int cpRows, int cpCols) {
  		//fix up cp to be positive
  		if(cpRows == 0 && cpCols == 0) {
  			return mat.copy();
  		}
  		if(cpRows < 0) {
  			cpRows = mat.getRowDimension()+cpRows;
  		}
  		if(cpRows < 0 || cpRows >= mat.getRowDimension()) {
  			throw new ArrayIndexOutOfBoundsException( String.format(
  					"Can't permute rows by %d: only %d rows.",
  					cpRows, mat.getRowDimension() )
  			);
  		}
  
  		if(cpCols < 0) {
  			cpCols = mat.getColumnDimension()+cpCols;
  		}
  		if(cpCols < 0 || cpCols >= mat.getColumnDimension()) {
  			throw new ArrayIndexOutOfBoundsException( String.format(
  					"Can't permute cols by %d: only %d rows.",
  					cpCols, mat.getColumnDimension() )
  			);
  		}
  
  		int[] rows = new int[mat.getRowDimension()];
  		for(int i=0;i<rows.length;i++) {
  			rows[i] = (i+cpRows)%rows.length;
  		}
  		int[] cols = new int[mat.getColumnDimension()];
  		for(int i=0;i<cols.length;i++) {
  			cols[i] = (i+cpCols)%cols.length;
  		}
  
  		Matrix newMat = mat.getMatrix(rows, cols);
  		assert(newMat.getRowDimension() == mat.getRowDimension());
  		assert(newMat.getColumnDimension() == mat.getColumnDimension());
  		assert(newMat.get(0, 0) ==
  			mat.get(cpRows%mat.getRowDimension(), cpCols%mat.getColumnDimension()));
  
  
  		return newMat;
  	}
docs: Permutes <i>mat</i> by moving the rows of the matrix upwards by <i>cp</i>
  rows.
  @param mat The original matrix
  @param cpRows Number of rows upward to move entries
  @param cpCols Number of columns leftward to move entries
  @return The permuted matrix