---
title: rsInterpolationBySinc
description: "| 硬件型号 | 支持情况 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/SiP/SIP_API_0032.html
sourcePath: /source/zh/canncommercial/900/API/SiP/SIP_API_0032.html
indexId: 088e160ca82836c0c4c80146aba5e2030ef9815ac8a7c2e58ee14d0d0f3b04a055
---
# rsInterpolationBySinc

#### 产品支持情况

| 硬件型号 | 支持情况 |
| --- | --- |
| Atlas 200I/500 A2 推理产品 | 不支持 |
| Atlas 推理系列产品 | 不支持 |
| Atlas 训练系列产品 | 不支持 |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | 支持 |
| Atlas A3 推理系列产品 / Atlas A3 训练系列产品 | 不支持 |


#### 功能描述

接口功能

- rsInterpolationBySincGetWorkspaceSize：计算rsInterpolationBySinc算子所需的workspace大小。
  若需使用“rsInterpolationBySinc”算子，需先调用“rsInterpolationBySincGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器，再调用“rsInterpolationBySinc”接口执行计算。

- 
  rsInterpolationBySinc：实现带batch的一维复数向量插值计算，返回结果和插值坐标同样形状大小。


计算公式

- rsInterpolationBySinc的计算公式：
  其中n为实信号索引，x[n]为原实信号序列，sinc(d-n)是插值系数，在本算子中需要作为参数传入。

- 示例：
  输入“inputTensor”为：

```
[ 1 + i , 2 + i ]
```


  输入“sincTab”为：（intp_num = 2， quant_num = 2）

```
[   [ 1 , 0 ],  [ 0.5 , 0.5 ],   [ 0 , 1 ]  ]
```


  原始“pos”为：

```
[ 0.2 , 1.6 ]
```


  转为输入“posFloor”为： floor(Pos)

```
[ 0 , 1 ]
```


  转为输入“posToTabIndex”为：round((Pos -posFloor) *quant_num)

```
[ 0 , 1 ]
```


  其中，tab大小为2 * 3。由于pos[0] = 0.2，取inputTensor[0]及后面一个元素inputTensor[1]共2个元素，与sincTab[posToTabIndex[0]]进行向量点乘，得到outputTensor[0]，依次计算后续元素。

```
pos[0] = 0.3 → outputTensor[0] = [1 + i , 2 + i] · [ 1 , 0 ] = 1 + i
pos[1] = 1.6 → outputTensor[1] = [2 + i , 2 + i] · [ 0.5 , 0.5 ] = 2 + i
```


  调用“rsInterpolationBySinc”算子后，输出“outputTensor”为：

```
[ 1 + i , 2 + i ]
```


#### 函数原型

- AspbStatus rsInterpolationBySincGetWorkspaceSize(const aclTensor *inputTensor, const aclTensor *sincTab,const aclTensor *posFloor, const aclTensor *posToTabIndex,aclTensor *outputTensor, int interpNum, int quantNum, int length,size_t *workspaceSize)
- AspbStatus rsInterpolationBySinc(const aclTensor *inputTensor, const aclTensor *sincTab,const aclTensor *posFloor, const aclTensor *posToTabIndex,aclTensor *outputTensor, int interpNum, int quantNum, int interpLength,void *stream, void *workSpace = nullptr)


#### 参数说明

- rsInterpolationBySincGetWorkspaceSize| 参数名称 | Input/Output | 类型 | 描述 |
| --- | --- | --- | --- |
| inputTensor | Input | const aclTensor \* | 原始信号，Device侧的Tensor，数据类型支持COMPLEX64，数据格式支持ND，shape为[batch, signalLength] |
| sincTab | Input | const aclTensor \* | 插值系数矩阵，Device侧的Tensor，数据类型支持FLOAT32，数据格式支持ND，shape为[ 4, ((quantNum + 1) \* 2) \* (interpNum \* 2 + 8)] 。 |
| posFloor | Input | const aclTensor \* | 插值点坐标向下取整后的值，Device侧的Tensor，数据类型支持INT32，数据格式支持ND，shape为[batch, length]。 |
| posToTabIndex | Input | const aclTensor \* | 插值点坐标通过round((Pos \-posFloor) \*quantNum)计算出对应插值系数矩阵的行号，Device侧的Tensor，数据类型支持INT16\_T，数据格式支持ND，shape为[batch, length]。 |
| outputTensor | Output | aclTensor \* | 插值结果，Device侧的Tensor，数据类型支持COMPLEX64，数据格式支持ND，shape为[batch, length]。 |
| interpNum | Input | int | 插值点数。 |
| quantNum | Input | int | 量化点数。 |
| length | Input | int | 插值长度。 |
| workspaceSize | Output | size\_t \* | rsInterpolationBySinc算子所需要的workspace。 |


- 
  rsInterpolationBySinc
| 参数名称 | Input/Output | 类型 | 描述 |
| --- | --- | --- | --- |
| inputTensor | Input | const aclTensor \* | 原始信号，Device侧的Tensor，数据类型支持COMPLEX64，数据格式支持ND，shape为[batch, signalLength] |
| sincTab | Input | const aclTensor \* | 插值系数矩阵，Device侧的Tensor，数据类型支持FLOAT32，数据格\-式支持ND，shape为[ 4, ((quantNum + 1) \* 2) \* (interpNum \* 2 + 8)] 。 |
| posFloor | Input | const aclTensor \* | 插值点坐标向下取整后的值，Device侧的Tensor，数据类型支持INT32，数据格式支持ND，shape为[batch, length]。 |
| posToTabIndex | Input | const aclTensor \* | 插值点坐标通过round((Pos \-posFloor) \*quantNum)计算出对应插值系数矩阵的行号，Device侧的Tensor，数据类型支持INT16\_T，数据格式支持ND，shape为[batch, length]。 |
| outputTensor | Output | aclTensor \* | 插值结果，Device侧的Tensor，数据类型支持COMPLEX64，数据格式支持ND，shape为[batch, length]。 |
| interpNum | Input | int | 插值点数。 |
| quantNum | Input | int | 量化点数。 |
| length | Input | int | 插值长度。 |
| stream | Input | void \* | npu执行流。 |
| workSpace | Input | void \* | workspace的地址 |


#### 返回值说明

返回值相关说明参见返回值。


#### 约束说明

- rsInterpolationBySincGetWorkspaceSize
  无。

- 
  rsInterpolationBySinc
  - 输入的元素个数理论支持[1，3.93e+09]。
  - 算子输入shape为[batch, signalLength]、[ 4, ((quantNum + 1) * 2) * (interpNum * 2 + 8)] 、[batch, length]、[batch, length]，输出shape为[batch, length]。

  - 算子实际计算时，不支持ND高维度运算（不支持维度≥3的运算）。
  - interpNum只支持偶数，通常使用 [8 ，12 ，16] ，当前版本最大支持16。
  - quantNum为2的幂，最大32。
  - inputTensor、posFloor、posToTabIndex第0维是相同的batch数，outTensors长度和posFloor、posToTabIndex一致。
  - sincTab：为了将复数点乘转化为实数点乘以及更亲和NPU和需要进行预处理，需要扩充成[ ((quantNum + 1) * 2) * (interpNum * 2 + 8) * 4] ，具体算法参考    rsInterpolationBySinc示例源码
中预处理内容。


#### 调用示例

算子的调用示例参见rsInterpolationBySinc。
