summaryrefslogtreecommitdiff
path: root/numpy/polynomial/polytemplate.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2010-05-21 05:36:05 +0000
committerCharles Harris <charlesr.harris@gmail.com>2010-05-21 05:36:05 +0000
commitaf79cde3ecc5a7bf6b14c97698cad08f2bde82b8 (patch)
treea833e7b4b3b938e2a5d197589a5ac89d3a836225 /numpy/polynomial/polytemplate.py
parentee4a8d391e21fe41ba919b21e890348c64b5a0e7 (diff)
downloadnumpy-af79cde3ecc5a7bf6b14c97698cad08f2bde82b8.tar.gz
CHG: Change the truncate method of the Chebyshev and Polynomial classes
to take degree instead of length. This seems to fit better with normal usage. I feel this change is safe at this time because these new classes seem to be little used as yet.
Diffstat (limited to 'numpy/polynomial/polytemplate.py')
-rw-r--r--numpy/polynomial/polytemplate.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/numpy/polynomial/polytemplate.py b/numpy/polynomial/polytemplate.py
index 424ce7f48..c2030db1b 100644
--- a/numpy/polynomial/polytemplate.py
+++ b/numpy/polynomial/polytemplate.py
@@ -391,19 +391,20 @@ class $name(pu.PolyBase) :
"""
return self.__class__(pu.trimcoef(self.coef, tol), self.domain)
- def truncate(self, size) :
- """Truncate series by discarding trailing coefficients.
+ def truncate(self, deg) :
+ """Truncate series to degree `deg`.
- Reduce the $name series to length `size` by removing trailing
- coefficients. The value of `size` must be greater than zero. This
- is most likely to be useful in least squares fits when the high
- order coefficients are very small.
+ 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.
Parameters:
-----------
- size : int
- The series is reduced to length `size` by discarding trailing
- coefficients. The value of `size` must be greater than zero.
+ 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.
Returns:
-------
@@ -411,9 +412,10 @@ class $name(pu.PolyBase) :
New instance of $name with truncated coefficients.
"""
- if size < 1 :
- raise ValueError("size must be > 0")
- if size >= len(self.coef) :
+ size = int(deg) + 1
+ if size != deg + 1 or size < 1 :
+ raise ValueError("deg must be a non-negative integer")
+ if size >= len(self) :
return self.__class__(self.coef, self.domain)
else :
return self.__class__(self.coef[:size], self.domain)