[Python-ideas] Adding a half-float (16-bit) type to PEP 3118 (and possibly the struct module?)

Eli Stevens (Gmail) wickedgrey at gmail.com
Wed Mar 30 20:37:32 CEST 2011


Numpy 1.6.0 adds support for a half-float (16-bit) data type, but
cannot currently export a buffer interface to the data, since the
closest type that PEP 3118 supports is an unsigned short ('H').  This
makes working with the data from outside numpy (for example, from
Cython) difficult, since even if numpy were to expose a buffer
interface to the data, it's unclear that the data needs special
treatment to interpret correctly (numpy does this with bit shifting
functions to convert it to a float32, but it has access to the array
dtype which isn't available through the buffer interface, per my

What would be required to get a float16 data type added to PEP 3118
(either implicitly via inclusion of the struct module, or explicitly
in the PEP itself)?

I'm not currently a contributor to python, numpy or cython, but am
prepared to provide patches.  Some of my exploratory work for numpy
and cython (which is my driving use case) is below.  Numpy seems to
use the 'e' format character, so I stuck with that.



More information about the Python-ideas mailing list