Skip to content

Enforce Array consistency across distributions#93

Open
gvcallen wants to merge 4 commits into
lockwo:mainfrom
gvcallen:array-consistency
Open

Enforce Array consistency across distributions#93
gvcallen wants to merge 4 commits into
lockwo:mainfrom
gvcallen:array-consistency

Conversation

@gvcallen

@gvcallen gvcallen commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@gvcallen gvcallen force-pushed the array-consistency branch from 1b6999d to c1c1c08 Compare July 6, 2026 16:29
Comment thread distreqx/distributions/_bernoulli.py Outdated
self,
logits: Optional[Array] = None,
probs: Optional[Array] = None,
logits: Optional[Union[float, Array]] = None,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

can we do | over Union. it has >3.10 anyway so this should be fine

Comment thread distreqx/distributions/_uniform.py Outdated
- `low`: Lower bound of the distribution.
- `high`: Upper bound of the distribution.
"""
self.low = jnp.asarray(low)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, yeah I thought about this but wasn't sure if you want to use Equinox fields. Will update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants