r"""Swaps shapes and strides according to given pattern. Args: inp: input tensor. pattern: a list of integers including 0, 1, ... , ``ndim``-1, and any number of ``'x'`` char in dimensions where this tensor should be broadcasted. For examples:
(inp: Tensor, pattern: Iterable[int])
| 900 | |
| 901 | |
| 902 | def transpose(inp: Tensor, pattern: Iterable[int]) -> Tensor: |
| 903 | r"""Swaps shapes and strides according to given pattern. |
| 904 | |
| 905 | Args: |
| 906 | inp: input tensor. |
| 907 | pattern: a list of integers including 0, 1, ... , ``ndim``-1, |
| 908 | and any number of ``'x'`` char in dimensions where this tensor should be broadcasted. |
| 909 | For examples: |
| 910 | |
| 911 | * (``'x'``) -> make a 0d (scalar) into a 1d vector |
| 912 | * (0, 1) -> identity for 2d vectors |
| 913 | * (1, 0) -> inverts the first and second dimensions |
| 914 | * (``'x'``, 0) -> make a row out of a 1d vector (N to 1xN) |
| 915 | * (0, ``'x'``) -> make a column out of a 1d vector (N to Nx1) |
| 916 | * (2, 0, 1) -> AxBxC to CxAxB |
| 917 | * (0, ``'x'``, 1) -> AxB to Ax1xB |
| 918 | * (1, ``'x'``, 0) -> AxB to Bx1xA |
| 919 | * (1,) -> this removes dimensions 0. It must be a broadcastable dimension (1xA to A) |
| 920 | |
| 921 | Returns: |
| 922 | output tensor. |
| 923 | |
| 924 | Examples: |
| 925 | >>> import numpy as np |
| 926 | >>> x = Tensor(np.array([[1, 1], [0, 0]], dtype=np.int32)) |
| 927 | >>> F.transpose(x, (1, 0)) |
| 928 | Tensor([[1 0] |
| 929 | [1 0]], dtype=int32, device=xpux:0) |
| 930 | """ |
| 931 | return inp.transpose(pattern) |
| 932 | |
| 933 | |
| 934 | def non_zero(condition: Tensor, as_tuple=False): |
no test coverage detected