[Numpy-discussion] More guestions on Chebyshev class.

Russell E. Owen rowen at uw.edu
Thu Oct 1 15:55:19 EDT 2009


In article 
<e06186140909302316v7dd6a741ubc28d98977d00b03 at mail.gmail.com>,
 Charles R Harris <charlesr.harris at gmail.com> wrote:

> The Chebyshev class is now working pretty well, but I would like to settle
> some things up front.
> 
> 1) Order in which coefficients are stored/passed/accessed.
> 
> The current poly1d class ctor is called with the coefficients in high to low
> order, yet the __getitem__ and __setitem__ methods access them in reverse
> order. This seems confusing and I think both should go in the same order and
> my preference would be from low to high. The low to high order also works a
> bit better for implementation.

This sounds like a very useful change to me.

> 2) poly1d allows the size of the coefficient array to be dynamically
> extended. I have mixed feeling about that and would prefer not, but there
> are arguments for that: students might find it easier to fool with.

If it's easy to make a new instance that copies the old cofficients and 
allow the user to add new ones or trim some high order terms, then 
surely that suffices and you need not support resizing the coefficient 
array?

> 3) The poly1d class prunes leading (high power) zeros. Because the Cheb
> class has a fit static method that returns a Cheb object, and because when
> fitting with Chebyshev polynomials the user often wants to see *all* of the
> coefficients, even if some of the leading ones are zero, the Cheb class does
> not automatically prune the zeros, instead there are methods for that.

Will this be affected if you list the coefficients low to high, as you 
recommend in (1) or make the coefficient list not resizable as per (2)? 
Certainly it seems much safer to elide trailing zeros, rather than 
leading zeros.

In any case, I agree with you that manually trimming sounds safer than 
than automatically trimming.

> 4) All the attributes of the Cheb class are read/write. The poly1d class
> attempts to hide some, but the method used breaks the copy module. Python
> really doesn't have private attributes, so I left all the attributes exposed
> with the usual Python proviso: if you don't know what it does, don't fool
> with it.
> 
> 5) Is Cheb the proper name for the class?

I suggest spelling it out: Chebyshev. Explicit is better than implicit 
and it doesn't save that much typing. (Failing that, I suggest at least 
including the Y -- I think Cheby is clearer than Cheb).

-- Russell




More information about the NumPy-Discussion mailing list