torch.linalg.slogdet(A, *, out=None)

Computes the sign and natural logarithm of the absolute value of the determinant of a square matrix.

For complex A, it returns the angle and the natural logarithm of the modulus of the determinant, that is, a logarithmic polar decomposition of the determinant.

The determinant can be recovered as sign * exp(logabsdet). When a matrix has a determinant of zero, it returns (0, -inf).

Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if A is a batch of matrices then the output has the same batch dimensions.

See also

torch.linalg.det() computes the determinant of square matrices.


A (Tensor) – tensor of shape (*, n, n) where * is zero or more batch dimensions.

Keyword Arguments:

out (tuple, optional) – output tuple of two tensors. Ignored if None. Default: None.


A named tuple (sign, logabsdet).

sign will have the same dtype as A.

logabsdet will always be real-valued, even when A is complex.


>>> A = torch.randn(3, 3)
>>> A
tensor([[ 0.0032, -0.2239, -1.1219],
        [-0.6690,  0.1161,  0.4053],
        [-1.6218, -0.9273, -0.0082]])
>>> torch.linalg.det(A)
>>> torch.logdet(A)
>>> torch.linalg.slogdet(A)
torch.return_types.linalg_slogdet(sign=tensor(-1.), logabsdet=tensor(-0.2776))


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources