cholesky

paddle.linalg. cholesky ( x, upper=False, name=None ) [source]

Computes the Cholesky decomposition of one symmetric positive-definite matrix or batches of symmetric positive-definite matrices.

If upper is True, the decomposition has the form \(A = U^{T}U\) , and the returned matrix \(U\) is upper-triangular. Otherwise, the decomposition has the form \(A = LL^{T}\) , and the returned matrix \(L\) is lower-triangular.

Parameters
  • x (Tensor) – The input tensor. Its shape should be [*, M, M], where * is zero or more batch dimensions, and matrices on the inner-most 2 dimensions all should be symmetric positive-definite. Its data type should be float32 or float64.

  • upper (bool, optional) – The flag indicating whether to return upper or lower triangular matrices. Default: False.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Tensor, A Tensor with same shape and data type as x. It represents triangular matrices generated by Cholesky decomposition.

Examples

>>> import paddle
>>> paddle.seed(2023)

>>> a = paddle.rand([3, 3], dtype="float32")
>>> a_t = paddle.transpose(a, [1, 0])
>>> x = paddle.matmul(a, a_t) + 1e-03

>>> out = paddle.linalg.cholesky(x, upper=False)
>>> print(out)
Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[1.04337072, 0.        , 0.        ],
 [1.06467664, 0.17859250, 0.        ],
 [1.30602181, 0.08326444, 0.22790681]])