Skip to content

Commit

Permalink
Broadcast shapes of alpha and beta in Weibull rng (pymc-devs#7288)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomicapretto authored and mkusnetsov committed Oct 26, 2024
1 parent 278889f commit 2482aad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pymc/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -2499,6 +2499,8 @@ def __call__(self, alpha, beta, size=None, **kwargs):

@classmethod
def rng_fn(cls, rng, alpha, beta, size) -> np.ndarray:
if size is None:
size = np.broadcast_shapes(alpha.shape, beta.shape)
return np.asarray(beta * rng.weibull(alpha, size=size))


Expand Down
8 changes: 8 additions & 0 deletions tests/distributions/test_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,14 @@ def seeded_weibul_rng_fn(self):
"check_rv_size",
]

def test_rng_different_shapes(self):
# See issue #7220
rng = np.random.default_rng(123)
alpha = np.abs(rng.normal(size=5))
beta = np.abs(rng.normal(size=(3, 1)))
draws = pm.draw(pm.Weibull.dist(alpha, beta), random_seed=rng)
assert len(np.unique(draws)) == draws.size


@pytest.mark.skipif(
condition=_polyagamma_not_installed,
Expand Down

0 comments on commit 2482aad

Please sign in to comment.