_size_docs.py 908 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # mypy: allow-untyped-defs
  2. """Adds docstrings to torch.Size functions"""
  3. import torch._C
  4. from torch._C import _add_docstr as add_docstr
  5. def add_docstr_all(method, docstr):
  6. add_docstr(getattr(torch._C.Size, method), docstr)
  7. add_docstr_all(
  8. "numel",
  9. """
  10. numel() -> int
  11. Returns the number of elements a :class:`torch.Tensor` with the given size would contain.
  12. More formally, for a tensor ``x = tensor.ones(10, 10)`` with size ``s = torch.Size([10, 10])``,
  13. ``x.numel() == x.size().numel() == s.numel() == 100`` holds true.
  14. Example::
  15. >>> x=torch.ones(10, 10)
  16. >>> s=x.size()
  17. >>> s
  18. torch.Size([10, 10])
  19. >>> s.numel()
  20. 100
  21. >>> x.numel() == s.numel()
  22. True
  23. .. warning::
  24. This function does not return the number of dimensions described by :class:`torch.Size`, but instead the number
  25. of elements a :class:`torch.Tensor` with that size would contain.
  26. """,
  27. )