Skip to content

Infer NumPy Generator.normal result shapes - #5619

Closed
AlessandroRuggiero wants to merge 1 commit into
pyrefly-org:mainfrom
AlessandroRuggiero:numpy-generator-normal-shapes
Closed

AlessandroRuggiero wants to merge 1 commit into
pyrefly-org:mainfrom
AlessandroRuggiero:numpy-generator-normal-shapes

Conversation

@AlessandroRuggiero

Copy link
Copy Markdown
Contributor

Summary

Adds shape-aware overloads for Generator.normal. With size, the result has exactly that shape. Without size, it has the broadcast shape of array loc and scale, and mismatched shapes are reported. NumPy's own overloads stay as fallbacks for lists.

  • I am a human, and I fully understand the code I am submitting.

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)

@meta-cla meta-cla Bot added the cla signed label Nov 11, 2026
@meta-codesync

meta-codesync Bot commented Nov 11, 2026

Copy link
Copy Markdown
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 stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@AlessandroRuggiero

Copy link
Copy Markdown
Contributor Author

@stroxler I don't think I have the permissions to assign this PR to you, as you mentioned in #5595.

@github-actions

Copy link
Copy Markdown

✅ This PR meets all requirements from our pull request checklist.

Optional recommendations:

  • If this PR addresses an open issue, please link the issue in the PR description and claim it.

Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour.

@meta-codesync

meta-codesync Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in cddd16a.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants