---
title: AsStridedOperation
description: "| 硬件型号 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendtb/ascendtb_01_0052.html
sourcePath: /source/zh/canncommercial/900/API/ascendtb/ascendtb_01_0052.html
indexId: 9517a3f186b8205872ff3fe343abb7f982b68624bc9b7411810ae04617e82c0164
---
# AsStridedOperation

#### 产品支持情况

| 硬件型号 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | x |
| Atlas A3 推理系列产品 / Atlas A3 训练系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 训练系列产品 | √ |
| Atlas 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |


#### 功能说明

基于已有的张量创建一个数据重新排布过的新的视图（view），可以通过指定形状（shape）和步长（strides）来重新排列元素。

映射关系（以输入为 3x3 shape、输出为 2x2 shape 为例）

- 输入

```
inTensor = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
opParam.size = [2, 2]
opParam.stride = [2, 3]
opParam.offset = [0]
```


- 输出

```
outTensor = [[1, 4], [3, 6]]
```


  映射关系为：outTensor[i][j] -> v_inTensor[ i * stride[0] + j * stride[1] + offset[0]]。

  其中：v_inTensor 为 输入tensor展开的一维向量。

  图1 AsStrided算子实现原理（offset为0时）


- offset不为0时的输出：
  若加上 offset：opParam.offset = [2]。

  则计算后输出为：outTensor = [[3, 6], [5, 8]]。

  图2 AsStrided算子实现原理（offset不为0时）


#### 算子上下文

图3 AsStridedOperation


#### 定义

```
struct AsStridedParam {
    SVector<int64_t> size;
    SVector<int64_t> stride;
    SVector<int64_t> offset;
    uint8_t rsv[8] = {0};
};
```


#### 参数列表

| 成员名称 | 类型 | 默认值 | 描述 |
| --- | --- | --- | --- |
| size | SVector<int64\_t> | \- | 输出tensor的shape。 “size”的长度要求小于或等于8且各元素要求大于0。 |
| stride | SVector<int64\_t> | \- | 用于从输入tensor推导输出tensor的各维度的步长。 “stride”的长度要求与size一致，各元素要求大于或等于0。 |
| offset | SVector<int64\_t> | \- | 输出tensor内存相对于输入tensor内存的偏移，作为常数使用。 “offset”的长度要求为1且元素要求大于或等于0。 |
| rsv[8] | uint8\_t | {0} | 预留参数。 |


#### 输入

| 参数 | 维度 | 数据类型 | 格式 | 描述 |
| --- | --- | --- | --- | --- |
| x | [din\_0, ..., din\_n] | float16/int64 | ND | 输入tensor。 |


#### 输出

| 参数 | 维度 | 数据类型 | 格式 | 描述 |
| --- | --- | --- | --- | --- |
| y | [dout\_0, ..., dout\_m] | float16/int64 | ND | 输出tensor。 |


#### 约束说明

Param参数约束：

- offset.size() == 1，offset.at(i) ≥ 0。
- size.size() ≤ 8，size.at(i) > 0。
- stride.size() == size.size()，stride.at(i) ≥ 0。
