diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 46e334f60c..2045d51f2d 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` no longer downcasts integers unnecessarily (see [#4569](https://github.com/pymc-devs/pymc3/pull/4569)) ## PyMC3 3.11.1 (12 February 2021) 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) 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) 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)