See what you think of the following code, it computes the min or max over rows of a CSR matrix, using boolean indexing to minimize calculations. It may be possible to improve it by not considering rows with a single item, but I doubt there is much to improve there:

```
def row_minmax(csr_mat, minmax='min'):
    if minmax == 'min':
        ufunc = np.minimum
        compare = np.greater_equal
    elif minmax == 'max':
        ufunc = np.maximum
        compare = np.less_equal
    else:
        raise ValueError('not \'min\' or \'max\'')

    mask_indptr = np.diff(csr_mat.indptr) > 0 # rows not all zeros
    new_data = ufunc.reduceat(csr_mat.data,
                              csr_mat.indptr[mask_indptr]) # min (max) of non-zeros in rows not all zeros
    mask_data = compare(new_data, 0) # wrong entries in new_data, should be zero
    new_data = new_data[~mask_data] # remove them
    mask_indptr[mask_indptr] ^= mask_data # set to False those rows in mask_indptr
    return sps.csc_matrix((new_data,
                           np.nonzero(mask_indptr)[0],
                           [0, len(new_data)]), shape=(csr_mat.shape[0], 1))
```