Skip to content

Commit 9b522a8

Browse files
committed
Suppress numpy warnings in python implementation of Elemwise
1 parent d87d44c commit 9b522a8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pytensor/tensor/elemwise.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,8 @@ def perform(self, node, inputs, output_storage):
707707

708708
nout = ufunc.nout
709709

710-
variables = ufunc(*ufunc_args, **ufunc_kwargs)
710+
with np.errstate(all="ignore"):
711+
variables = ufunc(*ufunc_args, **ufunc_kwargs)
711712

712713
if nout == 1:
713714
variables = [variables]

tests/tensor/test_elemwise.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,3 +1093,11 @@ def L_op(self, inputs, outputs, output_gradients):
10931093
np.ones((12,), dtype=config.floatX),
10941094
strict=True,
10951095
)
1096+
1097+
1098+
@pytest.mark.filterwarnings("error")
1099+
def test_numpy_warning_suppressed():
1100+
x = pt.scalar("x")
1101+
y = pt.log(x)
1102+
fn = pytensor.function([x], y, mode=Mode(linker="py"))
1103+
assert fn(0) == -np.inf

0 commit comments

Comments
 (0)