[Numpy-svn] r8427 - in trunk: doc/release numpy/polynomial numpy/polynomial/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Sun May 23 18:02:08 EDT 2010


Author: charris
Date: 2010-05-23 17:02:08 -0500 (Sun, 23 May 2010)
New Revision: 8427

Modified:
   trunk/doc/release/2.0.0-notes.rst
   trunk/numpy/polynomial/polytemplate.py
   trunk/numpy/polynomial/tests/test_chebyshev.py
   trunk/numpy/polynomial/tests/test_polynomial.py
Log:
REV: Revert the changes to the truncate method of Polynomial and Chebyshev.
On second thought it was a bad idea to make such a radical change to existing
behaviour. It was also hard to document the variations ;)

Modified: trunk/doc/release/2.0.0-notes.rst
===================================================================
--- trunk/doc/release/2.0.0-notes.rst	2010-05-21 05:36:18 UTC (rev 8426)
+++ trunk/doc/release/2.0.0-notes.rst	2010-05-23 22:02:08 UTC (rev 8427)
@@ -77,9 +77,6 @@
   derivations is a non-negative integer. The number 0 is a valid value for both
   functions.
 * A degree method has been added to the Polynomial class.
-* The truncate method of the Polynomial class now takes the degree of the
-  desired result as an argument instead of the number of coefficients. This
-  seems more natural.
 * The fit class function of the Polynomial class now uses None as the default
   domain for the fit. The domain can be specified as 'default' to use the
   Polynomial default domain [-1, 1].
@@ -91,9 +88,6 @@
   derivations is a non-negative integer. The number 0 is a valid value for both
   functions.
 * A degree method has been added to the Chebyshev class.
-* The truncate method of the Chebyshev class now takes the degree of the
-  desired result as an argument instead of the number of coefficients. This
-  seems more natural.
 * The fit class function of the Chebyshev class now uses None as the default
   domain for the fit. The domain can be specified as 'default' to use the
   Chebyshev default domain [-1, 1].

Modified: trunk/numpy/polynomial/polytemplate.py
===================================================================
--- trunk/numpy/polynomial/polytemplate.py	2010-05-21 05:36:18 UTC (rev 8426)
+++ trunk/numpy/polynomial/polytemplate.py	2010-05-23 22:02:08 UTC (rev 8427)
@@ -391,20 +391,19 @@
         """
         return self.__class__(pu.trimcoef(self.coef, tol), self.domain)
 
-    def truncate(self, deg) :
-        """Truncate series to degree `deg`.
+    def truncate(self, size) :
+        """Truncate series to length `size`.
 
-        Return a $name series obtained from the current instance by discarding
-        all terms of degree greater than `deg`.  The value of `deg` must be
-        non-negative. This operation is most likely to be useful in least squares
-        fits when the high order coefficients are very small.
+        Reduce the $name series to length `size` by discarding the high
+        degree terms. The value of `size` must be a positive integer. This
+        can be useful in least squares where the coefficients of the
+        high degree terms may be very small.
 
         Parameters:
         -----------
-        deg : non-negative int
-            The series is reduced to degree `deg` by discarding the
-            coefficients of the higher degree terms. The value of `deg`
-            must be non-negative.
+        size : positive int
+            The series is reduced to length `size` by discarding the high
+            degree terms. The value of `size` must be a positive integer.
 
         Returns:
         -------
@@ -412,13 +411,13 @@
             New instance of $name with truncated coefficients.
 
         """
-        size = int(deg) + 1
-        if size != deg + 1 or size < 1 :
-            raise ValueError("deg must be a non-negative integer")
-        if size  >= len(self) :
+        isize = int(size)
+        if isize != size or isize < 1 :
+            raise ValueError("size must be a positive integer")
+        if isize >= len(self.coef) :
             return self.__class__(self.coef, self.domain)
         else :
-            return self.__class__(self.coef[:size], self.domain)
+            return self.__class__(self.coef[:isize], self.domain)
 
     def copy(self) :
         """Return a copy.
@@ -442,7 +441,7 @@
 
         Parameters:
         -----------
-        m : non-negative integer
+        m : non-negative int
             The number of integrations to perform.
         k : array_like
             Integration constants. The first constant is applied to the
@@ -455,7 +454,7 @@
         Returns:
         --------
         integral : $name
-            The integral of the original series with the same domain.
+            The integral of the series using the same domain.
 
         See Also
         --------
@@ -479,13 +478,13 @@
 
         Parameters:
         -----------
-        m : non-negative integer
+        m : non-negative int
             The number of integrations to perform.
 
         Returns:
         --------
         derivative : $name
-            The derivative of the original series with the same domain.
+            The derivative of the series using the same domain.
 
         See Also
         --------

Modified: trunk/numpy/polynomial/tests/test_chebyshev.py
===================================================================
--- trunk/numpy/polynomial/tests/test_chebyshev.py	2010-05-21 05:36:18 UTC (rev 8426)
+++ trunk/numpy/polynomial/tests/test_chebyshev.py	2010-05-23 22:02:08 UTC (rev 8427)
@@ -420,11 +420,11 @@
 
     def test_truncate(self) :
         assert_raises(ValueError, self.p1.truncate, .5)
-        assert_raises(ValueError, self.p1.truncate, -1)
+        assert_raises(ValueError, self.p1.truncate, 0)
+        assert_equal(len(self.p1.truncate(4)), 3)
         assert_equal(len(self.p1.truncate(3)), 3)
-        assert_equal(len(self.p1.truncate(2)), 3)
-        assert_equal(len(self.p1.truncate(1)), 2)
-        assert_equal(len(self.p1.truncate(0)), 1)
+        assert_equal(len(self.p1.truncate(2)), 2)
+        assert_equal(len(self.p1.truncate(1)), 1)
 
     def test_copy(self) :
         p = self.p1.copy()

Modified: trunk/numpy/polynomial/tests/test_polynomial.py
===================================================================
--- trunk/numpy/polynomial/tests/test_polynomial.py	2010-05-21 05:36:18 UTC (rev 8426)
+++ trunk/numpy/polynomial/tests/test_polynomial.py	2010-05-23 22:02:08 UTC (rev 8427)
@@ -391,11 +391,11 @@
 
     def test_truncate(self) :
         assert_raises(ValueError, self.p1.truncate, .5)
-        assert_raises(ValueError, self.p1.truncate, -1)
+        assert_raises(ValueError, self.p1.truncate, 0)
+        assert_equal(len(self.p1.truncate(4)), 3)
         assert_equal(len(self.p1.truncate(3)), 3)
-        assert_equal(len(self.p1.truncate(2)), 3)
-        assert_equal(len(self.p1.truncate(1)), 2)
-        assert_equal(len(self.p1.truncate(0)), 1)
+        assert_equal(len(self.p1.truncate(2)), 2)
+        assert_equal(len(self.p1.truncate(1)), 1)
 
     def test_copy(self) :
         p = self.p1.copy()




More information about the Numpy-svn mailing list