[Numpy-discussion] Extensive use of methods instead of functions

José Fonseca j_r_fonseca at yahoo.co.uk
Thu Jan 23 16:10:02 EST 2003

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.

Taking this statement as an example:

	Numeric.put(myarray, myindices, myvalues)

In the current state of affairs, if we wanted to have to statment to
work with asparse matrix class derived from a Numeric array, it would
have to be something like:

	Sparse.put(myarray, myindices, myvalues)

That is, it forces to the underlaying code to know whether is dealing
with Numeric arrays, or some other equivalent class. But it would be
much more useful to have simply:

	myarray.put(myindices, myvalues)

which would work regardless of the actual type of myarray, provided it
supplied the put() method. This would improve enormously code
reusability and extensability.

I know that there are certain implementations details that may difficult
this (like many functions being implemented in pure Python), but any
advances made in this since will be an improvement of the current

Also, I know that this example is a little unhappy because numarray will
do these things with the __getitem__ and __setitem__ operators. But
others could easily be shown.


José Fonseca
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts

More information about the NumPy-Discussion mailing list