Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pytensor/tensor/random/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def explicit_expand_dims(
"""Introduce explicit expand_dims in RV parameters that are implicitly broadcasted together and/or by size."""

batch_dims = [
param.type.ndim - ndim_param for param, ndim_param in zip(params, ndim_params)
param.type.ndim - ndim_param
for param, ndim_param in zip(params, ndim_params, strict=True)
]

if size_length is not None:
Expand Down
8 changes: 6 additions & 2 deletions tests/tensor/random/test_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def test_RandomVariable_basics(strict_test_value_flags):
# `dtype` is respected
rv = RandomVariable("normal", signature="(),()->()", dtype="int32")
with config.change_flags(compute_test_value="off"):
rv_out = rv()
rv_out = rv(0, 0)
assert rv_out.dtype == "int32"
rv_out = rv(dtype="int64")
rv_out = rv(0, 0, dtype="int64")
assert rv_out.dtype == "int64"

with pytest.raises(
Expand All @@ -85,6 +85,10 @@ def test_RandomVariable_basics(strict_test_value_flags):
):
assert rv(dtype="float32").dtype == "float32"

# If we pass fewer arguments (and there are no defaults), an error is raised
with pytest.raises(ValueError):
rv(0)


def test_RandomVariable_bcast(strict_test_value_flags):
rv = RandomVariable("normal", 0, [0, 0], config.floatX, inplace=True)
Expand Down