_storage_docs.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # mypy: allow-untyped-defs
  2. """Adds docstrings to Storage functions"""
  3. import torch._C
  4. from torch._C import _add_docstr as add_docstr
  5. storage_classes = ["StorageBase"]
  6. def add_docstr_all(method, docstr):
  7. for cls_name in storage_classes:
  8. cls = getattr(torch._C, cls_name)
  9. try:
  10. add_docstr(getattr(cls, method), docstr)
  11. except AttributeError:
  12. pass
  13. add_docstr_all(
  14. "from_file",
  15. """
  16. from_file(filename, shared=False, nbytes=0) -> Storage
  17. Creates a CPU storage backed by a memory-mapped file.
  18. If ``shared`` is ``True``, then memory is shared between all processes.
  19. All changes are written to the file. If ``shared`` is ``False``, then the changes on
  20. the storage do not affect the file.
  21. ``nbytes`` is the number of bytes of storage. If ``shared`` is ``False``,
  22. then the file must contain at least ``nbytes`` bytes. If ``shared`` is
  23. ``True`` the file will be created if needed. (Note that for ``UntypedStorage``
  24. this argument differs from that of ``TypedStorage.from_file``)
  25. Args:
  26. filename (str): file name to map
  27. shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
  28. underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
  29. nbytes (int): number of bytes of storage
  30. """,
  31. )