mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Update as strided doc (#149146)
Make it clearer why it is not recommended to use it and when the resulting Tensor will have undefined behavior. Pull Request resolved: https://github.com/pytorch/pytorch/pull/149146 Approved by: https://github.com/gchanan, https://github.com/jbschlosser
This commit is contained in:
@ -918,13 +918,15 @@ Create a view of an existing `torch.Tensor` :attr:`input` with specified
|
||||
:attr:`size`, :attr:`stride` and :attr:`storage_offset`.
|
||||
|
||||
.. warning::
|
||||
Prefer using other view functions, like :meth:`torch.Tensor.expand`,
|
||||
to setting a view's strides manually with `as_strided`, as this
|
||||
function's behavior depends on the implementation of a tensor's storage.
|
||||
The constructed view of the storage must only refer to elements within
|
||||
the storage or a runtime error will be thrown, and if the view is
|
||||
"overlapped" (with multiple indices referring to the same element in
|
||||
memory) its behavior is undefined.
|
||||
Prefer using other view functions, like :meth:`torch.Tensor.view` or
|
||||
:meth:`torch.Tensor.expand`, to setting a view's strides manually with
|
||||
`as_strided`, as this function will throw an error on non-standard Pytorch
|
||||
backends (that do not have a concept of stride) and the result will depend
|
||||
on the current layout in memory. The constructed view must only refer to
|
||||
elements within the Tensor's storage or a runtime error will be thrown.
|
||||
If the generated view is "overlapped" (with multiple indices referring to
|
||||
the same element in memory), the behavior of inplace operations on this view
|
||||
is undefined (and might not throw runtime errors).
|
||||
|
||||
Args:
|
||||
{input}
|
||||
|
Reference in New Issue
Block a user