Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make random wrapping more robust to changes in jax.random #43

Merged
merged 1 commit into from
Oct 13, 2021
Merged
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
20 changes: 7 additions & 13 deletions scico/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,16 @@ def _wrap(fun):
return fun_wrapped


exceptions = [ # these do not take key and shape
"PRNGKey",
"double_sided_maxwell",
"fold_in",
"permutation",
"shuffle",
"split",
"weibull_min",
"threefry_2x32",
]
def _is_wrappable(fun):
params = inspect.signature(getattr(jax.random, fun)).parameters
return list(params.keys())[0] == "key" and "shape" in params.keys()


func_names = [
t[0] for t in inspect.getmembers(jax.random, inspect.isfunction) if t[0] not in exceptions
wrappable_func_names = [
t[0] for t in inspect.getmembers(jax.random, inspect.isfunction) if _is_wrappable(t[0])
]

for name in func_names:
for name in wrappable_func_names:
setattr(sys.modules[__name__], name, _wrap(getattr(jax.random, name)))


Expand Down