summaryrefslogtreecommitdiff
path: root/numpy/lib/polynomial.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2006-10-15 03:05:06 +0000
committerCharles Harris <charlesr.harris@gmail.com>2006-10-15 03:05:06 +0000
commit658b94aa185b341ddf638ec488ac5acd8cdf28fa (patch)
tree8f0af527de03270c39a48d582d2d2cc7c8cafa8e /numpy/lib/polynomial.py
parent62e610eac5302aa3c1f6c1715c5d3be745caedaa (diff)
downloadnumpy-658b94aa185b341ddf638ec488ac5acd8cdf28fa.tar.gz
Set rcond to precision of x as default.
Make error message more informative.
Diffstat (limited to 'numpy/lib/polynomial.py')
-rw-r--r--numpy/lib/polynomial.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py
index 18250700b..fa165dda1 100644
--- a/numpy/lib/polynomial.py
+++ b/numpy/lib/polynomial.py
@@ -11,11 +11,14 @@ import warnings
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 @@ def polyder(p, m=1):
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 @@ def polyfit(x, y, deg, rcond=-1):
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 @@ def polyfit(x, y, deg, rcond=-1):
# 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 :