8000 gh-90751: memoryview now supports half-float by corona10 · Pull Request #96738 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90751: memoryview now supports half-float #96738

8000
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

Merged
merged 9 commits into from
Sep 10, 2022
Merged

Conversation

corona10
Copy link
Member
@corona10 corona10 commented Sep 10, 2022

With patch


Python 3.12.0a0 (heads/gh-90751:ea5e2db2fa, Sep 10 2022, 15:41:30) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a = np.array([0.0, -1.5], np.float16())
>>> list(memoryview(a))
[0.0, -1.5]
>>> memoryview(a.tobytes()).cast('e').tolist()
[0.0, -1.5]
>>>

@corona10
Copy link
Member Author

(.oss) ➜  cpython git:(gh-90751) ✗ ./python.exe -m test test_memoryview -R 3:3
Raised RLIMIT_NOFILE: 256 -> 1024
0:00:00 load avg: 1.24 Run tests sequentially
0:00:00 load avg: 1.24 [1/1] test_memoryview
beginning 6 repetitions
123456
......

== Tests result: SUCCESS ==

1 test OK.

Total duration: 660 ms
Tests result: SUCCESS

@corona10 corona10 changed the title gh-90751: memoryview supports half-float gh-90751: memoryview now supports half-float Sep 10, 2022
Copy link
Member
@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Thank you @corona10 .
Can you also add half-float to the generic tests in test_buffer.py?

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@corona10
Copy link
Member Author

@pitrou

Can you also add half-float to the generic tests in test_buffer.py?

Hmm, would you like to recommend the proper place?

@pitrou
Copy link
Member
pitrou commented Sep 10, 2022

@corona10 You can use this patch:
https://gist.github.com/pitrou/266079854bae1873d771aed14ca8fefa

but you'll see that it triggers some "RuntimeError: memoryview: internal error in richcompare" exceptions.

@corona10
Copy link
Member Author
corona10 commented Sep 10, 2022

Thanks, I implemented unpack_cmp for half-float to pass your suggestion.
Now it passed all test suites :)


➜  cpython git:(gh-90751) ✗ ./python.exe -m test test_buffer -R 3:3
Raised RLIMIT_NOFILE: 256 -> 1024
0:00:00 load avg: 2.45 Run tests sequentially
0:00:00 load avg: 2.45 [1/1] test_buffer
beginning 6 repetitions
123456
......
test_buffer passed in 38.4 sec

== Tests result: SUCCESS ==

1 test OK.

Total duration: 38.4 sec
Tests result: SUCCESS

@pitrou
Copy link
Member
pitrou commented Sep 10, 2022

With Numpy installed I get errors, will push a fix.

@corona10
Copy link
Member Author

With Numpy installed I get errors, will push a fix.

Thanks

@pitrou pitrou requested a review from gpshead September 10, 2022 17:20
@corona10
Copy link
Member Author

@pitrou
With numpy installation:


test_buffer leaked [1481, 1467, 1476] references, sum=4424
test_buffer failed (reference leak) in 53.9 sec

@corona10
Copy link
Member Author
corona10 commented Sep 10, 2022

Forget about #96738 (comment)
The leakage is not related to this PR, the main branch is leaked also.
(With NumPy only)


test_buffer leaked [1392, 1380, 1375] references, sum=4147
test_buffer failed (reference leak) in 50.1 sec

== Tests result: FAILURE ==

1 test failed:
    test_buffer

Total duration: 50.1 sec
Tests result: FAILURE

Copy link
Member
@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

LGTM

@pitrou
Copy link
Member
pitrou commented Sep 10, 2022


The leakage is not related to this PR, the main branch is leaked also.
(With NumPy only)

Which Numpy version? I don't get this problem here.

@pitrou pitrou merged commit 8d75a13 into python:main Sep 10, 2022
@pitrou
Copy link
Member
pitrou commented Sep 10, 2022

Thanks a lot @corona10 !

@corona10 corona10 deleted the gh-90751 branch September 11, 2022 01:11
@corona10
Copy link
Member Author

Which Numpy version? I don't get this problem here.

@pitrou

Python 3.12.0a0 (heads/gh-90751:e8c1fed38f, Sep 10 2022, 17:46:55) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'1.23.3'

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.

4 participants
0