Skip to content

Commit

Permalink
Get rid of floatX_array
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoV94 committed May 23, 2024
1 parent 85a1e36 commit 7836447
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
4 changes: 0 additions & 4 deletions pymc/pytensorf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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])

Expand Down Expand Up @@ -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

Expand All @@ -94,47 +94,47 @@ 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)
return model.initial_point(), model, (mu, C)


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)
return model.initial_point(), model, (mu, C)


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)
Expand All @@ -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
Expand Down

0 comments on commit 7836447

Please sign in to comment.