Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions quantecon/random/tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ def test_return_types(self):
out = func(self.cdf, size)
assert_(out.shape == (size,))

def test_numpy_integer_size(self):
"""
A numpy integer `size` must request an array, as a Python `int`
does and as the jitted path already did. See #918.

"""
size = np.int64(10)
for func in self.draw_funcs:
out = func(self.cdf, size)
assert_(out.shape == (size,))

Comment on lines +128 to +138
def test_return_values(self):
for func in self.draw_funcs:
out = func(self.cdf)
Expand Down
5 changes: 4 additions & 1 deletion quantecon/random/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ def draw(cdf, size=None, rng=None):
"""
if rng is None:
rng = np.random
if isinstance(size, int):
# `bool` subclasses `int` in Python but Numba types it as `Boolean`,
# not `Integer`, so the exclusion keeps this branch in step with the
# `@overload` implementation below. See #918.
if isinstance(size, (int, np.integer)) and not isinstance(size, bool):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if isinstance(size, (int, np.integer)) and not isinstance(size, bool):
if isinstance(size, (int, np.integer)):

rs = rng.random(size)
out = np.searchsorted(cdf, rs, side='right')
return out
Expand Down
Loading