Add an operation to permute the dimensions of a tensor. The dimensions of the input tensor are permuted according to the sequence of dimensions in 'dims'. That operation maps to tensorrt.IShuffleLayer where the second transposition is described by the indices in 'dims'. Given
(input: Tensor, dims: Sequence[int])
| 1683 | |
| 1684 | |
| 1685 | def permute(input: Tensor, dims: Sequence[int]) -> Tensor: |
| 1686 | ''' |
| 1687 | Add an operation to permute the dimensions of a tensor. |
| 1688 | |
| 1689 | The dimensions of the input tensor are permuted according to the sequence |
| 1690 | of dimensions in 'dims'. That operation maps to tensorrt.IShuffleLayer where |
| 1691 | the second transposition is described by the indices in 'dims'. |
| 1692 | |
| 1693 | Given a tensor of rank N, the result of the permutation is a tensor of rank |
| 1694 | N in which the i-th input dimension maps to the dims[i]-th dimension. |
| 1695 | |
| 1696 | For example, permute(input, [1, 0]) will transpose a 2D tensor by permuting |
| 1697 | the rows and columns. |
| 1698 | |
| 1699 | Parameters: |
| 1700 | input : Tensor |
| 1701 | The input tensor to permute. |
| 1702 | |
| 1703 | dims : Sequence[int] |
| 1704 | The description of the permutation. |
| 1705 | |
| 1706 | Returns: |
| 1707 | The tensor produced by the permutation layer. |
| 1708 | ''' |
| 1709 | dims = dim_resolve_negative(tuple(dims), input.ndim()) |
| 1710 | layer = default_trtnet().add_shuffle(input.trt_tensor) |
| 1711 | layer.second_transpose = dims |
| 1712 | return _create_tensor(layer.get_output(0), layer) |
| 1713 | |
| 1714 | |
| 1715 | def transpose(input: Tensor, dim0: int, dim1: int) -> Tensor: |
no test coverage detected