From 6631803c82afecd9713cdbc87582d5adb35815cc Mon Sep 17 00:00:00 2001 From: Maxim Kochurov Date: Fri, 26 Mar 2021 07:48:50 +0000 Subject: [PATCH 1/6] add type guard for inX --- pymc3/theanof.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pymc3/theanof.py b/pymc3/theanof.py index 50ab8afdaf..7f22ce6f38 100644 --- a/pymc3/theanof.py +++ b/pymc3/theanof.py @@ -93,6 +93,9 @@ def intX(X): """ Convert a theano tensor or numpy array to theano.tensor.int32 type. """ + # check value is already int, do nothing in this case + if (hasattr(X, "dtype") and "int" in str(X.dtype)) or isinstance(X, int): + return X intX = _conversion_map[theano.config.floatX] try: return X.astype(intX) From e61ad341199f340f4ddc719012c8a6aa16a442fc Mon Sep 17 00:00:00 2001 From: Maxim Kochurov Date: Sun, 11 Apr 2021 08:17:07 +0000 Subject: [PATCH 2/6] fix test for pandas --- pymc3/tests/test_model_helpers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pymc3/tests/test_model_helpers.py b/pymc3/tests/test_model_helpers.py index 20745febad..d4198270a4 100644 --- a/pymc3/tests/test_model_helpers.py +++ b/pymc3/tests/test_model_helpers.py @@ -82,7 +82,7 @@ def test_pandas_to_array(self, input_dtype): assert isinstance(theano_output, theano.graph.basic.Variable) npt.assert_allclose(theano_output.eval(), theano_graph_input.eval()) intX = pm.theanof._conversion_map[theano.config.floatX] - if dense_input.dtype == intX or dense_input.dtype == theano.config.floatX: + if "int" in str(dense_input.dtype) or dense_input.dtype == theano.config.floatX: assert theano_output.owner is None # func should not have added new nodes assert theano_output.name == input_name else: @@ -92,7 +92,8 @@ def test_pandas_to_array(self, input_dtype): if "float" in input_dtype: assert theano_output.dtype == theano.config.floatX else: - assert theano_output.dtype == intX + # only cast floats, leave ints as is + assert theano_output.dtype == input_dtype # Check function behavior with generator data generator_output = func(square_generator) From fe96b5c96fe9c408530ef49cd25dac4948dfc9ac Mon Sep 17 00:00:00 2001 From: Maxim Kochurov Date: Sun, 11 Apr 2021 08:27:15 +0000 Subject: [PATCH 3/6] fix posterior test, ints passed for float data --- pymc3/tests/test_data_container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc3/tests/test_data_container.py b/pymc3/tests/test_data_container.py index 966ce47cd6..e1914f1e57 100644 --- a/pymc3/tests/test_data_container.py +++ b/pymc3/tests/test_data_container.py @@ -78,7 +78,7 @@ def test_sample_posterior_predictive_after_set_data(self): trace = pm.sample(1000, tune=1000, chains=1) # Predict on new data. with model: - x_test = [5, 6, 9] + x_test = [5.0, 6.0, 9.0] pm.set_data(new_data={"x": x_test}) y_test = pm.sample_posterior_predictive(trace) y_test1 = pm.fast_sample_posterior_predictive(trace) From bf23086557278fb5e2b43b221f44fb46db5c8489 Mon Sep 17 00:00:00 2001 From: Maxim Kochurov Date: Sun, 11 Apr 2021 10:29:26 +0000 Subject: [PATCH 4/6] release notes --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 46e334f60c..c0efa9587d 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -19,6 +19,7 @@ - `pm.make_shared_replacements` now retains broadcasting information which fixes issues with Metropolis samplers (see [#4492](https://github.com/pymc-devs/pymc3/pull/4492)). **Release manager** for 3.11.2: Michael Osthege ([@michaelosthege](https://github.com/michaelosthege)) +- `pm.intX` did bad job with downcasting integers. It is fixed in [#4569](https://github.com/pymc-devs/pymc3/pull/4569). ## PyMC3 3.11.1 (12 February 2021) From 3b4d0c807bedec8c54aec20efed7dbe8ec418747 Mon Sep 17 00:00:00 2001 From: Maxim Kochurov Date: Mon, 12 Apr 2021 10:09:01 +0300 Subject: [PATCH 5/6] Update RELEASE-NOTES.md --- RELEASE-NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index c0efa9587d..4c0c1ec7b7 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -19,7 +19,7 @@ - `pm.make_shared_replacements` now retains broadcasting information which fixes issues with Metropolis samplers (see [#4492](https://github.com/pymc-devs/pymc3/pull/4492)). **Release manager** for 3.11.2: Michael Osthege ([@michaelosthege](https://github.com/michaelosthege)) -- `pm.intX` did bad job with downcasting integers. It is fixed in [#4569](https://github.com/pymc-devs/pymc3/pull/4569). +- `pm.intX` did bad job with downcasting integers. It is fixed in [#4569](https://github.com/pymc-devs/pymc3/pull/4569). ## PyMC3 3.11.1 (12 February 2021) From efe506a4727d88f28ce5b4e16a2a0d35830cb264 Mon Sep 17 00:00:00 2001 From: Maxim Kochurov Date: Mon, 12 Apr 2021 10:19:13 +0300 Subject: [PATCH 6/6] Update RELEASE-NOTES.md --- RELEASE-NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 4c0c1ec7b7..2045d51f2d 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -19,7 +19,7 @@ - `pm.make_shared_replacements` now retains broadcasting information which fixes issues with Metropolis samplers (see [#4492](https://github.com/pymc-devs/pymc3/pull/4492)). **Release manager** for 3.11.2: Michael Osthege ([@michaelosthege](https://github.com/michaelosthege)) -- `pm.intX` did bad job with downcasting integers. It is fixed in [#4569](https://github.com/pymc-devs/pymc3/pull/4569). +- `pm.intX` no longer downcasts integers unnecessarily (see [#4569](https://github.com/pymc-devs/pymc3/pull/4569)) ## PyMC3 3.11.1 (12 February 2021)