This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients mark.dickinson, meador.inge, pitrou
Date 2022-01-31.15:28:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643642940.05.0.703714910656.issue46593@roundup.psfhosted.org>
In-reply-to
Content
The struct module has support for half-floats (the "e" format code) but support is not fully enabled in the memoryview object.

Let's contrast float32 (the "f" format code), which you can cast to, and read as Python objects:

>>> a = np.array([0.0, -1.5], np.float32())
>>> list(memoryview(a))
[0.0, -1.5]
>>> memoryview(a.tobytes()).cast('f').tolist()
[0.0, -1.5]

and float16, where support is minimal (casting forbidden, reading as Python objects unimplemented):

>>> a = np.array([0.0, -1.5], np.float16())
>>> list(memoryview(a))
Traceback (most recent call last):
  File "<ipython-input-15-102982f8ac8e>", line 1, in <module>
    list(memoryview(a))
NotImplementedError: memoryview: format e not supported

>>> memoryview(a.tobytes()).cast('e').tolist()
Traceback (most recent call last):
  File "<ipython-input-25-78df215a7360>", line 1, in <module>
    memoryview(a.tobytes()).cast('e').tolist()
ValueError: memoryview: destination format must be a native single character format prefixed with an optional '@'
History
Date User Action Args
2022-01-31 15:29:00pitrousetrecipients: + pitrou, mark.dickinson, meador.inge
2022-01-31 15:29:00pitrousetmessageid: <1643642940.05.0.703714910656.issue46593@roundup.psfhosted.org>
2022-01-31 15:29:00pitroulinkissue46593 messages
2022-01-31 15:28:59pitroucreate