-
Notifications
You must be signed in to change notification settings - Fork 149
Open
Labels
Description
Description
import numpy as np
import pytensor
import pytensor.tensor as pt
from pytensor.graph.basic import Apply
from pytensor.scalar import ScalarOp
from pytensor.tensor.elemwise import Elemwise
from pytensor.tensor.blockwise import Blockwise
class ScalarOp(ScalarOp):
def make_node(self, x):
return Apply(self, [x], [x.type()])
def perform(self, node, inputs, outputs):
[x] = inputs
outputs[0][0] = x + 1
x = pt.vector("x")
y = Elemwise(ScalarOp())(x)
fn = pytensor.function([x], y, mode="NUMBA")
# UserWarning: Numba will use object mode to run ScalarOp's perform method
np.testing.assert_allclose(fn(np.zeros((3,))), [1, 1, 1])
x = pt.vector("x")
z = Blockwise(ScalarOp(), signature="()->()")(x)
# UserWarning: Numba will use object mode to run ScalarOp's perform method
fn = pytensor.function([x], z, mode="NUMBA")
fn(np.zeros((3,))) # TypeError: can't unbox array from PyObject into native value. The object maybe of a different typeBlockwise is different than Elemwise in that it gets wrapped in a BlockwiseWithCoreShape, which is an OpFromGraph. So the failure may be more general to OpFromGraph