BUG: optimize: return a matrix if indeterminate variance

The documentation says pcov is a matrix, so it may be confusing to have
it be a scalar in some pathological cases.