torch.linalg.ldl_factor¶
- torch.linalg.ldl_factor(A, *, hermitian=False, out=None)¶
Computes a compact representation of the LDL factorization of a Hermitian or symmetric (possibly indefinite) matrix.
When
A
is complex valued it can be Hermitian (hermitian
= True) or symmetric (hermitian
= False).The factorization is of the form the form . If
hermitian
is True then transpose operation is the conjugate transpose.(or ) and are stored in compact form in
LD
. They follow the format specified by LAPACK’s sytrf function. These tensors may be used intorch.linalg.ldl_solve()
to solve linear systems.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.Note
When inputs are on a CUDA device, this function synchronizes that device with the CPU. For a version of this function that does not synchronize, see
torch.linalg.ldl_factor_ex()
.- Parameters
A (Tensor) – tensor of shape (*, n, n) where * is zero or more batch dimensions consisting of symmetric or Hermitian matrices.
- Keyword Arguments
- Returns
A named tuple (LD, pivots).
Examples:
>>> A = torch.randn(3, 3) >>> A = A @ A.mT # make symmetric >>> A tensor([[7.2079, 4.2414, 1.9428], [4.2414, 3.4554, 0.3264], [1.9428, 0.3264, 1.3823]]) >>> LD, pivots = torch.linalg.ldl_factor(A) >>> LD tensor([[ 7.2079, 0.0000, 0.0000], [ 0.5884, 0.9595, 0.0000], [ 0.2695, -0.8513, 0.1633]]) >>> pivots tensor([1, 2, 3], dtype=torch.int32)