From 78364477a4da25b623884ee35c4b3bc2842d2c25 Mon Sep 17 00:00:00 2001 From: Ricardo Vieira Date: Wed, 22 May 2024 18:20:47 +0200 Subject: [PATCH] Get rid of floatX_array --- pymc/pytensorf.py | 4 ---- tests/models.py | 30 +++++++++++++++--------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/pymc/pytensorf.py b/pymc/pytensorf.py index 6d44603a8c1..a4b7c7ec602 100644 --- a/pymc/pytensorf.py +++ b/pymc/pytensorf.py @@ -715,10 +715,6 @@ def generator(gen, default=None): return GeneratorOp(gen, default)() -def floatX_array(x): - return floatX(np.array(x)) - - def ix_(*args): """ PyTensor np.ix_ analog diff --git a/tests/models.py b/tests/models.py index 58f023af8f9..28a15adf06d 100644 --- a/tests/models.py +++ b/tests/models.py @@ -18,19 +18,19 @@ import pytensor import pytensor.tensor as pt +from pytensor import config from pytensor.compile.ops import as_op import pymc as pm from pymc import Categorical, Metropolis, Model, Normal -from pymc.pytensorf import floatX_array def simple_model(): mu = -2.1 tau = 1.3 with Model() as model: - Normal("x", mu, tau=tau, size=2, initval=floatX_array([0.1, 0.1])) + Normal("x", mu, tau=tau, size=2, initval=np.array([0.1, 0.1]).astype(config.floatX)) return model.initial_point(), model, (mu, tau**-0.5) @@ -43,8 +43,8 @@ def another_simple_model(): def simple_categorical(): - p = floatX_array([0.1, 0.2, 0.3, 0.4]) - v = floatX_array([0.0, 1.0, 2.0, 3.0]) + p = np.array([0.1, 0.2, 0.3, 0.4]) + v = np.array([0.0, 1.0, 2.0, 3.0]) with Model() as model: Categorical("x", p, size=3, initval=[1, 2, 3]) @@ -72,7 +72,7 @@ def arbitrary_det(value): with Model() as model: a = Normal("a") b = arbitrary_det(a) - Normal("obs", mu=b.astype("float64"), observed=floatX_array([1, 3, 5])) + Normal("obs", mu=b.astype("float64"), observed=np.array([1, 3, 5], dtype="float64")) return model.initial_point(), model @@ -94,15 +94,15 @@ def simple_2model_continuous(): def mv_simple(): - mu = floatX_array([-0.1, 0.5, 1.1]) - p = floatX_array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]]) + mu = np.array([-0.1, 0.5, 1.1]) + p = np.array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]]) tau = np.dot(p, p.T) with pm.Model() as model: pm.MvNormal( "x", pt.constant(mu), tau=pt.constant(tau), - initval=floatX_array([0.1, 1.0, 0.8]), + initval=np.array([0.1, 1.0, 0.8]), ) H = tau C = np.linalg.inv(H) @@ -110,15 +110,15 @@ def mv_simple(): def mv_simple_coarse(): - mu = floatX_array([-0.2, 0.6, 1.2]) - p = floatX_array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]]) + mu = np.array([-0.2, 0.6, 1.2]) + p = np.array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]]) tau = np.dot(p, p.T) with pm.Model() as model: pm.MvNormal( "x", pt.constant(mu), tau=pt.constant(tau), - initval=floatX_array([0.1, 1.0, 0.8]), + initval=np.array([0.1, 1.0, 0.8]), ) H = tau C = np.linalg.inv(H) @@ -126,15 +126,15 @@ def mv_simple_coarse(): def mv_simple_very_coarse(): - mu = floatX_array([-0.3, 0.7, 1.3]) - p = floatX_array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]]) + mu = np.array([-0.3, 0.7, 1.3]) + p = np.array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]]) tau = np.dot(p, p.T) with pm.Model() as model: pm.MvNormal( "x", pt.constant(mu), tau=pt.constant(tau), - initval=floatX_array([0.1, 1.0, 0.8]), + initval=np.array([0.1, 1.0, 0.8]), ) H = tau C = np.linalg.inv(H) @@ -144,7 +144,7 @@ def mv_simple_very_coarse(): def mv_simple_discrete(): d = 2 n = 5 - p = floatX_array([0.15, 0.85]) + p = np.array([0.15, 0.85]) with pm.Model() as model: pm.Multinomial("x", n, pt.constant(p), initval=np.array([1, 4])) mu = n * p