Conversation
There was a problem hiding this comment.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
array_api_compat/common/_helpers.py:944
- [nitpick] Consider adding a comment to explain why 'cache' is included in _all_ignore to improve clarity for future maintainers.
_all_ignore = ['cache', 'sys', 'math', 'inspect', 'warnings']
array_api_compat/common/_helpers.py
Outdated
|
|
||
|
|
||
| def _is_jax_zero_gradient_array(x: object) -> bool: | ||
| @cache |
There was a problem hiding this comment.
This in theory could lead to a memory leak for a user that somehow dynamically defines and then forgets a lot of classes. I don't think it's something to worry about in real life?
There was a problem hiding this comment.
Can we limit the cache size just not even think about this possibility?
There was a problem hiding this comment.
Yes. @lru_cache(100) costs just 4ns more than @cache as long as it doesn't need to evict anything (which in 99% of the times it won't happen). Amended.
9c0ea9c to
632f081
Compare
| dtype = x.dtype # type: ignore[attr-defined] | ||
| except AttributeError: | ||
| return False | ||
| cls = cast(Hashable, type(dtype)) |
There was a problem hiding this comment.
Can't say I'm happy to see cryptic things from typing doing something at runtime, but OK, am ready to believe it's somehow useful.
There was a problem hiding this comment.
cast is a noop at runtime.
|
Merged, thanks @crusaderky |
Speed up helper functions through caching.
Note:
is_numpy_arrayandis_jax_arrayare slower than the other equivalent functions due to the reclassification of JAX zero gradient arrays.