Repository navigation
Conversation
Read native NumPy properties directly and build one shared metadata result. Keep NumPy dtype inference for non-native byte order and generic inputs. Co-Authored-By: Aiden <aiden@weco.ai>
This branch has not been deployed
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.
TL;DR
metadataduring the 10,000-iteration fan-out/fan-in forward pass.python -m pytest -o addopts=''— 646 passed, with 14 warnings.What & Why
Previously, every metadata call used four general NumPy queries, even for arrays and scalars that already store these properties.
The change reads those properties directly for exact NumPy arrays and common scalar types.
NumPy still computes the dtype for non-native byte order, so the output stays the same.
Other inputs keep the existing queries, and one shared return builds the result.
Validation
Measurements used Python 3.12 and NumPy 2.5.4 on an isolated CPU core.
All situations use the repository's 10,000-iteration
fan_out_fan_inworkload.The forward-trace time ratios have the following summary:
The first row measures tracing with garbage collection disabled.
The other rows use the unchanged repository benchmarks through
timeit, with garbage collection enabled.Their repeat ranges overlap, so they do not establish a reliable speedup or slowdown.
Plain evaluation does not use the changed metadata path.
Run the repository's full-gradient benchmark from either checkout:
Use
time_fan_out_fan_in_forward_passfor forward tracing, ortime_fan_out_fan_in_funwith-n 10for plain evaluation.Nine additional regression checks passed for swapped-endian float64, complex128, and int32 arrays across scalar, vector, and matrix shapes.
These checks passed on baseline and failed on the earlier dtype shortcut.
Ruff 0.17.3 lint and formatting checks pass on both checkouts.
Why this is safe and easy to maintain
The change stays inside one short function and builds its result in one place.
Exact type checks keep the general path for subclasses and custom array protocols.
tests/test_numpy.py,tests/test_complex.py, and the byte-order regression checks verify unchanged outputs and gradients.AI assistance
This PR was prepared with AI assistance from Aiden. Candidates were tracked with Weco Observe.
Weco share link: https://dashboard.weco.ai/share/dImyhY89leTtdHie5cd2HIVt_O5_ViFJ