[Numpy-discussion] Introduction

Perry Greenfield perry at stsci.edu
Tue Apr 16 08:15:09 EDT 2002

> > > Important Question:  If an NDArray had a typecode (and it was a known
> > > string), is it possible to promote it to one of the standard NumArray
> > > types?
> > >
> >
> > I think we want to avoid NDArray having any type attribute (Some types
> > have subtypes and then the issue gets really messy). We leave it
> > to the subclass to address how types will be handled.
> > 
> Ok that's what you're currently doing, but let me rephrase the question.
>   :-)
> Given a "leaf type" -- something that is really well specified and very
> similar on all modern platforms:
>     "Int32"    - not just an arbitrary "Int"
>     "Float64"  - not just an arbitrary "Float")
> Do you think you could write a general purpose _function_ that 
> converted an
> "NDArray" to a full featured "NumArray"?  I know this would be in Python,
> but let's pretend it's a C++ prototype to make the types clear:
> NumArray NDArray_to_NumArray(NDArray nda, String typecode, Endian end) {
>     if (WellKnownLeafTypecodeString(typecode)) {
>         /* fill in the blanks here */
>         return NumArray(result)
>     }
>     throw "conversion really is impossible";
> }

I'm not sure I understand exactly what you are trying to do here, but
I try to address the question as best I can.

If one had an NDArray that happened to contain a type that numarray 
supported, yes it is possible (in fact RecArray does that sort of thing).

If your point is that in doing so one must use the private attributes
such as _strides, yes that is true. These attributes are private in 
the sense that users of instances of these objects should never have
cause to access them. But it does not mean that classes that subclass
NDArray or any of its subclasses, should not access them. They are not
private in the sense of the class family (one reason we didn't use
__strides since that mechanism is  not usable (easily anyway) for 
subclasses. In that sense, the attributes form an interface within 
the class family. Some class extenders may need to access them, sure.


More information about the NumPy-Discussion mailing list