Skip to content

Commit

Permalink
Extend explanation of torch.cholesky_inverse to consider batched in…
Browse files Browse the repository at this point in the history
…puts. (#69069)

Summary:
While implementing #68720,
We found out empirically that `torch.cholesky_inverse` support batched inputs, but it is not explained in doc: [link](#68720 (review))
`torch.cholesky_inverse` is implemented in #50269 and the doc was updated at #31275 but not merged.
neerajprad

Pull Request resolved: #69069

Reviewed By: mrshenli

Differential Revision: D32979362

Pulled By: neerajprad

fbshipit-source-id: 0967c969434ce6e0ab15889c240149c23c0bce44
  • Loading branch information
nonconvexopt authored and facebook-github-bot committed Dec 9, 2021
1 parent 9ad05f2 commit e963b43
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions torch/_torch_docs.py
Expand Up @@ -2223,7 +2223,7 @@ def merge_dicts(*dicts):
tensor([[ 2.4112, -0.7486, 1.4551],
[-0.7486, 1.3544, 0.1294],
[ 1.4551, 0.1294, 1.6724]])
>>> a = torch.randn(3, 2, 2)
>>> a = torch.randn(3, 2, 2) # Example for batched input
>>> a = a @ a.mT + 1e-03 # make symmetric positive-definite
>>> l = torch.cholesky(a)
>>> z = l @ l.mT
Expand Down Expand Up @@ -2272,7 +2272,7 @@ def merge_dicts(*dicts):
>>> a = torch.randn(3, 3)
>>> a = torch.mm(a, a.t()) # make symmetric positive definite
>>> u = torch.cholesky(a)
>>> u = torch.linalg.cholesky(a)
>>> a
tensor([[ 0.7747, -1.9549, 1.3086],
[-1.9549, 6.7546, -5.4114],
Expand Down Expand Up @@ -2311,10 +2311,15 @@ def merge_dicts(*dicts):
.. math::
inv = (u^T u)^{{-1}}
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :math:`A` is a batch of matrices then the output has the same batch dimensions.
Args:
input (Tensor): the input 2-D tensor :math:`u`, a upper or lower triangular
Cholesky factor
upper (bool, optional): whether to return a lower (default) or upper triangular matrix
input (Tensor): the input tensor :math:`A` of size :math:`(*, n, n)`,
consisting of symmetric positive-definite matrices
where :math:`*` is zero or more batch dimensions.
upper (bool, optional): flag that indicates whether to return a
upper or lower triangular matrix. Default: False
Keyword args:
out (Tensor, optional): the output tensor for `inv`
Expand All @@ -2323,7 +2328,7 @@ def merge_dicts(*dicts):
>>> a = torch.randn(3, 3)
>>> a = torch.mm(a, a.t()) + 1e-05 * torch.eye(3) # make symmetric positive definite
>>> u = torch.cholesky(a)
>>> u = torch.linalg.cholesky(a)
>>> a
tensor([[ 0.9935, -0.6353, 1.5806],
[ -0.6353, 0.8769, -1.7183],
Expand All @@ -2336,6 +2341,12 @@ def merge_dicts(*dicts):
tensor([[ 1.9314, 1.2251, -0.0889],
[ 1.2251, 2.4439, 0.2122],
[-0.0889, 0.2122, 0.1412]])
>>> a = torch.randn(3, 2, 2) # Example for batched input
>>> a = a @ a.mT + 1e-03 # make symmetric positive-definite
>>> l = torch.linalg.cholesky(a)
>>> z = l @ l.mT
>>> torch.dist(z, a)
tensor(3.5894e-07)
""")

add_docstr(torch.clone, r"""
Expand Down

0 comments on commit e963b43

Please sign in to comment.