From a7c2d85c18e8810095a807465ed722c0db6bcfd3 Mon Sep 17 00:00:00 2001 From: Jackson Date: Fri, 31 Jan 2025 15:53:59 +0000 Subject: [PATCH] Add overloads to diagonal docs (#144214) Fixes #126827. Refactored doc to demonstrate when none of the optional values are passed in. Added another example so that all overloads of the function are covered. Pull Request resolved: https://github.com/pytorch/pytorch/pull/144214 Approved by: https://github.com/albanD --- torch/_torch_docs.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/torch/_torch_docs.py b/torch/_torch_docs.py index 57009deb20c..c52ef658697 100644 --- a/torch/_torch_docs.py +++ b/torch/_torch_docs.py @@ -3611,13 +3611,20 @@ Examples:: [ 0.6927, -0.3735, -0.4945]]) - >>> torch.diagonal(a, 0) + >>> torch.diagonal(a) tensor([-1.0854, -0.0905, -0.4945]) >>> torch.diagonal(a, 1) tensor([ 1.1431, 0.0360]) + >>> b = torch.randn(2, 5) + >>> b + tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745], + [ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]]) + + >>> torch.diagonal(b, 1, 1, 0) + tensor([1.8262]) >>> x = torch.randn(2, 5, 4, 2) >>> torch.diagonal(x, offset=-1, dim1=1, dim2=2)