Repository navigation
Micro optimization of plotting #26303
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
Changes from 8 commits
750dcef
b33ba05
d35fa2e
735038f
6ae9b66
2cafe97
f3f1b4b
2e4bd65
18b4a54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,7 +286,7 @@ def process(self, s, *args, **kwargs): | |
| """ | ||
| if self._signals is not None: | ||
| _api.check_in_list(self._signals, signal=s) | ||
| for cid, ref in list(self.callbacks.get(s, {}).items()): | ||
| for ref in list(self.callbacks.get(s, {}).values()): | ||
| func = ref() | ||
| if func is not None: | ||
| try: | ||
|
|
@@ -1634,6 +1634,8 @@ def _safe_first_finite(obj, *, skip_nonfinite=True): | |
| def safe_isfinite(val): | ||
| if val is None: | ||
| return False | ||
| if isinstance(val, int): | ||
|
Contributor
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. I'm not sure special-casing ints here make sense -- certainly that'll make a microbenchmark based on plotting ints faster, but at the cost of introducing a branch for all other cases (plotting floats is likely much more common, and even np.int is perhaps a more common case than python ints in real code). If one really wants to workaround the fact that np.isfinite is relatively slow, one can instead use math.isfinite (which on a quick microbenchmark is extremely fast), taking into account the fact that it won't handle certain cases like datetimes (but will handle numpy floats and ints), so something like try:
if math.isfinite(val): return True
except TypeError:
pass
# continue with the np.isfinite check
Contributor
Author
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. This is an excellent suggestion. On my system |
||
| return True | ||
| try: | ||
| return np.isfinite(val) if np.isscalar(val) else True | ||
| except TypeError: | ||
|
|
@@ -1661,7 +1663,10 @@ def safe_isfinite(val): | |
| raise RuntimeError("matplotlib does not " | ||
| "support generators as input") | ||
| else: | ||
| return next((val for val in obj if safe_isfinite(val)), safe_first_element(obj)) | ||
| for val in obj: | ||
| if safe_isfinite(val): | ||
| return val | ||
| return safe_first_element(obj) | ||
|
oscargus marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| def sanitize_sequence(data): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.