Skip to content

Commit 19185cc

Browse files
Filter non-numeric types from connection_pattern
1 parent 8d34161 commit 19185cc

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pytensor/tensor/optimize.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
truncated_graph_inputs,
2323
)
2424
from pytensor.scalar import ScalarType, ScalarVariable
25+
from pytensor.sparse.variable import SparseVariable
2526
from pytensor.tensor import as_tensor_variable
2627
from pytensor.tensor.basic import (
2728
atleast_2d,
@@ -224,7 +225,13 @@ def connection_pattern(self, node=None):
224225

225226
return [
226227
[
227-
(connection and input.type.dtype in ("float32", "float64"),),
228+
(
229+
connection
230+
and isinstance(
231+
input, TensorVariable | ScalarVariable | SparseVariable
232+
)
233+
and input.type.dtype.startswith("float")
234+
),
228235
False,
229236
]
230237
for input, connection in zip(inputs, io_connection_pattern(inputs, [fx]))
@@ -422,7 +429,9 @@ def compute_implicit_gradients(
422429
)
423430

424431
# Replace inner inputs (abstract dummies) with outer inputs (the actual user-provided symbols)
425-
# at the solution point. From here on, the inner values should not be referenced.
432+
# at the solution point. Innner arguments aren't needed anymore, delete them to avoid accidental references.
433+
del inner_x
434+
del inner_args
426435
inner_to_outer_map = dict(zip(fgraph.inputs, (x_star, *args)))
427436
df_dx_star, df_dtheta_star = graph_replace(
428437
[df_dx, df_dtheta], inner_to_outer_map

tests/tensor/test_optimize.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,6 @@ def filter(self, x, **kwargs):
474474
return x
475475
raise TypeError
476476

477-
def dtype(self):
478-
return "<U64"
479-
480477
class SmileOrFrown(Op):
481478
def make_node(self, x, str_emoji):
482479
return Apply(self, [x, str_emoji], [x.type()])

0 commit comments

Comments
 (0)