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

Made sample_shape same across all contexts in draw_values #4305

Merged
merged 6 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## PyMC3 3.10.x

### Maintenance
- Make `sample_shape` same across all contexts in `draw_values` (see [#4305](https://github.com/pymc-devs/pymc3/pull/4305)).

## PyMC3 3.10.0 (7 December 2020)

This is a major release with many exciting new features. The biggest change is that we now rely on our own fork of [Theano-PyMC](https://github.com/pymc-devs/Theano-PyMC). This is in line with our [big announcement about our commitment to PyMC3 and Theano](https://pymc-devs.medium.com/the-future-of-pymc3-or-theano-is-dead-long-live-theano-d8005f8a0e9b).
Expand Down
1 change: 1 addition & 0 deletions pymc3/distributions/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ def draw_values(params, point=None, size=None):
"""
# The following check intercepts and redirects calls to
# draw_values in the context of sample_posterior_predictive
size = to_tuple(size)
ppc_sampler = vectorized_ppc.get(None)
if ppc_sampler is not None:
# this is being done inside new, vectorized sample_posterior_predictive
Expand Down
7 changes: 4 additions & 3 deletions pymc3/distributions/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from scipy.spatial import cKDTree

from pymc3.distributions.distribution import NoDistribution, draw_values
from pymc3.distributions.distribution import NoDistribution, draw_values, to_tuple

__all__ = ["Simulator"]

Expand Down Expand Up @@ -114,11 +114,12 @@ def random(self, point=None, size=None):
-------
array
"""
size = to_tuple(size)
params = draw_values([*self.params], point=point, size=size)
if size is None:
if len(size) == 0:
return self.function(*params)
else:
return np.array([self.function(*params) for _ in range(size)])
return np.array([self.function(*params) for _ in range(size[0])])

def _str_repr(self, name=None, dist=None, formatting="plain"):
if dist is None:
Expand Down
4 changes: 4 additions & 0 deletions pymc3/tests/test_distributions_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,10 @@ def test_issue_3758(self):
for var in "abcd":
assert not np.isnan(np.std(samples[var]))

for var in "bcd":
std = np.std(samples[var] - samples["a"])
np.testing.assert_allclose(std, 1, rtol=1e-2)

def test_issue_3829(self):
with pm.Model() as model:
x = pm.MvNormal("x", mu=np.zeros(5), cov=np.eye(5), shape=(2, 5))
Expand Down