Subclassing Numeric arrays.

J

Jacek Generowicz

The Numeric docs state that "Subclassing Numeric arrays is not
possible due to a limitation of Python."

What is this limitation? My first guess is that it is the unsbclassability
of built-in types, which was addressed by the introduction of
new-style classes ... and, indeed, Numeric.ArrayType.__bases__ lists
object, so it looks like a new style class and therefore it seems to
me that it should be subclassable. Yet, if I try to subclass it, I get
told that it is not an acceptable base type.

Now, there is also a UserArray module in the Numeric distribution,
which, supposedly provides a subclassable analogue of the Numeric
arrays. But attempts to subclass it give an identical error message.

So, what am I missing ?
 
L

Lukasz Pankowski

Jacek Generowicz said:
[...]
Now, there is also a UserArray module in the Numeric distribution,
which, supposedly provides a subclassable analogue of the Numeric
arrays. But attempts to subclass it give an identical error message.

So, what am I missing ?

I suppose you subclassed UserArray.array which is the same function as
Numeric.array. Subclassing UserArray.UserArray works:
True
 
J

Jacek Generowicz

Lukasz Pankowski said:
I suppose you subclassed UserArray.array which is the same function as
Numeric.array.

Nope, I subclassed UserArray.ArrayType
Subclassing UserArray.UserArray works:

Aaaah, Numeric.ArrayType == UserArray.ArrayType.

OK, thanks.

I'd still like to understand why Numeric.ArrayType is not
subclassable.
 
C

Colin J. Williams

I haven't looked at Numeric for a while. Numarray
http://stsdas.stsci.edu/numarray/Doc/index.html, which is under
development to replace Numeric, has been modified to facilitate subclassing.

The basic problem remains, factory functions are used for instance
creation, rather than the conventional class constructors.

It would help if there were some guidance with respect to pythonic ways
of creating instances. I posted an enquiry earlier this month:
http://groups.google.ca/groups?q=py...F-8&[email protected]&rnum=1

Colin W.

Lukasz said:
[...]
Now, there is also a UserArray module in the Numeric distribution,
which, supposedly provides a subclassable analogue of the Numeric
arrays. But attempts to subclass it give an identical error message.

So, what am I missing ?


I suppose you subclassed UserArray.array which is the same function as
Numeric.array. Subclassing UserArray.UserArray works:


True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,167
Messages
2,570,911
Members
47,453
Latest member
MadelinePh

Latest Threads

Top