---
title: MaxAbsIndx
description: "获取向量中的最大绝对值及其位置索引。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_hmpp_06_0068.html
sourcePath: /source/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_hmpp_06_0068.html
indexId: 3af5ceb90abce41b5032421492a7bdae36b7f8e26123c0a764db2fbd63df8cef77
---
# MaxAbsIndx

获取向量中的最大绝对值及其位置索引。

函数接口声明如下：

HmppResult HMPPS_MaxAbsIndx_16s(const int16_t *src int32_t len, int16_t *maxAbs, int32_t *indx);

HmppResult HMPPS_MaxAbsIndx_32s(const int32_t *src, int32_t len, int32_t *maxAbs, int32_t *indx);

#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| src | 指向源向量的指针。 | 非空 | 输入 |
| len | 向量长度。 | (0, INT\_MAX] | 输入 |
| maxAbs | 指向最大绝对值的指针。 | 非空 | 输出 |
| indx | 指向位置索引的指针。 | 非空 | 输出 |


#### 返回值

- 成功：返回HMPP_STS_NO_ERR。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| HMPP\_STS\_NULL\_PTR\_ERR | src、maxAbs、indx这两个入参中存在空指针。 |
| HMPP\_STS\_SIZE\_ERR | len小于或等于0。 |


#### 示例

```
#define BUFFER_SIZE_T 10
void MaxAbsIndxExample(void)
{
int16_t src[BUFFER_SIZE_T] = {3, 0, 2, -8, 3, 15, 26, -31, 1, 23};
int16_t maxAbs;
int32_t maxIndex;
HmppResult result = HMPPS_MaxAbsIndx_16s(src, BUFFER_SIZE_T, &maxAbs, &maxIndex);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("maxAbs = %d, index of maxAbs is %d\n", maxAbs, maxIndex);
}
```

运行结果：

```
result = 0
maxAbs = 31, index of maxAbs is 7
```
