[SciPy-dev] Generic polynomials class (was Re: Volunteer for Scipy Project)
Charles R Harris
charlesr.harris@gmail....
Mon Oct 12 21:33:08 CDT 2009
On Mon, Oct 12, 2009 at 6:14 PM, Anne Archibald
<peridot.faceted@gmail.com>wrote:
> 2009/10/9 Charles R Harris <charlesr.harris@gmail.com>:
> >
> > It's not inheritence, it's a class templaate. Because classes are
> objects
> > in python you can return them from functions.with a defined enviroment.
> > Another way to look at it is completions. A basis would just be another
> > passed parameter. and the class code would still only heed to be written
> > once for all the different types of polynnomial basis.. I think it is a
> > cleaner way to go.
>
> Upon reflection, I think you were right about wanting the polynomial
> code in the polynomial classes themselves. I've implemented this in
> the git branch "twoclass"; there, when you implement a new
> representation of polynomials, you write a new subclass of Polynomial
> and a new subclass of Basis, and polynomials are created with
> "basis.polynomial(coefficients)".
>
>
I wasn't thinking of using subclasses at all, what I wanted was an standard
interface on top of the different types of polynomials using a few
polynomial specific functions like add, sub, mul, and divide. One way to do
that would be to simply copy the interface code into each different
polynomial module, but that would make maintenance more difficult. Using a
generic_interface function to return a class object (not instance) from a
function that accepts the add, sub, mul, and divide functions as arguments
has the same effect, but the class code only needs to be written in one
place. And since I've already written code for the Chebyshev series I
thought I would reuse it, just replacing Chebyshev by some generic name like
Poly, which can be done without danger because the class name is local to
the factory function.
Anyway, I was thinking about polynomials of the Chebyshev or power series
type, I don't know that the same interface would be appropriate for the
different Lagrange basis. All I wanted for the different polynomial types
were the coefficients and domain, whereas for the Lagrange type basis it
looks like you will need a list of (x_i, y_i) pairs, or at least the x_i.
You could still use a domain for axis scaling/translation, but that doesn't
seem the most natural way. What you might could do is pass a list of the x_i
to a factory function which would then return a class that could be
instantiated using the y_i values. That way the instances with different
sample points would not compare as instances of the same class.
I've just gotten back and have been playing with the cat/dog/pet thing just
to test things out and it looks like it is going to work, I've attached
copies of the silly things so you can see an example of what I'm thinking
of. Now I'll go take a closer look at what you've been doing, which I
probably should have done before running on like this ;)
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20091012/519199de/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pet.py
Type: text/x-python
Size: 290 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-dev/attachments/20091012/519199de/attachment.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cat.py
Type: text/x-python
Size: 78 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-dev/attachments/20091012/519199de/attachment-0001.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dog.py
Type: text/x-python
Size: 78 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-dev/attachments/20091012/519199de/attachment-0002.py
More information about the Scipy-dev
mailing list