scipy/scipy — pull request #289 by jakevdp (2012-08-16 16:44:20+00:00)
Title: Pinv enhancements

This is a PR based on some of @vene's work in scikit-learn: see https://github.com/scikit-learn/scikit-learn/pull/1015

There are two enhanvements:

- `scipy.linalg.pinv2` is sped up by only computing necessary singular values, and not allocating the entire `psigma` matrix

- `scipy.linalg.pinvh` added: this uses `eigh` to significantly speed up the pseudo-inverse computation in the symmetric/hermitian case

Here are some simple benchmarks:

**old pinv2 vs new pinv2**

old version:
```
In [1]: import numpy as np
In [2]: from scipy.linalg import pinv2
In [3]: np.random.seed(0)
In [4]: X = np.random.random((500, 100))
In [5]: %timeit pinv2(X)
10 loops, best of 3: 172 ms per loop
```

new version:
```
...
In [5]: %timeit pinv2(X)
10 loops, best of 3: 38.1 ms per loop
```

**pinvh vs new pinv2:**

```
In [1]: import numpy as np
In [2]: from scipy.linalg import pinv2, pinvh
In [3]: np.random.seed(0)
In [4]: X = np.random.random((500, 400))
In [5]: X = np.dot(X, X.T) # make symmetric positive semi-definite
In [6]: %timeit pinv2(X)
1 loops, best of 3: 736 ms per loop
In [7]: %timeit pinvh(X)
1 loops, best of 3: 320 ms per loop
```