Transposition (Transpose)#
API#
- class warp_nn.modules.operators.Transpose( )[source]#
Bases:
ModuleTransposition (Transpose) operation.
This class permutes the dimensions of an array, so that the dimension
iof the output array is the dimensiondims[i]of the input array:\[\text{Transpose}(x)_{j_0, \ldots, j_{n-1}} = x_{i_0, \ldots, i_{n-1}} \quad \text{with} \quad i_{\text{dims}[k]} = j_k\]The transposed (strided) view of the input array is copied into a contiguous output array by a kernel launch, so the gradients of the output array are propagated to the (floating-point) input array. Integer and Boolean arrays are not differentiable.
If the input array is contiguous and the permutation keeps the order of its dimensions larger than 1 (e.g. it only moves dimensions of size 1), or the input array is empty, its elements are already in the output order: the output array is then a reshaped view of the input array (no data is copied, and no kernel is launched), which shares its memory and gradients (and whether it requires gradients) with the input array.
- Parameters:
dims – The permutation of the input array’s dimensions. Negative values count from the last dimension. If not given, the order of the dimensions is reversed.
requires_grad – Whether the cached (floating-point) output arrays of the module require gradients. It does not apply to the output arrays that are views of the input array.
- Raises:
ValueError – If
dimscontains duplicated values.
- __call__(
- input: array,
Forward pass of the operation.
- Parameters:
input – The input array, with up to 4 dimensions (floating-point, integer or Boolean). It can be non-contiguous (e.g. a strided view), but it must not share memory with an output array of the module (e.g. the output of a previous call).
- Returns:
The (contiguous) output array, whose dimension
iis the dimensiondims[i]of the input array. It is a view of the input array if no data has to be moved, in which case it requires gradients if (and only if) the input array does, regardless of the module’srequires_grad.- Raises:
ValueError – If the input array is not on the module’s device, if
dimsis not a permutation of the input array’s dimensions, or if the input array shares memory with the output array.TypeError – If the input array’s data type is not supported.