[Numpy-discussion] 1.6.0b1 half float buffer bug?

Pauli Virtanen pav at iki.fi
Fri Mar 25 13:21:40 EDT 2011


Fri, 25 Mar 2011 10:00:24 -0700, Eli Stevens (Gmail) wrote:
> I'm working on getting support for 16-bit floats into cython and have
> run into what seems like a numpy bug (I'm a new contributor to both
> projects, so bear with me ;).
> 
> https://github.com/wickedgrey/numpy/
commit/29f9f1b709cc2c346b8514859c58a761df80f031
> 
> Adding NPY_HALF to the switch statement on line 350 of
> numpy/core/src/multiarray/buffer.c doesn't seem controversial (unless it
> needs to be spelled NPY_FLOAT16 or something similar), but I have no
> idea how to test the change.

The buffer interface cannot be used to export the half-float types, since 
the type is not specified in PEP 3118. Numpy cannot unilaterally add 
nonstandard format codes to the spec.

What can be done instead is exporting the half-float items (and any other 
non-3118 types) as plain bytes. I think this is the way to go.

On the Cython side, you'd need to detect when you are working with Numpy 
arrays, and get the half-float type information from the Numpy dtype 
rather than from the exported buffer.

-- 
Pauli Virtanen




More information about the NumPy-Discussion mailing list