Skip to content

Commit

Permalink
Fix bug in nlinalg.slogdet and expose it in linalg module (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
theorashid committed Jun 6, 2024
1 parent 086323f commit 4b6a444
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pytensor/tensor/nlinalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def perform(self, node, inputs, outputs):
(x,) = inputs
(sign, det) = outputs
try:
sign[0], det[0] = (z.astype(x.dtype) for z in np.linalg.slogdet(x))
sign[0], det[0] = (np.array(z, dtype=x.dtype) for z in np.linalg.slogdet(x))
except Exception:
print("Failed to compute determinant", x)
raise
Expand Down Expand Up @@ -1186,6 +1186,7 @@ def kron(a, b):
"lstsq",
"matrix_power",
"norm",
"slogdet",
"tensorinv",
"tensorsolve",
"kron",
Expand Down
5 changes: 5 additions & 0 deletions tests/tensor/test_nlinalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ def test_slogdet():
sign, det = np.linalg.slogdet(r)
assert np.equal(sign, f_sign)
assert np.allclose(det, f_det)
# check numpy array types is returned
# see https://github.com/pymc-devs/pytensor/issues/799
sign, logdet = slogdet(x)
det = sign * pytensor.tensor.exp(logdet)
assert_array_almost_equal(det.eval({x: [[1]]}), np.array(1.0))


def test_trace():
Expand Down

0 comments on commit 4b6a444

Please sign in to comment.