From 30040cd643f76c68ec7e0be288cf7073e2c45c49 Mon Sep 17 00:00:00 2001 From: Michael Osthege Date: Wed, 15 Sep 2021 13:33:51 +0200 Subject: [PATCH] Add regression tests for #4993 --- pymc3/tests/test_initvals.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pymc3/tests/test_initvals.py b/pymc3/tests/test_initvals.py index 0e9232681d..cfaf163172 100644 --- a/pymc3/tests/test_initvals.py +++ b/pymc3/tests/test_initvals.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import aesara.tensor as at import numpy as np import pytest @@ -92,6 +93,27 @@ def test_automatically_assigned_test_values(self): assert hasattr(rv.tag, "test_value") pass + @pytest.mark.parametrize("rv_cls", [pm.Flat, pm.HalfFlat]) + def test_initval_shape(self, rv_cls): + rv = rv_cls.dist(shape=(2,)) + assert np.shape(rv.tag.test_value) == (2,) + # Can't set numeric test values when dimensionality is symbolic + rv = rv_cls.dist(shape=(at.scalar(),)) + assert rv.tag.test_value is None + pass + + @pytest.mark.parametrize("rv_cls", [pm.Flat, pm.HalfFlat]) + def test_initval_dims(self, rv_cls): + with pm.Model( + coords={ + "year": [2019, 2020, 2021], + } + ) as pmodel: + rv = rv_cls("rv", dims=("year",)) + # Can't set numeric test values when dimensionality is symbolic + assert rv.tag.test_value is None + pass + class TestMoment: def test_basic(self):