mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Everything here is a grep except the changes in tools/autograd/load_derivatives.py which I manually corrected. The correct notation is: ``` Example:: >>> ... ``` It is common and wrong to have: ``` Example:: >>> ... ``` In the wrong example, we get these pesky double colons:  Pull Request resolved: https://github.com/pytorch/pytorch/pull/153978 Approved by: https://github.com/soulitzer, https://github.com/malfet
40 lines
900 B
Python
40 lines
900 B
Python
"""Adds docstrings to torch.Size functions"""
|
|
|
|
import torch._C
|
|
from torch._C import _add_docstr as add_docstr
|
|
|
|
|
|
def add_docstr_all(method: str, docstr: str) -> None:
|
|
add_docstr(getattr(torch._C.Size, method), docstr)
|
|
|
|
|
|
add_docstr_all(
|
|
"numel",
|
|
"""
|
|
numel() -> int
|
|
|
|
Returns the number of elements a :class:`torch.Tensor` with the given size would contain.
|
|
|
|
More formally, for a tensor ``x = tensor.ones(10, 10)`` with size ``s = torch.Size([10, 10])``,
|
|
``x.numel() == x.size().numel() == s.numel() == 100`` holds true.
|
|
|
|
Example::
|
|
|
|
>>> x=torch.ones(10, 10)
|
|
>>> s=x.size()
|
|
>>> s
|
|
torch.Size([10, 10])
|
|
>>> s.numel()
|
|
100
|
|
>>> x.numel() == s.numel()
|
|
True
|
|
|
|
|
|
.. warning::
|
|
|
|
This function does not return the number of dimensions described by :class:`torch.Size`, but instead the number
|
|
of elements a :class:`torch.Tensor` with that size would contain.
|
|
|
|
""",
|
|
)
|