[WIP] MAINT: Wrap printoptions in ContextVar#26345
Closed
mtsokol wants to merge 1 commit intonumpy:mainfrom
Closed
[WIP] MAINT: Wrap printoptions in ContextVar#26345mtsokol wants to merge 1 commit intonumpy:mainfrom
printoptions in ContextVar#26345mtsokol wants to merge 1 commit intonumpy:mainfrom
Conversation
e6c3ab5 to
f932b7f
Compare
seberg
reviewed
Apr 25, 2024
| formatters defined above. | ||
| """ | ||
| options = _format_options.copy() | ||
| options = _format_options.get().copy() |
Member
There was a problem hiding this comment.
Not sure it makes sense, but I was half hoping we can just stop passing options around completely and enter a new context ourselves when necessary. contextvar lookup is almost as fast as dict lookup, and global lookup also not really expensive at the function level (within a loop it might be).
printoptions in ContextVarprintoptions in ContextVar
Member
|
ping @mtsokol |
Member
|
I'm going to take this over from @mtsokol and also deal with the |
Member
|
Closing in favor of a new PR closer to the top of the queue. |
seberg
pushed a commit
that referenced
this pull request
Jul 22, 2024
This is a re-do of gh-26345, I'm taking over from @mtsokol because this is needed for the free-threaded work. The new _printoptions.py file exists to avoid a circular import during setup of the multiarray module. I'm guessing this adds some overhead to printing. I haven't benchmarked it because it wasn't clear to me: do we care about printing performance? I could certainly add some caching or a way to avoid repeatedly calling get_legacy_print_mode for every printed value. We could also keep the C global we had before but make it thread-local. I just thought it made things conceptually simpler to store all the printoptions state in the context variable. Co-authored-by: Mateusz Sokół <mat646@gmail.com>
ArvidJB
pushed a commit
to ArvidJB/numpy
that referenced
this pull request
Nov 1, 2024
This is a re-do of numpygh-26345, I'm taking over from @mtsokol because this is needed for the free-threaded work. The new _printoptions.py file exists to avoid a circular import during setup of the multiarray module. I'm guessing this adds some overhead to printing. I haven't benchmarked it because it wasn't clear to me: do we care about printing performance? I could certainly add some caching or a way to avoid repeatedly calling get_legacy_print_mode for every printed value. We could also keep the C global we had before but make it thread-local. I just thought it made things conceptually simpler to store all the printoptions state in the context variable. Co-authored-by: Mateusz Sokół <mat646@gmail.com>
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #26314
Hi @seberg @ngoldbaum,
This (WIP) PR wraps
printoptionsinContextVar. For now I tried with wrapping whole dict into a one ContextVar to see how the implementation changes - I think I can also clean/refactor the file/functions a bit (e.g.set_string_functionwas deprecated in 2.0, maybe we can remove it in 2.1?)