Conversation
Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com>
6a3ed13 to
3c9f13f
Compare
|
Rebased this branch onto current The preserved behavior is:
Local verification after the rebase: New head: |
|
Thanks @kocaemre — closing this one, but the fix is landing: I've opened #955 with the reduced form of it. Two things came out of reviewing this that are worth passing back. The @overload edits turn out to be no-ops: types.Boolean is not a subclass of types.Integer, so isinstance(size, types.Integer) and not isinstance(size, types.Boolean) can never differ from isinstance(size, types.Integer) alone. The jitted path was already dispatching every case correctly — only the pure-Python body was wrong. Similarly, the np.bool_ half of the exclusion in the Python predicate cannot be reached, because np.bool_ fails isinstance(size, (int, np.integer)) first. So the change reduces to the single line #918 proposed, and #955 is that line plus your np.int64 test, which was the genuinely useful part of this PR. A suggestion for future contributions here: when an issue already specifies the fix — #918 gave the exact predicate, the dispatch table and the reasoning — the most valuable PR is the smallest one that implements it, plus a test. Extra defensive clauses cost review time to prove inert, which is time we would rather spend on the next issue. Thanks for the work on this, including the rebase onto the rng= path after #917 landed. |
Closes #918.
Summary
np.int64(10)) the same as Pythonintin the pure-Pythonrandom.drawpath.sizevalues on the scalar branch so Python and jitted dispatch agree.@njitcallers for both cases.Test plan
pytest quantecon/random/tests/test_utilities.py::TestDraw::test_numpy_integer_size_returns_array quantecon/random/tests/test_utilities.py::TestDraw::test_bool_size_is_treated_as_scalar -qfailed with the Python path returning a scalar fornp.int64(10)and raisingTypeErrorforTrue.2 passed in 6.43s.pytest quantecon/random/tests/test_utilities.py -q—11 passed in 4.45s.pytest quantecon/random -q—11 passed in 4.54s.pytest quantecon -q—602 passed, 2 warnings in 504.77s.flake8 --select=F401,F405,E231 quantecon.git diff --check.