
Hi all, I'm migrating my pyCGNS package to numarray. I think that numarray is better suited for the in-memory share of array I'd like to achieve. Now, with Numeric, I use to create arrays with integers, floats, but also char type. In CGNS (http://www.cgns.org) we have types I4, I8, R4 and R8, but also C1 which is an array of chars. It looks like, in numarray, we should consider chars as unsigned ints. This is not false from a system point of view, but from an application point of view I have to make a difference between *real* char arrays, and unsigned int arrays. In other words, when I have a C1 array, I have to translate it as a String, when I have an I4 or even I8, I have to translate it as Integer array. Now I only have integers arrays, and I have to find out a way to know that my array of int is a string. The CGNS->numarray translation is OK, but now I'm loosing information when I'm going back numarray->CGNS. You can say: It's up to your application to understand that this list of ints is a string. I'll reply: So why don't you consider a list of bytes, it's up to the application to know that you're 32 or 64 bits... Is there something in numarray that could replace the Numeric interface for this string type? Is it difficult to add a 'Character' type? Is the (undocumented) CharArrayType the solution for this? Marcvs [alias Not using unicode...] ----------------------------------------------------------------------- Marc POINOT Alias: marcvs Email: poinot@onera.fr ONERA -MFE/DSNA/ELSA Tel: 01.46.73.42.84 Info: elsa-info@onera.fr 29, Div. Leclerc Fax: 01.46.73.41.66 Site: 92322 Chatillon FRANCE Project: elsA Web: http://www.onera.fr

Hi Marc, A Dimarts 30 Setembre 2003 18:21, Marc Poinot va escriure:
Is there something in numarray that could replace the Numeric interface for this string type? Is it difficult to add a 'Character' type? Is the (undocumented) CharArrayType the solution for this?
Yes, it is. See:
from numarray import strings strings.array(["asd", "aa"]) CharArray(['asd', 'aa']) a=strings.array(["asd", "aa"]) a[1] 'aa' a.raw()[1] # If you want to get *all* spaces and nulls in strings 'aa '
This is undocumented in the manual, but it's quite well described in the doc strings:
help(strings.array)
Cheers, -- Francesc Alted

Francesc Alted wrote:
from numarray import strings
This solves the python lib problem, but not the API problem. In the API, I've got some arrays, and when I want to store these arrays in CGNS I cannot decide if an UInt32 is a string or not. Then I'll have to manage my string arrays as specific types, but not arrays... I'll have to add an attribute to arrays to indicate that it is a string, if so then I should store it in CGNS as C1 array. Is there a reason why Char type is not taken into account in numarray ? Well known data representation or storage systems as netCDF or HDF, or even ADF (our CGNS storage system) have a Char type... -MP- ----------------------------------------------------------------------- Marc POINOT Alias: marcvs Email: poinot@onera.fr ONERA -MFE/DSNA/ELSA Tel: 01.46.73.42.84 Info: elsa-info@onera.fr 29, Div. Leclerc Fax: 01.46.73.41.66 Site: 92322 Chatillon FRANCE Project: elsA Web: http://www.onera.fr

A Dimecres 01 Octubre 2003 10:57, Marc Poinot va escriure:
Francesc Alted wrote:
from numarray import strings
This solves the python lib problem, but not the API problem. In the API, I've got some arrays, and when I want to store these arrays in CGNS I cannot decide if an UInt32 is a string or not. Then I'll have to manage my string arrays as specific types, but not arrays...
I use something like: isinstance(arr, numarray.strings.CharArray) in my C extensions. I'm using Pyrex to do that and it is responsible to generate the appropriate C code, so, a priori, this is also possible from C.
I'll have to add an attribute to arrays to indicate that it is a string, if so then I should store it in CGNS as C1 array.
That's another possibility
Is there a reason why Char type is not taken into account in numarray ? Well known data representation or storage systems as netCDF or HDF, or even ADF (our CGNS storage system) have a Char type...
In the numarray.records module there is a Char type defined as: class Char: """ data type Char class""" bytes = 1 def __repr__(self): return "CharType" CharType = Char() But this is not defined widely in all the numarray package. Perhaps there is a good reason for not doing that, but I can't figure it now. -- Francesc Alted
participants (2)
-
Francesc Alted
-
Marc Poinot