_storage_docs.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """Adds docstrings to Storage functions"""
  2. import torch._C
  3. from torch._C import _add_docstr as add_docstr
  4. storage_classes = [
  5. "StorageBase",
  6. ]
  7. def add_docstr_all(method, docstr):
  8. for cls_name in storage_classes:
  9. cls = getattr(torch._C, cls_name)
  10. try:
  11. add_docstr(getattr(cls, method), docstr)
  12. except AttributeError:
  13. pass
  14. add_docstr_all(
  15. "from_file",
  16. """
  17. from_file(filename, shared=False, size=0) -> Storage
  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. `size` is the number of elements in the storage. If `shared` is `False`,
  22. then the file must contain at least `size * sizeof(Type)` bytes
  23. (`Type` is the type of storage). If `shared` is `True` the file will be
  24. created if needed.
  25. Args:
  26. filename (str): file name to map
  27. shared (bool): whether to share memory
  28. size (int): number of elements in the storage
  29. """,
  30. )