[Numpy-discussion] Extensive use of methods instead of functions
Paul F Dubois
paul at pfdubois.com
Fri Jan 24 12:36:03 CST 2003
Every time the subject of subclassing a numeric array comes up, it as if
nobody ever thought of it before. Been there, done that. It doesn't turn out
to be all that useful. To see why, consider a + b where a and b are Foo
instances, and Foo inherits from numarray.
a. a + b will be a numarray, not a Foo instance, unless you write a new +
operator.
b. Attempting to have numarray itself apply a subclass constructor to the
result runs into the problem that numarray does not have any idea what the
constructor's signature is or what information is needed to fill out that
constructor.
c. Even if the subclass accepts numarray's constructor signature, it would
rarely produced satisfactory results just "losing" the Foo'ness details of a
and b.
This same argument applies to every method that returns a Foo instance, and
every ufunc. So you end up redoing everything anyway.
In short, worrying about subclassing is way down the list of things we ought
to consider.
> -----Original Message-----
> From: numpy-discussion-admin at lists.sourceforge.net
> [mailto:numpy-discussion-admin at lists.sourceforge.net] On
> Behalf Of Konrad Hinsen
> Sent: Friday, January 24, 2003 12:07 PM
> To: José Fonseca
> Cc: numpy-discussion at lists.sourceforge.net
> Subject: Re: [Numpy-discussion] Extensive use of methods
> instead of functions
>
>
> José Fonseca <j_r_fonseca at yahoo.co.uk> writes:
>
> > With the ability of subclassing types in recent versions of
> the Python
> > language, more people will be interested in subclassing
> Numeric arrays
> > for specific purposes. Still the use of functions instead
> of methods
> > takes away many of the advantages, the ability of being overloaded.
>
> True. On the other hand, there is also an advantage: NumPy
> routines can be used on standard Python data types such as
> number and sequence types.
>
> In the ideal world (which might come one day), core NumPy
> functionality would be part of standard Python, and then all
> these operations would work on other built-in types as well.
>
> Until then, I am not sure that changing NumPy functions to
> methods is a good idea. I need to call them on scalar numbers
> much more often than I subclass arrays.
>
> Konrad.
> --
> --------------------------------------------------------------
> -----------------
> Konrad Hinsen | E-Mail:
> hinsen at cnrs-orleans.fr
> Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
> Rue Charles Sadron | Fax: +33-2.38.63.15.17
> 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/
> France | Nederlands/Francais
> --------------------------------------------------------------
> -----------------
>
>
> -------------------------------------------------------
> This SF.NET email is sponsored by:
> SourceForge Enterprise Edition + IBM + LinuxWorld =omething 2
> See! http://www.vasoftware.com
> _______________________________________________
> Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
More information about the Numpy-discussion
mailing list