AsStridedOperation
Description
Generates an output tensor with data re-arranged based on the specified parameters.
Operator Context
Operator Function Implementation
The AsStrided operator is used to create a view based on an existing tensor. You can rearrange elements by specifying the shape and stride.
Mapping (using the 3 x 3 input shape and 2 x 2 output shape as an example)
- Input
inTensor = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] opParam.size = [2, 2] opParam.stride = [2, 3] opParam.offset = [0]
- Output
outTensor = [[1, 4], [3, 6]]
Mapping: outTensor[i][j] -> v_inTensor[ i * stride[0] + j * stride[1] + offset[0]].
v_inTensor is the 1D vector of the input tensor.
- Output when offset is not 0:
If offset is added, opParam.offset = [2].
Output: outTensor = [[3, 6], [5, 8]].
Figure 3 Implementation principle of the AsStrided operator (when offset is not 0)
Definition
struct AsStridedParam {
SVector<int64_t> size;
SVector<int64_t> stride;
SVector<int64_t> offset;
uint8_t rsv[8] = {0};
};
Parameters
|
Member |
Type |
Default Value |
Description |
|---|---|---|---|
|
size |
SVector<int64_t> |
- |
Shape of the output tensor. The length of size must be less than or equal to 8, and each element must be greater than 0. |
|
stride |
SVector<int64_t> |
- |
Stride of each dimension of the output tensor derived based on the input tensor. The length of stride must be the same as that of size, and each element must be greater than or equal to 0. |
|
offset |
SVector<int64_t> |
- |
Offset of the output tensor memory relative to the input tensor memory, which is used as a constant. The length of offset must be 1, and the element must be greater than or equal to 0. |
|
rsv[8] |
uint8_t |
{0} |
Reserved |
Input
|
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
|
x |
[din_0, ..., din_n] |
float16/int64 |
ND |
Input tensor |
Output
|
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
|
y |
[dout_0, ..., dout_m] |
float16/int64 |
ND |
Output tensor |
Restrictions
Restrictions on the parameters:
- offset.size() == 1, offset.at(i) ≥ 0.
- size.size() ≤ 8, size.at(i) > 0.
- stride.size() == size.size(), stride.at(i) ≥ 0.