Skip to content

Commit b953c40

Browse files
Sayam753twiecki
andauthored
Made sample_shape same across all contexts in draw_values (#4305)
* Made sample_shape same across all contexts, thereby resolves #3758 * Pass the failing test * Worked on suggestions * Used to_tuple for size * Given a mention in release notes * Update RELEASE-NOTES.md Co-authored-by: Thomas Wiecki <[email protected]>
1 parent 4fd56fd commit b953c40

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

Diff for: RELEASE-NOTES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes
22

3+
## PyMC3 3.10.1 (on deck)
4+
5+
### Maintenance
6+
- Make `sample_shape` same across all contexts in `draw_values` (see [#4305](https://github.com/pymc-devs/pymc3/pull/4305)).
7+
38
## PyMC3 3.10.0 (7 December 2020)
49

510
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).

Diff for: pymc3/distributions/distribution.py

+1
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ def draw_values(params, point=None, size=None):
690690
"""
691691
# The following check intercepts and redirects calls to
692692
# draw_values in the context of sample_posterior_predictive
693+
size = to_tuple(size)
693694
ppc_sampler = vectorized_ppc.get(None)
694695
if ppc_sampler is not None:
695696
# this is being done inside new, vectorized sample_posterior_predictive

Diff for: pymc3/distributions/simulator.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from scipy.spatial import cKDTree
2020

21-
from pymc3.distributions.distribution import NoDistribution, draw_values
21+
from pymc3.distributions.distribution import NoDistribution, draw_values, to_tuple
2222

2323
__all__ = ["Simulator"]
2424

@@ -114,11 +114,12 @@ def random(self, point=None, size=None):
114114
-------
115115
array
116116
"""
117+
size = to_tuple(size)
117118
params = draw_values([*self.params], point=point, size=size)
118-
if size is None:
119+
if len(size) == 0:
119120
return self.function(*params)
120121
else:
121-
return np.array([self.function(*params) for _ in range(size)])
122+
return np.array([self.function(*params) for _ in range(size[0])])
122123

123124
def _str_repr(self, name=None, dist=None, formatting="plain"):
124125
if dist is None:

Diff for: pymc3/tests/test_distributions_random.py

+4
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,10 @@ def test_issue_3758(self):
16641664
for var in "abcd":
16651665
assert not np.isnan(np.std(samples[var]))
16661666

1667+
for var in "bcd":
1668+
std = np.std(samples[var] - samples["a"])
1669+
np.testing.assert_allclose(std, 1, rtol=1e-2)
1670+
16671671
def test_issue_3829(self):
16681672
with pm.Model() as model:
16691673
x = pm.MvNormal("x", mu=np.zeros(5), cov=np.eye(5), shape=(2, 5))

0 commit comments

Comments
 (0)