From 057be231688f712212688530f0105ba143e9a1bf Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Wed, 13 Jan 2021 01:00:01 -0800 Subject: [PATCH] [doc] Add note about `torch.flip` returning new tensor and not view. (#50041) Summary: Reference: https://github.com/pytorch/pytorch/issues/38271 Pull Request resolved: https://github.com/pytorch/pytorch/pull/50041 Reviewed By: izdeby Differential Revision: D25883870 Pulled By: mruberry fbshipit-source-id: 33cc28a2176e98f2f29077958782291609c7999b --- torch/_torch_docs.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/torch/_torch_docs.py b/torch/_torch_docs.py index 9f1366e5072f..d25a8d5b38cf 100644 --- a/torch/_torch_docs.py +++ b/torch/_torch_docs.py @@ -8477,6 +8477,11 @@ def merge_dicts(*dicts): Reverse the order of a n-D tensor along given axis in dims. +.. note:: + `torch.flip` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flip`, + which returns a view in constant time. Since copying a tensor's data is more work than viewing that data, + `torch.flip` is expected to be slower than `np.flip`. + Args: {input} dims (a list or tuple): axis to flip on @@ -8502,13 +8507,18 @@ def merge_dicts(*dicts): r""" fliplr(input) -> Tensor -Flip array in the left/right direction, returning a new tensor. +Flip tensor in the left/right direction, returning a new tensor. Flip the entries in each row in the left/right direction. Columns are preserved, but appear in a different order than before. Note: - Equivalent to input[:,::-1]. Requires the array to be at least 2-D. + Requires the tensor to be at least 2-D. + +.. note:: + `torch.fliplr` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.fliplr`, + which returns a view in constant time. Since copying a tensor's data is more work than viewing that data, + `torch.fliplr` is expected to be slower than `np.fliplr`. Args: input (Tensor): Must be at least 2-dimensional. @@ -8528,13 +8538,18 @@ def merge_dicts(*dicts): r""" flipud(input) -> Tensor -Flip array in the up/down direction, returning a new tensor. +Flip tensor in the up/down direction, returning a new tensor. Flip the entries in each column in the up/down direction. Rows are preserved, but appear in a different order than before. Note: - Equivalent to input[::-1,...]. Requires the array to be at least 1-D. + Requires the tensor to be at least 1-D. + +.. note:: + `torch.flipud` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flipud`, + which returns a view in constant time. Since copying a tensor's data is more work than viewing that data, + `torch.flipud` is expected to be slower than `np.flipud`. Args: input (Tensor): Must be at least 1-dimensional.