[SciPy-Dev] Proposal to merge linalg.pinv and linalg.pinv2 and deprecate pinv2

Ilhan Polat ilhanpolat at gmail.com
Sat Apr 10 11:42:24 EDT 2021


Thanks Stefan, this proves that it dates back to matlab pre6.5 days, for
some reason I vaguely remember using pinv2 on some non-python tool but
couldn't find anything online.

I attempted to fix the atol/rtol issue that apparently caused some
difficulties in over scikit-learn for quite some timesee [1], [2] reported
by @ogrisel and then deprecated pinv2. The PR is here
https://github.com/scipy/scipy/pull/13831

Feedback always welcome







[1] : https://github.com/scipy/scipy/issues/13704
[2] : https://github.com/scikit-learn/scikit-learn/pull/19646



On Mon, Mar 22, 2021 at 9:33 PM Stefan van der Walt <stefanv at berkeley.edu>
wrote:

> On Sun, Mar 21, 2021, at 16:17, Robert Kern wrote:
>
> On Sun, Mar 21, 2021 at 6:53 PM Robert Kern <robert.kern at gmail.com> wrote:
>
> On Sun, Mar 21, 2021 at 6:00 PM Ralf Gommers <ralf.gommers at gmail.com>
> wrote:
>
>
> Do you happen to know the history of how we ended up with pinv2?
>
>
> I suspect that when `pinv2()` was added, the `lstsq()` call underlying
> `pinv()` was not SVD-based. The precise LAPACK driver has changed over the
> years. We might have started with the QR-based driver.
>
>
> It's going to be very hard to tell definitively because I think the
> history got lost in the SVN->git conversion due to some directory renames
> that happened in the early days. The pinv/pinv2 split seems to have been
> very early, though, so it may have dated from the original Multipack
> library (the source tarballs of which are also linkrotted away).
>
>
> I think you're right, this was pre-SVN.  I was looking at the following
> commit from https://github.com/scipy/scipy-svn
>
> commit c6ef539392f31bda0b56541a1c8fdd61a0c0e6eb (HEAD)
> Author: pearu <pearu at d6536bca-fef9-0310-8506-e4c0a848fbcf>
> Date:   Sun Apr 7 15:03:50 2002 +0000
>
>     Replacing linalg with linalg2: linalg->linalg/linalg1 and
> linalg2->linalg
>
>
> There, the linalg/basic.py file is added, and inside it both pinv and
> pinv2 already exist:
>
> def pinv(a, cond=-1):
>     """Compute generalized inverse of A using least-squares solver.
>     """
>     a = asarray(a)
>     t = a.typecode()
>     b = scipy.identity(a.shape[0],t)
>     return lstsq(a, b, cond=cond)[0]
>
> def pinv2(a, cond=-1):
>     """Compute the generalized inverse of A using svd.
>     """
>     a = asarray(a)
>     u, s, vh = decomp.svd(a)
>     m = u.shape[1]
>     n = vh.shape[0]
>     t = u.typecode()
>     if cond is -1 or cond is None:
>         cond = {0: feps*1e3, 1: eps*1e6}[_array_precision[t]]
>     cutoff = cond*scipy_base.maximum.reduce(s)
>     for i in range(min(n,m)):
>         if s[i] > cutoff:
>             s[i] = 1.0/s[i]
>         else:
>             s[i] = 0.0
>     return dot(tran(conj(vh)),tran(conj(u))*s[:,NewAxis])
>
>
> I have not been able to find a copy of multipack-0.7.tar.gz
>
> Stéfan
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/scipy-dev/attachments/20210410/f17c6d97/attachment-0001.html>


More information about the SciPy-Dev mailing list