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

Refactor argument validation? #1865

Closed
tillahoffmann opened this issue Sep 23, 2024 · 1 comment
Closed

Refactor argument validation? #1865

tillahoffmann opened this issue Sep 23, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@tillahoffmann
Copy link
Contributor

What are your thoughts on refactoring the argument validation code below into a separate method validate_args() (or another name) so it can be invoked on an existing instance? The motivation is that I often have jitted functions that return distribution instances which I would like to validate.

if self._validate_args:
for param, constraint in self.arg_constraints.items():
if param not in self.__dict__ and isinstance(
getattr(type(self), param), lazy_property
):
continue
if constraints.is_dependent(constraint):
continue # skip constraints that cannot be checked
is_valid = constraint(getattr(self, param))
if not_jax_tracer(is_valid):
if not np.all(is_valid):
raise ValueError(
"{} distribution got invalid {} parameter.".format(
self.__class__.__name__, param
)
)

@fehiepsi
Copy link
Member

Yup, exposing that method would be convenient.

@fehiepsi fehiepsi added the enhancement New feature or request label Sep 23, 2024
tillahoffmann added a commit to tillahoffmann/numpyro that referenced this issue Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants