From 0f9cb03d303fbbfddb7d99006119e36aa77bafc4 Mon Sep 17 00:00:00 2001 From: Danni Li Date: Fri, 7 Jul 2023 12:08:38 -0700 Subject: [PATCH] [Doc] Add `Tensor.Shape` (#104750) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/104750 Add `Tensor.Shape` doc. Ref: - https://github.com/pytorch/pytorch/issues/5544 - https://github.com/pytorch/pytorch/issues/1980 Differential Revision: D47278630 fbshipit-source-id: b549a68eb632f46db921fd5ae89ad58767a880a4 --- docs/source/tensors.rst | 1 + torch/_tensor_docs.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/docs/source/tensors.rst b/docs/source/tensors.rst index 941f8136cf5b7..fc9f93b454f52 100644 --- a/docs/source/tensors.rst +++ b/docs/source/tensors.rst @@ -622,6 +622,7 @@ Tensor class reference Tensor.asinh_ Tensor.arcsinh Tensor.arcsinh_ + Tensor.shape Tensor.size Tensor.slogdet Tensor.slice_scatter diff --git a/torch/_tensor_docs.py b/torch/_tensor_docs.py index bdd635629259c..52f40fd2f8450 100644 --- a/torch/_tensor_docs.py +++ b/torch/_tensor_docs.py @@ -4727,6 +4727,27 @@ def callable(a, b) -> number """, ) +add_docstr_all( + "shape", + r""" +shape() -> torch.Size + +Returns the size of the :attr:`self` tensor. Tensor :attr:`shape` is the alias for :attr:`size`. +It was added for consistency with NumPy. + +See also :meth:`Tensor.size`. + +Example:: + + >>> t = torch.empty(3, 4, 5) + >>> t.size() + torch.Size([3, 4, 5]) + >>> t.shape + torch.Size([3, 4, 5]) + +""", +) + add_docstr_all( "sort", r"""