Skip to content
Snippets Groups Projects
Commit 4a91d117 authored by Rob Moss's avatar Rob Moss
Browse files

Ensure inverse_uniform samples are reproducible

Prior to NumPy 1.21 the low and high values could be reversed, and
samples were calculated using `low + (high - low) * random()`. This was
changed in NumPy 1.21 so that if `low > high` an exception is raised;
see https://github.com/numpy/numpy/pull/17921 for details.

We can preserve the original behaviour by negating low and high and the
samples values. This means we obtain the same samples for NumPy < 1.21
and NumPy >= 1.21.
parent cb269565
No related branches found
No related tags found
No related merge requests found
Pipeline #17203 passed
......@@ -64,6 +64,12 @@ def make_prior_fn(fn_name, args):
else:
high = 1 / args['inv_high']
if low > high:
# Return consistent outputs for NumPy < 1.21 and NumPy >= 1.21.
# See https://github.com/numpy/numpy/pull/17921 for details.
return lambda r, size=None: -1 / r.uniform(
low=-low, high=-high, size=size)
return lambda r, size=None: 1 / r.uniform(
low=low, high=high, size=size)
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment