Adds internal `dimlub()`; fix #4788

dimlub() computes least upper bound on a sparse matrix dimension given a
vector of indices. The vector may be empty.