[NumPy-Tickets] [NumPy] #2252: numpy binary format files with float128 entries cannot be read on windows

NumPy Trac numpy-tickets@scipy....
Mon Nov 26 04:03:01 CST 2012

#2252: numpy binary format files with float128 entries cannot be read on windows
 Reporter:  valhallasw   |       Owner:  somebody   
     Type:  enhancement  |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  numpy.core   |     Version:  1.6.1      
 Keywords:               |  
 '''Steps to reproduce:'''

 1. On a platform supporting float128: import numpy as np;
 np.save('test.npy', np.float128(1))

 2. Copy the file to a platform that does not support float128

 3. import numpy as np; np.load('test.npy')

 '''Observed result:'''

 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "C:\Python27\lib\site-packages\numpy\lib\npyio.py", line 350, in
     return format.read_array(fid)
   File "C:\Python27\lib\site-packages\numpy\lib\format.py", line 440, in
     shape, fortran_order, dtype = read_array_header_1_0(fp)
   File "C:\Python27\lib\site-packages\numpy\lib\format.py", line 361, in
     raise ValueError(msg % (d['descr'],))
 ValueError: descr is not a valid dtype descriptor: '<f16'

 '''Expected result'''
 (some path): DowncastWarning: The file contains float128 values, but the
 system does not support them. The values will be represented as float96

 array(1.0, dtype=float96)

 '''Used platforms & versions'''

 numpy 1.3.0 @ Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC 4.4.5]
 on linux2

 numpy 1.6.1 @ python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32
 bit (Intel)]


 a) Store only < float128 values, or

 b) convert existing files with the following script:

 import sys
 import numpy as np
 from numpy import dtype, float64, float128

 m = {dtype(float128): dtype(float64)}
 data = np.load(sys.argv[1])
 newdata = data.astype([(name, m.get(dt,dt)) for name, (dt, alignment) in
 sorted(data.dtype.fields.items(), key=lambda x: x[1][1])])
 np.save(sys.argv[1] + ".reduced.npy", newdata)

 and call it with
 python scriptname.py <file to convert>

 conversions are defined by the dictionary ''m''.

Ticket URL: <http://projects.scipy.org/numpy/ticket/2252>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list