forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_size_docs.py
39 lines (27 loc) · 908 Bytes
/
_size_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# mypy: allow-untyped-defs
"""Adds docstrings to torch.Size functions"""
import torch._C
from torch._C import _add_docstr as add_docstr
def add_docstr_all(method, docstr):
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.
""",
)