Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions pytensor/link/jax/dispatch/nlinalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Det,
Eig,
Eigh,
KroneckerProduct,
MatrixInverse,
MatrixPinv,
QRFull,
Expand Down Expand Up @@ -104,6 +105,14 @@ def batched_dot(a, b):
return batched_dot


@jax_funcify.register(KroneckerProduct)
def jax_funcify_KroneckerProduct(op, **kwargs):
def _kron(x, y):
return jnp.kron(x, y)

return _kron


@jax_funcify.register(Max)
def jax_funcify_Max(op, **kwargs):
axis = op.axis
Expand Down
12 changes: 12 additions & 0 deletions tests/link/jax/test_nlinalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,15 @@ def test_pinv_hermitian():
assert not np.allclose(
jax_fn(A_not_h_test), np.linalg.pinv(A_not_h_test, hermitian=True)
)


def test_kron():
x = matrix("x")
y = matrix("y")
z = pt_nlinalg.kron(x, y)

fgraph = FunctionGraph([x, y], [z])
x_np = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=config.floatX)
y_np = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=config.floatX)

compare_jax_and_py(fgraph, [x_np, y_np])