[Numpy-svn] r8424 - in trunk/numpy/polynomial: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Fri May 21 01:36:13 EDT 2010


Author: charris
Date: 2010-05-21 00:36:13 -0500 (Fri, 21 May 2010)
New Revision: 8424

Modified:
   trunk/numpy/polynomial/polytemplate.py
   trunk/numpy/polynomial/tests/test_chebyshev.py
   trunk/numpy/polynomial/tests/test_polynomial.py
Log:
CHG: Change the default domain for the fit class method of the
Chebyshev and Polynomial classes to None. Add 'default' as a possible
value of the domain argument to specify the default domain. This change
fits better with my experience with this method. I feel it is safe to
make this change at this late date because the functions seem little
used as yet and I would like to get them 'right' before folks catch on
to their presence.

Modified: trunk/numpy/polynomial/polytemplate.py
===================================================================
--- trunk/numpy/polynomial/polytemplate.py	2010-05-21 05:36:10 UTC (rev 8423)
+++ trunk/numpy/polynomial/polytemplate.py	2010-05-21 05:36:13 UTC (rev 8424)
@@ -514,7 +514,7 @@
         return pu.mapdomain(roots, $domain, self.domain)
 
     @staticmethod
-    def fit(x, y, deg, domain=$domain, rcond=None, full=False) :
+    def fit(x, y, deg, domain=None, rcond=None, full=False) :
         """Least squares fit to data.
 
         Return a `$name` instance that is the least squares fit to the data
@@ -533,10 +533,11 @@
             passing in a 2D-array that contains one dataset per column.
         deg : int
             Degree of the fitting polynomial
-        domain : {None, [beg, end]}, optional
+        domain : {None, [beg, end], 'default'}, optional
             Domain to use for the returned $name instance. If ``None``,
-            then a minimal domain that covers the points `x` is chosen. The
-            default value is ``$domain``.
+            then a minimal domain that covers the points `x` is chosen.
+            If ``'default'`` the default domain ``$domain`` is used. The
+            default value is ``None``.
         rcond : float, optional
             Relative condition number of the fit. Singular values smaller
             than this relative to the largest singular value will be
@@ -568,6 +569,8 @@
         """
         if domain is None :
             domain = pu.getdomain(x)
+        elif domain == 'default' :
+            domain = $domain
         xnew = pu.mapdomain(x, domain, $domain)
         res = ${nick}fit(xnew, y, deg, rcond=None, full=full)
         if full :

Modified: trunk/numpy/polynomial/tests/test_chebyshev.py
===================================================================
--- trunk/numpy/polynomial/tests/test_chebyshev.py	2010-05-21 05:36:10 UTC (rev 8423)
+++ trunk/numpy/polynomial/tests/test_chebyshev.py	2010-05-21 05:36:13 UTC (rev 8424)
@@ -463,7 +463,13 @@
             return x*(x - 1)*(x - 2)
         x = np.linspace(0,3)
         y = f(x)
+
+        # test default value of domain
         p = ch.Chebyshev.fit(x, y, 3)
+        assert_almost_equal(p.domain, [0,3])
+
+        # test that fit works in given domains
+        p = ch.Chebyshev.fit(x, y, 3, 'default')
         assert_almost_equal(p(x), y)
         p = ch.Chebyshev.fit(x, y, 3, None)
         assert_almost_equal(p(x), y)

Modified: trunk/numpy/polynomial/tests/test_polynomial.py
===================================================================
--- trunk/numpy/polynomial/tests/test_polynomial.py	2010-05-21 05:36:10 UTC (rev 8423)
+++ trunk/numpy/polynomial/tests/test_polynomial.py	2010-05-21 05:36:13 UTC (rev 8424)
@@ -434,7 +434,13 @@
             return x*(x - 1)*(x - 2)
         x = np.linspace(0,3)
         y = f(x)
+
+        # test default value of domain
         p = poly.Polynomial.fit(x, y, 3)
+        assert_almost_equal(p.domain, [0,3])
+
+        # test that fit works in given domains
+        p = poly.Polynomial.fit(x, y, 3, 'default')
         assert_almost_equal(p(x), y)
         p = poly.Polynomial.fit(x, y, 3, None)
         assert_almost_equal(p(x), y)




More information about the Numpy-svn mailing list