Skip to content

memoryview lacks support for half floats #90751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pitrou opened this issue Jan 31, 2022 · 3 comments
Closed

memoryview lacks support for half floats #90751

pitrou opened this issue Jan 31, 2022 · 3 comments
Labels
3.12 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@pitrou
Copy link
Member

pitrou commented Jan 31, 2022

BPO 46593
Nosy @mdickinson, @pitrou, @meadori, @corona10

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2022-01-31.15:29:00.019>
labels = ['interpreter-core', 'type-feature', '3.11']
title = 'memoryview lacks support for half floats'
updated_at = <Date 2022-01-31.15:54:50.040>
user = 'https://github.com/pitrou'

bugs.python.org fields:

activity = <Date 2022-01-31.15:54:50.040>
actor = 'corona10'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2022-01-31.15:29:00.019>
creator = 'pitrou'
dependencies = []
files = []
hgrepos = []
issue_num = 46593
keywords = []
message_count = 1.0
messages = ['412205']
nosy_count = 4.0
nosy_names = ['mark.dickinson', 'pitrou', 'meador.inge', 'corona10']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46593'
versions = ['Python 3.11']

@pitrou
Copy link
Member Author

pitrou commented Jan 31, 2022

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 '@'

@pitrou pitrou added 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jan 31, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
corona10 added a commit to corona10/cpython that referenced this issue Sep 10, 2022
corona10 added a commit to corona10/cpython that referenced this issue Sep 10, 2022
pitrou added a commit to corona10/cpython that referenced this issue Sep 10, 2022
pitrou added a commit that referenced this issue Sep 10, 2022
@corona10 corona10 added 3.12 only security fixes and removed 3.11 only security fixes labels Sep 11, 2022
@corona10
Copy link
Member

@pitrou We can close this issue right?

@pitrou
Copy link
Member Author

pitrou commented Sep 11, 2022

Ah, sorry, I forgot it. Yes, we can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants