Skip to content

Commit 4ed93b1

Browse files
committed
feat: Support float32 settings in pytensor
1 parent dc261a0 commit 4ed93b1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

python/nutpie/compile_pymc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def _make_functions(model, *, mode, compute_grad, join_expanded):
483483
variables = [joined[slice_val] for slice_val in zip(joined_slices)]
484484

485485
replacements = {
486-
model.rvs_to_values[var]: value.reshape(shape) if len(shape) != 1 else value
486+
model.rvs_to_values[var]: value.reshape(shape).astype(var.dtype)
487487
for var, shape, value in zip(
488488
model.free_RVs,
489489
joined_shapes,

tests/test_pymc.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ def test_pymc_model(backend, gradient_backend):
2323
trace.posterior.a # noqa: B018
2424

2525

26+
@parameterize_backends
27+
def test_pymc_model_float32(backend, gradient_backend):
28+
import pytensor
29+
30+
with pytensor.config.change_flags(floatX="float32"):
31+
with pm.Model() as model:
32+
pm.Normal("a")
33+
34+
compiled = nutpie.compile_pymc_model(
35+
model, backend=backend, gradient_backend=gradient_backend
36+
)
37+
trace = nutpie.sample(compiled, chains=1)
38+
trace.posterior.a # noqa: B018
39+
40+
2641
@parameterize_backends
2742
def test_blocking(backend, gradient_backend):
2843
with pm.Model() as model:

0 commit comments

Comments
 (0)