Add document of function torch.as_strided (#22842)

Summary:
Documentation of `torch.as_strided` and `Tensor.as_strided` is missing. As mentioned in https://github.com/pytorch/pytorch/issues/9886
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22842

Differential Revision: D16254106

Pulled By: soumith

fbshipit-source-id: dee142483fb9ef7bea84bd44a970b6eccdcdc471
This commit is contained in:
Kexuan Sun 2019-07-23 05:42:08 -07:00 committed by Facebook Github Bot
parent c9e62f6988
commit 45d3f495ef
5 changed files with 49 additions and 1 deletions

View file

@ -176,6 +176,7 @@ view of a storage and defines numeric operations on it.
.. automethod:: argsort
.. automethod:: asin
.. automethod:: asin_
.. automethod:: as_strided
.. automethod:: atan
.. automethod:: atan2
.. automethod:: atan2_

View file

@ -36,6 +36,7 @@ Creation Ops
.. autofunction:: tensor
.. autofunction:: sparse_coo_tensor
.. autofunction:: as_tensor
.. autofunction:: as_strided
.. autofunction:: from_numpy
.. autofunction:: zeros
.. autofunction:: zeros_like

View file

@ -193,7 +193,6 @@ class _TestTorchMixin(object):
# FIXME: fix all the skipped ones below!
test_namespace(torch.randn(1),
'as_strided',
'as_strided_',
re.compile('^clamp_(min|max)_?$'),
'coalesce',

View file

@ -399,6 +399,12 @@ asin_() -> Tensor
In-place version of :meth:`~Tensor.asin`
""")
add_docstr_all('as_strided', r"""
as_strided(size, stride, storage_offset=0) -> Tensor
See :func:`torch.as_strided`
""")
add_docstr_all('atan',
r"""
atan() -> Tensor

View file

@ -469,6 +469,47 @@ Example::
True
""")
add_docstr(torch.as_strided,
r"""
as_strided(input, size, stride, storage_offset=0) -> Tensor
Create a view of an existing `torch.Tensor` :attr:`input` with specified
:attr:`size`, :attr:`stride` and :attr:`storage_offset`.
.. warning::
More than one element of a created tensor may refer to a single memory
location. As a result, in-place operations (especially ones that are
vectorized) may result in incorrect behavior. If you need to write to
the tensors, please clone them first.
Many PyTorch functions, which return a view of a tensor, are internally
implemented with this function. Those functions, like
:meth:`torch.Tensor.expand`, are easier to read and are therefore more
advisable to use.
Args:
input (Tensor): the input tensor
size (tuple or ints): the shape of the output tensor
stride (tuple or ints): the stride of the output tensor
storage_offset (int, optional): the offset in the underlying storage of the output tensor
Example::
>>> x = torch.randn(3, 3)
>>> x
tensor([[ 0.9039, 0.6291, 1.0795],
[ 0.1586, 2.1939, -0.4900],
[-0.1909, -0.7503, 1.9355]])
>>> t = torch.as_strided(x, (2, 2), (1, 2))
>>> t
tensor([[0.9039, 1.0795],
[0.6291, 0.1586]])
>>> t = torch.as_strided(x, (2, 2), (1, 2), 1)
tensor([[0.6291, 0.1586],
[1.0795, 2.1939]])
""")
add_docstr(torch.as_tensor,
r"""
as_tensor(data, dtype=None, device=None) -> Tensor