diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/polynomial/polytemplate.py | 37 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_chebyshev.py | 8 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_polynomial.py | 8 |
3 files changed, 26 insertions, 27 deletions
diff --git a/numpy/polynomial/polytemplate.py b/numpy/polynomial/polytemplate.py index 08510c1ff..bf94d28ec 100644 --- a/numpy/polynomial/polytemplate.py +++ b/numpy/polynomial/polytemplate.py @@ -391,20 +391,19 @@ class $name(pu.PolyBase) : """ 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 @@ class $name(pu.PolyBase) : 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 @@ class $name(pu.PolyBase) : 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 @@ class $name(pu.PolyBase) : 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 @@ class $name(pu.PolyBase) : 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 -------- diff --git a/numpy/polynomial/tests/test_chebyshev.py b/numpy/polynomial/tests/test_chebyshev.py index 2278ca871..d61e8b07c 100644 --- a/numpy/polynomial/tests/test_chebyshev.py +++ b/numpy/polynomial/tests/test_chebyshev.py @@ -420,11 +420,11 @@ class TestChebyshevClass(TestCase) : 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() diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py index 13718fe9e..530e5d949 100644 --- a/numpy/polynomial/tests/test_polynomial.py +++ b/numpy/polynomial/tests/test_polynomial.py @@ -391,11 +391,11 @@ class TestPolynomialClass(TestCase) : 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() |