[Numpy-discussion] Response to PEP suggestions

David M. Cooke cookedm at physics.mcmaster.ca
Thu Feb 17 17:55:20 CST 2005


On Thu, Feb 17, 2005 at 08:00:38PM -0500, Colin J. Williams wrote:
> David M. Cooke wrote:
> >I come from a C background, so things like Float64, etc., look wrong.
> >I think more in terms of single- and double-precision, so I think
> >adding some more descriptive types:
> >
> >CInt         (would be either Int32 or Int64, depending on the platform)
> >CFloat       (can't do Float, for backwards-compatibility reasons)
> >CDouble      (could just be Double)
> >CLong        (or Long)
> >CLongLong    (or LongLong)
> >
> >That could make it easier to match types in Python code to types in C
> >extensions.
> > 
> >
> I guess the issue revolves around the characteristics of the target 
> users, if most are C aficionados then the above has merit.  However, 
> this doesn't provide for the Int8's or the Int16's.  Neither does it 
> provide for a bit array, which would be suitable for Booleans.
> 
> My guess is that most users would not be from a C background and so 
> something along the lines of numerictypes makes sense.

I'm thinking that CInt, etc., would be aliases for Int32 or Int64 (or
whatever makes sense on the platform), at least at the Python level.

The idea is if you're writing wrapper code for external routines, you
want to use the types used in the routine, which most likely will vary
platform-by-platform. In that case you *don't* want to hardcode Int32,
etc., because that's not the right type for all platforms. I've run into
enough of these bugs, since I'm using a 64-bit Athlon64 Linux system now
as my main system (and Numeric still has some problems internally in
this respect).

It's partly documentation: you're asserting that an array is an array of
C ints, whatever a C int is. Passing that to a routine that takes C ints
shouldn't require conversion, or fail because of mismatched min-max int
ranges.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca




More information about the Numpy-discussion mailing list