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
6 changes: 5 additions & 1 deletion pytensor/tensor/nlinalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def make_node(self, x):
out_dtype = "float64"
else:
out_dtype = x.dtype
return Apply(self, [x], [matrix(shape=x.type.shape, dtype=out_dtype)])
return Apply(
self,
[x],
[matrix(shape=(x.type.shape[1], x.type.shape[0]), dtype=out_dtype)],
)

def perform(self, node, inputs, outputs):
(x,) = inputs
Expand Down
15 changes: 15 additions & 0 deletions tests/tensor/test_nlinalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ def test_pseudoinverse_grad():
utt.verify_grad(pinv, [r])


def test_pseudoinverse_static_shape():
x = matrix(shape=(3, 5))
z = pinv(x)
assert z.type.shape == (5, 3)

g = pytensor.grad(z.sum(), x)
f = function([x], g)

rng = np.random.default_rng(utt.fetch_seed())
r = rng.standard_normal((3, 5)).astype(config.floatX)
assert f(r).shape == (3, 5)

utt.verify_grad(pinv, [r])


class TestMatrixInverse(utt.InferShapeTester):
def setup_method(self):
super().setup_method()
Expand Down
Loading