FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-146151: memoryview supports 'F' and 'D' format types (complex) by skirpichev · Pull Request #146241 · python/cpython · GitHub

/ cpython Public

gh-146151: memoryview supports 'F' and 'D' format types (complex) - #146241

Merged
vstinner merged 5 commits into
python:mainfrom
skirpichev:support-complex-memoryview/146151
Mar 26, 2026
Merged

gh-146151: memoryview supports 'F' and 'D' format types (complex)#146241
vstinner merged 5 commits into
python:mainfrom
skirpichev:support-complex-memoryview/146151

Conversation

skirpichev commented Mar 21, 2026
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

Comment thread Doc/whatsnew/3.15.rst Outdated
skirpichev requested a review from vstinner March 26, 2026 00:11

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. The implementation looks complete and well tested.

Comment thread Objects/memoryobject.c
memcpy(ptr, &x, sizeof(x));
}
else {
float x[2] = {(float)c.real, (float)c.imag};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I wasn't sure of the behavior on underflow or overflow of the double to float cast, so I tested:

>>> import struct, sys
>>> data=struct.pack('F', 0.0) * 4
>>> m=memoryview(bytearray(data)).cast('F')
>>> m[0]=math.nextafter(0, 1)
>>> m[1]=sys.float_info.min
>>> m[2]=sys.float_info.max
>>> m[3]=float("nan")
>>> m.tolist()
[0j, 0j, (inf+0j), (nan+0j)]

I got the values that I expected. I suppose that these conversions are well specified by IEEE 754.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The behavior here is same as for 'f' format, just component-wise, see PACK_SINGLE macro.

…e-146151.4-lhim.rst

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner merged commit c68a194 into python:main Mar 26, 2026
51 checks passed

Copy link
Copy Markdown
Member

Merged, thanks for your contribution.

skirpichev deleted the support-complex-memoryview/146151 branch March 26, 2026 18:34
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Apr 16, 2026
skirpichev added a commit to skirpichev/cpython that referenced this pull request Apr 17, 2026
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL