Optimize pinv for diagonal matrices

In general, the pseudoinverse is determined to only half of the machine
precision for general dense ill-conditioned matrices. For diagonal and
certain other matrices (e.g., tridiagonal matrices), the pseudoinverse
can be determined more accurately. We try to detect if the matrix is
diagonal immediately after the call to pinv and invert the diagonal elements
only whithout invoking ths svdfact function which is both faster and
more accurate.

Since the default threshold can not be determined in advance for arbitrary
matrices, provide a user-selectable parameter tol and provide a simple
scheme for automatic threshold selection.

pinv(A) sets the threshold tol to eps(one(T))*maximum(size(A)).

pinv(A,tol) sets the user-selectable threshold tol.

pinv(A,0) attempts to determine the threshold tol by forming two pseudoinverses
for tol=eps(one(T))*maximum(size(A)) and tol=sqrt(eps(one(T)) and estimating
the error in the first Moore-Penrose relation a*pinv(a)*a = a. This can be done
with very little overhead (since svdvals is an expensive call) while using
about twice as much intermediate memory.

Add pinv method for Diagonal type.

Check and fix zero and sub-normal matrices.
Merge pull request #9008 from zgimbutas/optimize-pinv

Optimize pinv for diagonal matrices