Skip to content
Merged
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
5 changes: 5 additions & 0 deletions pytensor/tensor/rewriting/elemwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,11 @@ def elemwise_scalar_op_has_c_code(node: Apply) -> bool:
fuseable_clients: FUSEABLE_MAPPING = defaultdict(list)
unfuseable_clients: UNFUSEABLE_MAPPING = defaultdict(set)
for out, clients in fg.clients.items():
# Old FunctionGraph nodes remain in the clients dictionary
# even after they are removed by rewrites
if not clients:
continue

out_maybe_fuseable = (
out.owner
and isinstance(out.owner.op, Elemwise)
Expand Down
18 changes: 18 additions & 0 deletions tests/tensor/rewriting/test_elemwise.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import numpy as np
import pytest

Expand Down Expand Up @@ -36,6 +38,7 @@
invert,
iround,
log,
log1mexp,
log2,
log10,
mul,
Expand Down Expand Up @@ -1370,6 +1373,21 @@ def rewrite_func():

assert benchmark(rewrite_func) == 103

def test_no_warning_from_old_client(self):
# There used to be a warning issued when creating fuseable mapping
# for nodes that are no longer in the FunctionGraph
with warnings.catch_warnings():
warnings.simplefilter("error")
# The -2 integer array cannot be passed directly to the C method
# of log1mexp as that can only handle floats. There is a rewrite
# that casts it to a float, but the FunctionGraph client retains
# the original log1mexp of the integer input, which caused
# a misleading warning for non C implementation in the FusionRewrite
assert np.isclose(
log1mexp(np.array(-2, dtype="int64")).eval(),
np.log(1 - np.exp(-2)),
)


class TimesN(aes.basic.UnaryScalarOp):
"""
Expand Down