[Numpy-discussion] __array_typestr__

Colin J. Williams cjw at sympatico.ca
Fri Apr 1 05:49:53 EST 2005


Travis Oliphant wrote:

>
> For the most part, it seems the array protocol is easy to agree on.  
> The one difficulty is typestr.
>
> For what it's worth, here are my opinions on what has been said 
> regarding the typestr.
>
> * Endian-ness should be included in the typestr --- it is how the data 
> is viewed and an intrinsic part of the type as much as int, or float.

In most cases, endian-ness is associated with the machine being used, 
rather than the data element.  It seems to me that numarray's numeric 
types provides a good model, which may need enhancing for records, 
strings etc.

numarray has:

      Numeric type objects:
        Bool
        Int8 Int16 Int32 Int64
        UInt8 UInt16 UInt32 UInt64
        Float32 Double64
        Complex32 Complex64

      Numeric type classes:
        NumericType
          BooleanType
          SignedType
          UnsignedType
          IntegralType
            SignedIntegralType
            UnsignedIntegralType
          FloatingType
          ComplexType


>
> * I like the fact that struct character codes are documented, but it 
> is hard to remember.  

This is the problem.  numerictypes provides nmenonic names and, if one 
uses an editor with autocompletion, a prompt from the editor.  For those 
interface to existing code, there could be a helper function:

              def toType(eltType= 'i'):  => an instance of NumericType

It should also be possible to derive the typeCode from the eltType, 
numarray doesn't seem to provide this.

Colin W.





More information about the NumPy-Discussion mailing list