[Numpy-discussion] float16/half-precision module

Mark Wiebe mwwiebe@gmail....
Wed Nov 3 18:45:32 CDT 2010

I wrote a float16/half-precision module here:


I've tested it with NumPy 1.3.0 and the latest trunk. With it, you can do
things like this:

>>> import numpy as np, half as h
>>> np.array([0,0.1,1.0/3.0], dtype='float16')
array([ 0.        ,  0.09997559,  0.33325195], dtype=float16)
>>> a = h.float16(1.5)
>>> print a
>>> a.dtype

Many functions aren't implemented, so things like this don't work:

>>> np.arange(10, dtype='float16')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: no fill-function for data-type.

Also, because of bug #809, it looks like there's no way to nicely support
'<f2' or '>f2'.

>>> np.array([10], dtype='f2')
array([ 10.], dtype=float16)
>>> np.array([10], dtype='<f2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: data type not understood

What would need to be done to build it in as a supported NumPy data type?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20101103/c259ea6c/attachment.html 

More information about the NumPy-Discussion mailing list