Skip to content
Open
Changes from 1 commit
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
18 changes: 12 additions & 6 deletions pytensor/link/numba/dispatch/compile_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,28 @@ def numba_funcify_IfElse(op, **kwargs):
@numba_basic.numba_njit
def ifelse(cond, *args):
if cond:
res = args[:n_outs]
selected = args[:n_outs]
else:
res = args[n_outs:]
selected = args[n_outs:]

return res
# Return a tuple of copies
out = [None] * n_outs
for i in range(n_outs):
out[i] = selected[i].copy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only make a copy if not op.inplace


return tuple(out)

else:

@numba_basic.numba_njit
def ifelse(cond, *args):
if cond:
res = args[:n_outs]
arr = args[0]
Copy link
Member

@ricardoV94 ricardoV94 Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case can be simplified to have signature ifelse(cond, if_true, if_false), without need for indexing internally.

It's unrelated to the copy change

else:
res = args[n_outs:]
arr = args[1]

return res[0]
# Return a copy
return arr.copy()

return ifelse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ifelse
cache_version = 1
return ifelse, cache_version

We need to tell PyTensor the implementation of ifelse changed to invalidate old caches


Expand Down
Loading