Skip to content

Numba ifelse does not copy inputs when not inplace #1761

@ricardoV94

Description

@ricardoV94

Description

This breaks the semantics of ifelse and can even cause errors when trying to mutate a global array which is non-mutable by default in numba:

import pytensor
import pytensor.tensor as pt
from pytensor.compile.mode import Mode

x = pt.vector("x")
out = pytensor.ifelse(x.sum() > 0, x, x)
fn = pytensor.function([x], out, mode=Mode("numba", optimizer=None))
fn.dprint(print_memory_map=True)  # Not a view
# if{} [id A] 2
#  ├─ Gt [id B] 1
#  │  ├─ Sum{axes=None} [id C] 0
#  │  │  └─ x [id D]
#  │  └─ 0 [id E]
#  ├─ x [id D]
#  └─ x [id D]
x_test = np.zeros((5,))
assert fn(x_test) is not x_test  # Fails

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnumba

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions