Repository navigation
Infer NumPy Generator.normal result shapes - #5619
Closed
AlessandroRuggiero wants to merge 1 commit into
Closed
AlessandroRuggiero wants to merge 1 commit into
AlessandroRuggiero wants to merge 1 commit into
Conversation
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D131296292. (Because this pull request was imported automatically, there will not be any future comments.) |
stroxler
approved these changes
Nov 11, 2026
stroxler
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Contributor
Author
|
✅ This PR meets all requirements from our pull request checklist. Optional recommendations:
Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour. |
Contributor
|
This pull request has been merged in cddd16a. |
This was referenced Nov 14, 2026
meta-codesync Bot
pushed a commit
that referenced
this pull request
Nov 17, 2026
Summary: Same pattern as #5619: `rng.uniform` and `rng.exponential` now return `size`'s shape, or without `size` the broadcast shape of array `low`/`high` (`scale`'s shape for `exponential`). `test_issue_4917.py` calls `rng.uniform` with a tuple size, so it now gets exact shapes instead of `Any`; I updated its expectations. It no longer exercises comparing an unknown-shape array with a float. - [x] I am a human, and I fully understand the code I am submitting. Pull Request resolved: #5651 Test Plan: Added tests to `tensor-shapes/pyrefly-numpy-stubs/test/test_random.py` covering int, tuple, list and symbolic `size`, array parameters with and without `size`, mismatched `low`/`high`, and the `float` result without arrays or `size`. Updated the expectations in `test_issue_4917.py`. Ran: - `python3 tensor-shapes/pyrefly-numpy-stubs/run_pyrefly.py` - `"$TENSOR_SHAPES_VENV/bin/python" tensor-shapes/pyrefly-numpy-stubs/run_runtime_tests.py` - `./test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema --no-extension` (formatting and lint) Reviewed By: stroxler Differential Revision: D132604572 fbshipit-source-id: b9987525ba407f9b78648059c8b48972d5f660fb
meta-codesync Bot
pushed a commit
that referenced
this pull request
Nov 17, 2026
Summary: Same pattern as #5619: `rng.integers` now returns `size`'s shape, or without `size` the broadcast shape of array `low`/`high`. The dtype is kept (`int64` by default, or e.g. `np.int32` / `np.bool_`), using a TypeVar default so one set of overloads covers both. - [x] I am a human, and I fully understand the code I am submitting. Pull Request resolved: #5652 Test Plan: Added tests to `tensor-shapes/pyrefly-numpy-stubs/test/test_random.py` covering scalar results, int, tuple, list and symbolic `size`, explicit dtypes, array bounds with and without `size`, and mismatched bounds. Ran: - `python3 tensor-shapes/pyrefly-numpy-stubs/run_pyrefly.py` - `"$TENSOR_SHAPES_VENV/bin/python" tensor-shapes/pyrefly-numpy-stubs/run_runtime_tests.py` - `./test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema --no-extension` (formatting and lint) Reviewed By: stroxler Differential Revision: D132604672 fbshipit-source-id: f28c20eceefad0cc8639b3f54d4f22d8af45444c
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.
Summary
Adds shape-aware overloads for
Generator.normal. Withsize, the result has exactly that shape. Withoutsize, it has the broadcast shape of arraylocandscale, and mismatched shapes are reported. NumPy's own overloads stay as fallbacks for lists.Test Plan
Added tests to
tensor-shapes/pyrefly-numpy-stubs/test/test_random.py.Ran:
python3 tensor-shapes/pyrefly-numpy-stubs/run_pyrefly.py"$TENSOR_SHAPES_VENV/bin/python" tensor-shapes/pyrefly-numpy-stubs/run_runtime_tests.py./test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema --no-extension(formatting and lint)