[Numpy-discussion] Subclassing numarray arrays

Todd Miller jmiller at stsci.edu
Thu Sep 25 13:20:05 EDT 2003

On Thu, 2003-09-25 at 12:14, Colin J. Williams wrote:
> Todd,
> Thanks for the benchmark data.

Thanks for the references.  They suggest that the classmethod approach
we've already tried for folding in the numarray factory functions is
reasonable OOP.
> I intend to post the matrix stuff.  Performance is not a problem for me 
> at this stage.
> Currently, I'm plodding along, making things work.  Later, I'll post it 
> with some rudimentary documentation.
> Regarding the "new-classes standard", I can't find much in either the 
> Python docs or Alex Martelli's "Python in a Nutshell".  One of the new 
> features is a __new__ constructor.

Well,  we've certainly got those (__new__ methods).  They don't match
the __init__ signature though,  nor was I aware that they should.

> The Python array module doesn't formally have a class and thus it can't 
> be sub-classed.  It uses a factory function to create instance objects.
> Martelli, in PIAN p74, writes of factory functions being useful when one 
> wishes to create instances of different classes depending on some 
> condition or for the reuse of an existing instance.
> In the Python Cookbook p173, he proposes the use of a factory function 
> to get around the limitations of Python 2.1 and earlier.  On page 179, 
> he refers to the use of a factory method, again to work around 
> limitations before Python 2.2.
> My rough and ready definition would include the ability to create an 
> instance and initialize
> the data in one step.

One thing to keep in mind is that NumArray was designed to run on
Python-2.0.  As Python-2.2 became widely available and stable, we
realized we could exploit it for better C-API compatibility with
Numeric, and for better speed.   

I think what you and later Nadav have pointed out is that we can exploit
Python-2.2 for better sub-classing as well.  We just haven't done it
yet.  Concrete proposals are welcome.


More information about the NumPy-Discussion mailing list