swapLast2Axes
Applicable Products
|
Hardware Model |
Supported or Not |
|---|---|
|
|
Not supported |
|
|
Not supported |
|
|
Not supported |
|
|
Supported |
|
|
Supported |
Function Description
API function
- swapLast2AxesGetWorkspaceSize: calculates the workspace size required by the swapLast2Axes operator.
To use the swapLast2Axes operator, you need to call the swapLast2AxesGetWorkspaceSize API to obtain the workspace size required for calculation and the executor that contains the operator calculation process, and then call the swapLast2Axes API to perform calculation.
- swapLast2Axes: swaps the last two dimensions of a tensor.
Formula:
- The calculation formula of swapLast2Axes is
, where b indicates the batch number of data, i indicates the row number of the input data, and j indicates the column number of the input data. - Example:
- Example 1:
[[1.+0.j, 2.+0.j, 3.+0.j]],
After the swapLast2Axes operator is called,
outTensor:
[[1.+0.j], [2.+0.j], [3.+0.j]].
- Example 2:
[[[ 0.+0.j, 1.+0.j, 2.+0.j], [ 3.+0.j, 4.+0.j, 5.+0.j]], [[ 6.+0.j, 7.+0.j, 8.+0.j], [ 9.+0.j, 10.+0.j, 11.+0.j]]],
After the swapLast2Axes operator is called, the outTensor is as follows:
[[[ 0.+0.j, 3.+0.j], [ 1.+0.j, 4.+0.j], [ 2.+0.j, 5.+0.j]], [[ 6.+0.j, 9.+0.j], [ 7.+0.j, 10.+0.j], [ 8.+0.j, 11.+0.j]]].
- Example 1:
Function Prototype
- AsdSip::AspbStatus swapLast2AxesGetWorkspaceSize(const aclTensor *inTensor, aclTensor *outTensor, size_t *size)
- AsdSip::AspbStatus swapLast2Axes(const aclTensor *inTensor, aclTensor *outTensor, void *stream,void *workspace = nullptr)
Parameter Description
- swapLast2AxesGetWorkspaceSize
Parameter
Input/Output
Type
Description
inTensor
Input
const aclTensor *
In the formula, inTensor indicates the tensor on the device. The input dimension is 2 or 3. The maximum number of input elements is 3600000000. The data type must be COMPLEX64 and the data format must be ND.
outTensor
Input
aclTensor *
outTensor: tensor on the device. The data type must be COMPLEX64. If the shape of inTensor is [k, x, y], the shape of outTensor is [k, y, x], the data type must be the same as that of inTensor. The data format can be ND.
workspaceSize
Input
size_t *
Workspace required by the swapLast2Axes operator.
- swapLast2Axes
Parameter
Input/Output
Type
Description
inTensor
Input
const aclTensor *
In the formula, inTensor indicates the tensor on the device. The input dimension is 2 or 3. The maximum number of input elements is 3600000000. The data type must be COMPLEX64 and the data format must be ND.
outTensor
Output
aclTensor *
outTensor: tensor on the device. The data type must be COMPLEX64. If the shape of inTensor is [k, x, y], the shape of outTensor is [k, y, x], the data type must be the same as that of inTensor. The data format can be ND.
stream
Input
void*
NPU execution flow.
workspaceSize
Input
void *
Workspace required by the swapLast2Axes operator.
Constraints
- swapLast2AxesGetWorkspaceSize: none.
- swapLast2Axes
- The maximum number of input elements is 3600000000 (within [60000, 60000]).
- If the input shape of the operator is [k, x, y], the output shape of the operator is [k, y, x].
- The operator does not support the calculation for more than three dimensions.
Calling Example
For details about the operator calling example, see swapLast2Axes.