enum values visible in numeric types instances?
![](https://secure.gravatar.com/avatar/6c9110e0401b013d2324fbd6257dc80d.jpg?s=120&d=mm&r=g)
Hi, A couple of points related with numarray type objects: 1.- When working with numeric types instances like UInt8 or Float64, is there a way to access to their enumeration NumarrayType C counterpart?. That can be handy when want to map from these objects and integers. For example, right now, I'm forced to use these mappings in Pyrex: # Conversion tables from/to classes to the numarray enum types toenum = {num.Int8:tInt8, num.UInt8:tUInt8, num.Int16:tInt16, num.UInt16:tUInt16, num.Int32:tInt32, num.UInt32:tUInt32, num.Float32:tFloat32, num.Float64:tFloat64, CharType:97 # ascii(97) --> 'a' # Special case (to be corrected) } toclass = {tInt8:num.Int8, tUInt8:num.UInt8, tInt16:num.Int16, tUInt16:num.UInt16, tInt32:num.Int32, tUInt32:num.UInt32, tFloat32:num.Float32, tFloat64:num.Float64, 97:CharType # ascii(97) --> 'a' # Special case (to be corrected) } (yes, Pyrex lets you do that kind of "miracles", like mappings between Python objects and C integers) but if I had this access directly from the object (for example Int8.enumType), my code (and C-extensions in general) could look simpler. 2.- I understand now why Todd was worried about CharArray objects to be assigned to an enumerated type. In fact, if you look at the above maps, I have to map myself this special object as the number 97 (which is the ascii value for character "a"). 97 is ok for now because it can't collide (at least for a while) with other enumeration types. My suggestion is that it would be a good thing to have a reserved enum type for CharArray. And I think that mapping CharArrays with Bool or Int8, would not be a good solution because chararray objects differ in some ways from them, that it would be a mess to distinguish both objects in C-code by just looking at its enumeration type. I don't know, but maybe recarrays also merit a place in enumeration (?). By the way, after the discussion with Todd I finally decided to remove all the Numeric charcodes (and related codes) from PyTables. However, I can still manage Numeric objects by converting them to numarray and accessing the class type with the .type() method. An you know that? the code looks much more logical and neat, and best of all, less error-prone (well, at least I hope so!). I definitely encourage you to do a similar transition in numarray (although I guess that would be more difficult because you still need to Numeric compatibility). Thanks, -- Francesc Alted
participants (1)
-
Francesc Alted