Skip to content

Commit 33b0e2c

Browse files
committed
Get rid of floatX_array
1 parent c4a081e commit 33b0e2c

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

pymc/pytensorf.py

-4
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,6 @@ def generator(gen, default=None):
715715
return GeneratorOp(gen, default)()
716716

717717

718-
def floatX_array(x):
719-
return floatX(np.array(x))
720-
721-
722718
def ix_(*args):
723719
"""
724720
PyTensor np.ix_ analog

tests/models.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
import pytensor
1919
import pytensor.tensor as pt
2020

21+
from pytensor import config
2122
from pytensor.compile.ops import as_op
2223

2324
import pymc as pm
2425

2526
from pymc import Categorical, Metropolis, Model, Normal
26-
from pymc.pytensorf import floatX_array
2727

2828

2929
def simple_model():
3030
mu = -2.1
3131
tau = 1.3
3232
with Model() as model:
33-
Normal("x", mu, tau=tau, size=2, initval=floatX_array([0.1, 0.1]))
33+
Normal("x", mu, tau=tau, size=2, initval=np.array([0.1, 0.1]).astype(config.floatX))
3434

3535
return model.initial_point(), model, (mu, tau**-0.5)
3636

@@ -43,8 +43,8 @@ def another_simple_model():
4343

4444

4545
def simple_categorical():
46-
p = floatX_array([0.1, 0.2, 0.3, 0.4])
47-
v = floatX_array([0.0, 1.0, 2.0, 3.0])
46+
p = np.array([0.1, 0.2, 0.3, 0.4])
47+
v = np.array([0.0, 1.0, 2.0, 3.0])
4848
with Model() as model:
4949
Categorical("x", p, size=3, initval=[1, 2, 3])
5050

@@ -72,7 +72,7 @@ def arbitrary_det(value):
7272
with Model() as model:
7373
a = Normal("a")
7474
b = arbitrary_det(a)
75-
Normal("obs", mu=b.astype("float64"), observed=floatX_array([1, 3, 5]))
75+
Normal("obs", mu=b.astype("float64"), observed=np.array([1, 3, 5], dtype="float64"))
7676

7777
return model.initial_point(), model
7878

@@ -94,47 +94,47 @@ def simple_2model_continuous():
9494

9595

9696
def mv_simple():
97-
mu = floatX_array([-0.1, 0.5, 1.1])
98-
p = floatX_array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]])
97+
mu = np.array([-0.1, 0.5, 1.1])
98+
p = np.array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]])
9999
tau = np.dot(p, p.T)
100100
with pm.Model() as model:
101101
pm.MvNormal(
102102
"x",
103103
pt.constant(mu),
104104
tau=pt.constant(tau),
105-
initval=floatX_array([0.1, 1.0, 0.8]),
105+
initval=np.array([0.1, 1.0, 0.8]),
106106
)
107107
H = tau
108108
C = np.linalg.inv(H)
109109
return model.initial_point(), model, (mu, C)
110110

111111

112112
def mv_simple_coarse():
113-
mu = floatX_array([-0.2, 0.6, 1.2])
114-
p = floatX_array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]])
113+
mu = np.array([-0.2, 0.6, 1.2])
114+
p = np.array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]])
115115
tau = np.dot(p, p.T)
116116
with pm.Model() as model:
117117
pm.MvNormal(
118118
"x",
119119
pt.constant(mu),
120120
tau=pt.constant(tau),
121-
initval=floatX_array([0.1, 1.0, 0.8]),
121+
initval=np.array([0.1, 1.0, 0.8]),
122122
)
123123
H = tau
124124
C = np.linalg.inv(H)
125125
return model.initial_point(), model, (mu, C)
126126

127127

128128
def mv_simple_very_coarse():
129-
mu = floatX_array([-0.3, 0.7, 1.3])
130-
p = floatX_array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]])
129+
mu = np.array([-0.3, 0.7, 1.3])
130+
p = np.array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]])
131131
tau = np.dot(p, p.T)
132132
with pm.Model() as model:
133133
pm.MvNormal(
134134
"x",
135135
pt.constant(mu),
136136
tau=pt.constant(tau),
137-
initval=floatX_array([0.1, 1.0, 0.8]),
137+
initval=np.array([0.1, 1.0, 0.8]),
138138
)
139139
H = tau
140140
C = np.linalg.inv(H)
@@ -144,7 +144,7 @@ def mv_simple_very_coarse():
144144
def mv_simple_discrete():
145145
d = 2
146146
n = 5
147-
p = floatX_array([0.15, 0.85])
147+
p = np.array([0.15, 0.85])
148148
with pm.Model() as model:
149149
pm.Multinomial("x", n, pt.constant(p), initval=np.array([1, 4]))
150150
mu = n * p

0 commit comments

Comments
 (0)