summaryrefslogtreecommitdiff
path: root/numpy/polynomial
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2010-05-23 22:02:08 +0000
committerCharles Harris <charlesr.harris@gmail.com>2010-05-23 22:02:08 +0000
commit6e77005137eca1e7fdd4ebd3935f7f57d6aba7bd (patch)
treee5845447e506a080d00961f5e0a3dfc3e40d8c8a /numpy/polynomial
parent59fd4c37d75895ca09f5ad06571d67084eb34324 (diff)
downloadnumpy-6e77005137eca1e7fdd4ebd3935f7f57d6aba7bd.tar.gz
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 ;)
Diffstat (limited to 'numpy/polynomial')
-rw-r--r--numpy/polynomial/polytemplate.py37
-rw-r--r--numpy/polynomial/tests/test_chebyshev.py8
-rw-r--r--numpy/polynomial/tests/test_polynomial.py8
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()