Thanks a lot for your answer Francesc,

Cyril.



Francesc Alted a écrit :
> Cyril,
>
> A Tuesday 28 April 2009, cyril giraudon escrigué:
>   
>> Hi,
>>
>> I use HDF5 to store complex numbers and I see two ways of defining a
>> complex number (since I believe there is no official manner):
>>     
>
> Yes, as far as I know there is not an blessed way to declare complex 
> types in HDF5.  In fact, PyTables chose the compound approach back in 
> 2004 (in fact, contributed by Tom Hedley) and frankly, as it seems to 
> work quite well, we have never looked back (in fact, Octave follows the 
> same strategy when writes to HDF5 files, except that the compound 
> fields are called 'real' and 'imag' instead of the PyTables 'r' and 'i' 
> convention, but this is supported by PyTables for reading too).
>
> In addition, lately the h5py project seems to have chosen the same 
> approach than PyTables to represent complex numbers.  So, even though 
> it is true that there is not an 'official' way to specify complex 
> numbers, there is an a certain tradition in doing it the PyTables' way 
> (let's call it this way).
>
>   
>> 1. A compound datatype : one real for the real part and one real for
>> the imaginery part
>> 2. A 2 element array datatype : two reals in an array A, A(0) is the
>> real part and A(1) is the imaginary part.
>>
>> Pytables read directly the compound datatype as a complex number but
>> read "logically" the array datatype as an array.
>> Is it possible pytables read directly an array datatype as a complex
>> number without any conversion ?
>>
>> Why this question ? It is very simpler to manipulate an array
>> datatype from C, fortran ... than a compound datatype and the new
>> lite API allows easily the creation of such a structure.
>>     
>
> Yes, this should be possible, but provided that it already exists a way, 
> I think there is not much point in changing it.  Perhaps you may want 
> to create your complex arrays out of your HDF5 data by operating with 
> NumPy, like for example:
>
> In [66]: r = np.array([1,2,3], dtype='f8')
>
> In [67]: i = np.array([4,5,6], dtype='f8')
>
> In [68]: cplx = r+i*1.j
>
> In [69]: cplx
> Out[69]: array([ 1.+4.j,  2.+5.j,  3.+6.j])
>
> which should be fast enough for most of applications.
>
> HTH,
>
>   


------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to