[Python-ideas] Adding a half-float (16-bit) type to PEP 3118 (and possibly the struct module?)
raymond.hettinger at gmail.com
Thu Mar 31 00:03:06 CEST 2011
On Mar 30, 2011, at 11:37 AM, Eli Stevens (Gmail) wrote:
> 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 would support adding float16 to the struct module.
It's a well defined format so we might as well provide an accessor.
Just open a feature request for it.
Any issues surrounding its use (i.e. double-rounding) are no
different that the usual float/double conversion issues.
More information about the Python-ideas