Enforce Array consistency across distributions#93
Open
gvcallen wants to merge 4 commits into
Open
Conversation
Uniform had no __init__ at all, so `low`/`high` were stored as whatever was passed in (e.g. bare Python floats) instead of being cast to jax arrays like Normal, Beta, Gamma, etc. already do. Bernoulli/Categorical/ OneHotCategorical actively rejected non-jax-array probs/logits via an isinstance check instead of casting them, and the four MultivariateNormal classes accessed .shape/.ndim on loc/scale/covariance before casting, crashing with AttributeError for plain floats or lists. Cast inputs to arrays up front in all of these, matching the existing convention, so construction behaves consistently across the library regardless of whether callers pass raw Python numbers/lists or arrays.
1b6999d to
c1c1c08
Compare
lockwo
reviewed
Jul 6, 2026
| self, | ||
| logits: Optional[Array] = None, | ||
| probs: Optional[Array] = None, | ||
| logits: Optional[Union[float, Array]] = None, |
Owner
There was a problem hiding this comment.
can we do | over Union. it has >3.10 anyway so this should be fine
| - `low`: Lower bound of the distribution. | ||
| - `high`: Upper bound of the distribution. | ||
| """ | ||
| self.low = jnp.asarray(low) |
Owner
There was a problem hiding this comment.
for these ones (where we don't have like an if none for the other), we can make this nice with a low: Float[Array, "..."] = eqx.field(converter=jnp.asarray) (or something very close to that)
Contributor
Author
There was a problem hiding this comment.
Ah, yeah I thought about this but wasn't sure if you want to use Equinox fields. Will update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some distributions cast inputs to arrays during initialization (e.g.
Normal) while others do not (e.g.Uniform). This PR ensures that all distribution fields are arrays across all distributions.