diff options
author | Pauli Virtanen <pav@iki.fi> | 2008-12-13 16:18:04 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2008-12-13 16:18:04 +0000 |
commit | f947ff3bf90038bc0b37bc9b6a95138a0cf5e47a (patch) | |
tree | 21b7e635180e6e79688a2740535a1ebc01259e6f | |
parent | 57c9ad3baa68a11aa8cfd272e4ccbb9002526cf1 (diff) | |
download | numpy-f947ff3bf90038bc0b37bc9b6a95138a0cf5e47a.tar.gz |
Get lstsq and eigvals from numpy.linalg, not from numpy.dual. Addresses Scipy ticket #800
-rw-r--r-- | numpy/lib/polynomial.py | 31 | ||||
-rw-r--r-- | numpy/ma/extras.py | 4 |
2 files changed, 6 insertions, 29 deletions
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index 4a70c9fa3..504a1271f 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -15,36 +15,13 @@ from numpy.lib.getlimits import finfo from numpy.lib.twodim_base import diag, vander from numpy.lib.shape_base import hstack, atleast_1d from numpy.lib.function_base import trim_zeros, sort_complex -eigvals = None -lstsq = None +from numpy.linalg import eigvals, lstsq class RankWarning(UserWarning): """Issued by polyfit when Vandermonde matrix is rank deficient. """ pass -def get_linalg_funcs(): - "Look for linear algebra functions in numpy" - global eigvals, lstsq - from numpy.dual import eigvals, lstsq - return - -def _eigvals(arg): - "Return the eigenvalues of the argument" - try: - return eigvals(arg) - except TypeError: - get_linalg_funcs() - return eigvals(arg) - -def _lstsq(X, y, rcond): - "Do least squares on the arguments" - try: - return lstsq(X, y, rcond) - except TypeError: - get_linalg_funcs() - return lstsq(X, y, rcond) - def poly(seq_of_zeros): """ Return polynomial coefficients given a sequence of roots. @@ -94,7 +71,7 @@ def poly(seq_of_zeros): seq_of_zeros = atleast_1d(seq_of_zeros) sh = seq_of_zeros.shape if len(sh) == 2 and sh[0] == sh[1]: - seq_of_zeros = _eigvals(seq_of_zeros) + seq_of_zeros = eigvals(seq_of_zeros) elif len(sh) ==1: pass else: @@ -177,7 +154,7 @@ def roots(p): # build companion matrix and find its eigenvalues (the roots) A = diag(NX.ones((N-2,), p.dtype), -1) A[0, :] = -p[1:] / p[0] - roots = _eigvals(A) + roots = eigvals(A) else: roots = NX.array([]) @@ -500,7 +477,7 @@ def polyfit(x, y, deg, rcond=None, full=False): # solve least squares equation for powers of x v = vander(x, order) - c, resids, rank, s = _lstsq(v, y, rcond) + c, resids, rank, s = lstsq(v, y, rcond) # warn on rank reduction, which indicates an ill conditioned matrix if rank != order and not full: diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 843dfd431..cf80180e4 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -40,7 +40,7 @@ import numpy as np from numpy import ndarray, array as nxarray import numpy.core.umath as umath from numpy.lib.index_tricks import AxisConcatenator -from numpy.lib.polynomial import _lstsq +from numpy.linalg import lstsq #............................................................................... def issequence(seq): @@ -1033,7 +1033,7 @@ def polyfit(x, y, deg, rcond=None, full=False): x = x / scale # solve least squares equation for powers of x v = vander(x, order) - c, resids, rank, s = _lstsq(v, y.filled(0), rcond) + c, resids, rank, s = lstsq(v, y.filled(0), rcond) # warn on rank reduction, which indicates an ill conditioned matrix if rank != order and not full: warnings.warn("Polyfit may be poorly conditioned", np.RankWarning) |