scipy/scipy — pull request #3281 by argriffing (2014-02-04 20:49:58+00:00)
Title: MAINT: logm will be more like matlab for singular matrices

This PR addresses https://github.com/scipy/scipy/issues/3279 where someone uses MATLAB to find a `logm` of a complex matrix in a way that has small backward error so that `expm(logm(A))` gives something that is near `A`. When `A` is singular, the `logm` does not exist so it has infinite forward error, but it's possible to find an answer with small backward error. This is like returning `log(0) := -46` which has small backward error because `0 ~= exp(-46)`.

This PR modifies scipy `logm(A)` in a way that returns something other than a matrix of `nan`s when `A` is singular, while also giving a warning in that case. Although such an answer would have infinite forward error, it has a chance of having small backwards error.

I'm pasting some MATLAB R2012b output for singular real and complex matrices. The output is strange because it returns NaN for a real singular matrix, but it returns non-NaN (analogous to `-46` for `log(0)`)
for a complex singular matrix.

```
>> logm([0, 0; 1, 1])
Warning: At least one zero eigenvalue is detected in SCHUR(A).
Matrix A may be singular or badly scaled.
> In funm at 159
In logm at 25
Warning: Principal matrix logarithm is not defined for A with
nonpositive real eigenvalues. A non-principal matrix
logarithm is returned.
> In funm at 164
In logm at 25

ans =

NaN NaN
NaN NaN

>> logm([0, 0; j, j])

ans =

-37.4299 - 1.5708i -0.0000
37.4299 + 3.1416i 0.0000 + 1.5708i
```