xref: /aosp_15_r20/external/pytorch/torch/_storage_docs.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# mypy: allow-untyped-defs
2"""Adds docstrings to Storage functions"""
3
4import torch._C
5from torch._C import _add_docstr as add_docstr
6
7
8storage_classes = ["StorageBase"]
9
10
11def add_docstr_all(method, docstr):
12    for cls_name in storage_classes:
13        cls = getattr(torch._C, cls_name)
14        try:
15            add_docstr(getattr(cls, method), docstr)
16        except AttributeError:
17            pass
18
19
20add_docstr_all(
21    "from_file",
22    """
23from_file(filename, shared=False, size=0) -> Storage
24
25Creates a CPU storage backed by a memory-mapped file.
26
27If ``shared`` is ``True``, then memory is shared between all processes.
28All changes are written to the file. If ``shared`` is ``False``, then the changes on
29the storage do not affect the file.
30
31``size`` is the number of elements in the storage. If ``shared`` is ``False``,
32then the file must contain at least ``size * sizeof(Type)`` bytes
33(``Type`` is the type of storage, in the case of an ``UnTypedStorage`` the file must contain at
34least ``size`` bytes). If ``shared`` is ``True`` the file will be created if needed.
35
36Args:
37    filename (str): file name to map
38    shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
39                    underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
40    size (int): number of elements in the storage
41""",
42)
43