-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Optimize imshow #26335
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
+9
−3
Merged
Optimize imshow #26335
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ca00835
optimize imshow
eendebakpt 6e9fe63
fix check
eendebakpt 3991dc6
workaround
eendebakpt ffb8969
ensure error reporting is sorted
eendebakpt 10a677a
add test for strip_math
eendebakpt c831e85
add test for strip_math
eendebakpt a2de5ea
revert strip_math tests
eendebakpt ea53f0d
remove import
eendebakpt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1390,6 +1390,12 @@ def autoscale(self, A): | |||||||||||||||||
def autoscale_None(self, A): | ||||||||||||||||||
"""If vmin or vmax are not set, use the min/max of *A* to set them.""" | ||||||||||||||||||
A = np.asanyarray(A) | ||||||||||||||||||
|
||||||||||||||||||
if isinstance(A, np.ma.MaskedArray): | ||||||||||||||||||
# we need to make the distinction between an array, False, np.bool_(False) | ||||||||||||||||||
if A.mask is False or not A.mask.shape: | ||||||||||||||||||
A = A.data | ||||||||||||||||||
Comment on lines
+1396
to
+1397
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another way of testing:
Suggested change
Numpy generated a |
||||||||||||||||||
|
||||||||||||||||||
if self.vmin is None and A.size: | ||||||||||||||||||
self.vmin = A.min() | ||||||||||||||||||
if self.vmax is None and A.size: | ||||||||||||||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matters for the printed error message when the colormap is invalid. (We could instead ensure that _colormaps is always sorted by sorting it whenever a new item is added, though.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. We could ensure the ordering of
_colormaps
by addingc._cmaps = {k: c._cmaps[k] for k in sorted(c._cmaps)}
at the end ofColormapRegistry.register
. Under the assumption that number of colormaps added is reasonable, this will not have any other negative performance impact.Another option is to replace the code with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making sure that
__iter__
onColormapRegistry
is always sorted is probably the best option (rather than mucking with dictionary order we can keep aself._sorted_keys = sorted(self._cmap)
attribute and iterate over that in__iter__
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but the
if not in...
is also fine (as I see you already pushed that).