Skip to content
Open
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
14 changes: 13 additions & 1 deletion pytensor/link/jax/dispatch/tensor_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,20 @@ def allocempty(*shape):

@jax_funcify.register(Alloc)
def jax_funcify_Alloc(op, node, **kwargs):
static_shapes = []
for shape_input in node.inputs[1:]:
try:
static_shapes.append(int(get_scalar_constant_value(shape_input)))
except NotScalarConstantError:
concrete_shape = None
break
else:
concrete_shape = tuple(static_shapes)

def alloc(x, *shape):
res = jnp.broadcast_to(x, shape)
res = jnp.broadcast_to(
x, concrete_shape if concrete_shape is not None else shape
)
Alloc._check_runtime_broadcast(node, jnp.asarray(x), res.shape)
return res

Expand Down
Loading