Skip to content

Commit

Permalink
Fix up so that scipy.linalg.pinv2 is selected for numpy.dual (it uses…
Browse files Browse the repository at this point in the history
… SVD like numpy.dual does).
  • Loading branch information
teoliphant committed Dec 7, 2006
1 parent a59190e commit 08b4d98
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
8 changes: 7 additions & 1 deletion Lib/linalg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@

from numpy.dual import register_func
for k in ['norm', 'inv', 'svd', 'solve', 'det', 'eig', 'eigh', 'eigvals',
'eigvalsh', 'lstsq', 'pinv', 'cholesky']:
'eigvalsh', 'lstsq', 'cholesky']:
try:
register_func(k, eval(k))
except ValueError:
pass

try:
register_func('pinv', pinv2)
except ValueError:
pass

del k, register_func

from numpy.testing import ScipyTest
Expand Down
12 changes: 8 additions & 4 deletions Lib/linalg/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,28 +370,32 @@ def lstsq(a, b, cond=None, overwrite_a=0, overwrite_b=0):
return x,resids,rank,s


def pinv(a, cond=None):
""" pinv(a, cond=None) -> a_pinv
def pinv(a, cond=None, rcond=None):
""" pinv(a, rcond=None) -> a_pinv
Compute generalized inverse of A using least-squares solver.
"""
a = asarray_chkfinite(a)
b = numpy.identity(a.shape[0], dtype=a.dtype)
if rcond is not None:
cond = rcond
return lstsq(a, b, cond=cond)[0]


eps = numpy.finfo(float).eps
feps = numpy.finfo(single).eps

_array_precision = {'f': 0, 'd': 1, 'F': 0, 'D': 1}
def pinv2(a, cond=None):
""" pinv2(a, cond=None) -> a_pinv
def pinv2(a, cond=None, rcond=None):
""" pinv2(a, rcond=None) -> a_pinv
Compute the generalized inverse of A using svd.
"""
a = asarray_chkfinite(a)
u, s, vh = decomp.svd(a)
t = u.dtype.char
if rcond is not None:
cond = rcond
if cond in [None,-1]:
cond = {0: feps*1e3, 1: eps*1e6}[_array_precision[t]]
m,n = a.shape
Expand Down
4 changes: 2 additions & 2 deletions Lib/sandbox/xplt/Mplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
numpy = Numeric
from numpy import ravel, reshape, repeat, arange, transpose, compress, \
where, ones, newaxis, asarray
import numpy.lib.mlab as MLab
from numpy.lib.mlab import pi, cos, sin, arctan2, array, angle
import numpy.oldnumeric.mlab as MLab
from numpy.oldnumeric.mlab import pi, cos, sin, arctan2, array, angle
import types
import write_style
points = 0.0013000
Expand Down
2 changes: 1 addition & 1 deletion Lib/signal/signaltools.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def wiener(im,mysize=None,noise=None):


def convolve2d(in1, in2, mode='full', boundary='fill', fillvalue=0):
"""Conolve two 2-dimensional arrays.
"""Convolve two 2-dimensional arrays.
Description:
Expand Down
4 changes: 2 additions & 2 deletions Lib/signal/sigtoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ static PyObject *sigtools_convolve2d(PyObject *dummy, PyObject *args) {

PyObject *in1=NULL, *in2=NULL, *fill_value=NULL;
int mode=2, boundary=0, typenum, flag, flip=1, ret;
intp *aout_dimens, *dims=NULL;
intp *aout_dimens=NULL, *dims=NULL;
char zeros[32]; /* Zeros */
int n1, n2, i;
PyArrayObject *ain1=NULL, *ain2=NULL, *aout=NULL;
Expand Down Expand Up @@ -1804,7 +1804,6 @@ static PyObject *sigtools_convolve2d(PyObject *dummy, PyObject *args) {
}

aout = (PyArrayObject *)PyArray_SimpleNew(ain1->nd, aout_dimens, typenum);
free(aout_dimens);
if (aout == NULL) goto fail;

flag = mode + boundary + (typenum << TYPE_SHIFT) + \
Expand Down Expand Up @@ -1849,6 +1848,7 @@ static PyObject *sigtools_convolve2d(PyObject *dummy, PyObject *args) {
}

fail:
free(aout_dimens);
Py_XDECREF(ain1);
Py_XDECREF(ain2);
Py_XDECREF(aout);
Expand Down
4 changes: 2 additions & 2 deletions Lib/stats/continuous.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -2931,8 +2931,8 @@ G\left(q;a\right) & = & \left\{ \Gamma^{-1}\left[a,\Gamma\left(a\right)q\right]\


\begin_inset Formula \begin{eqnarray*}
\mu & = & \frac{1}{a-1}\\
\mu_{2} & = & \frac{1}{\left(a-2\right)\left(a-1\right)}-\mu^{2}\\
\mu & = & \frac{1}{a-1}\quad a>1\\
\mu_{2} & = & \frac{1}{\left(a-2\right)\left(a-1\right)}-\mu^{2}\quad a>2\\
\gamma_{1} & = & \frac{\frac{1}{\left(a-3\right)\left(a-2\right)\left(a-1\right)}-3\mu\mu_{2}-\mu^{3}}{\mu_{2}^{3/2}}\\
\gamma_{2} & = & \frac{\frac{1}{\left(a-4\right)\left(a-3\right)\left(a-2\right)\left(a-1\right)}-4\mu\mu_{3}-6\mu^{2}\mu_{2}-\mu^{4}}{\mu_{2}^{2}}-3\end{eqnarray*}

Expand Down

0 comments on commit 08b4d98

Please sign in to comment.