Quickly compute min or max of each row or column of a matrix.