# [Numpy-svn] r3339 - trunk/numpy/lib

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Oct 14 22:05:08 CDT 2006

```Author: charris
Date: 2006-10-14 22:05:06 -0500 (Sat, 14 Oct 2006)
New Revision: 3339

Modified:
trunk/numpy/lib/polynomial.py
Log:
Set rcond to precision of x as default.
Make error message more informative.

Modified: trunk/numpy/lib/polynomial.py
===================================================================
--- trunk/numpy/lib/polynomial.py	2006-10-14 21:34:16 UTC (rev 3338)
+++ trunk/numpy/lib/polynomial.py	2006-10-15 03:05:06 UTC (rev 3339)
@@ -11,11 +11,14 @@
import numpy.core.numeric as NX

from numpy.core import isscalar, abs
+from numpy.lib.machar import MachAr
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
+_single_eps = MachAr(NX.single).eps
+_double_eps = MachAr(NX.double).eps

def get_linalg_funcs():
"Look for linear algebra functions in numpy"
@@ -170,7 +173,7 @@
val = poly1d(val)
return val

-def polyfit(x, y, deg, rcond=-1):
+def polyfit(x, y, deg, rcond=None):
"""

Do a best fit polynomial of degree 'deg' of 'x' to 'y'.  Return value is a
@@ -241,6 +244,14 @@
if x.shape[0] != y.shape[0] :
raise TypeError, "expected x and y to have same length"

+    # set rcond
+    if rcond is None :
+        xtype = x.dtype
+        if xtype == NX.single or xtype == NX.csingle :
+            rcond = _single_eps
+        else :
+            rcond = _double_eps
+
# scale x to improve condition number
scale = abs(x).max()
if scale != 0 :
@@ -253,7 +264,7 @@
# warn on rank reduction, which indicates an ill conditioned matrix
if rank != order :
# fixme -- want a warning here, not an exception
-        raise RuntimeError, "degree reduced to %d" % (rank - 1)
+        raise RuntimeError, "Rank deficit fit. Try degree %d." % (rank - 1)

# scale returned coefficients
if scale != 0 :

```

More information about the Numpy-svn mailing list