MinMaxIndx
获取向量中的最大值、最小值以及它们的索引。
函数接口声明如下:
- 整型数的操作:
HmppResult HMPPS_MinMaxIndx_8u(const uint8_t *src, int32_t len, uint8_t *min, int32_t *minIndx, uint8_t *max,int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_16u(const uint16_t *src, int32_t len, uint16_t *min, int32_t *minIndx,uint16_t *max, int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_32u(const uint32_t *src, int32_t len, uint32_t *min, int32_t *minIndx,uint32_t *max, int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_16s(const int16_t *src, int32_t len, int16_t *min, int32_t *minIndx, int16_t *max,int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_32s(const int32_t *src, int32_t len, int32_t *min, int32_t *minIndx, int32_t *max,int32_t *maxIndx);
- 浮点数的操作:
HmppResult HMPPS_MinMaxIndx_32f(const float *src, int32_t len, float *min, int32_t *minIndx, float *max,int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_64f(const double *src, int32_t len, double *min, int32_t *minIndx, double *max,int32_t* maxIndx);
参数
参数名 |
描述 |
取值范围 |
输入/输出 |
---|---|---|---|
src |
指向源向量的指针。 |
非空 |
输入 |
len |
向量长度。 |
(0, INT_MAX] |
输入 |
min |
指向最小值的指针。 |
非空 |
输出 |
minIndx |
指向最小值的位置索引的指针。 |
非空 |
输出 |
max |
指向最大值的指针。 |
非空 |
输出 |
maxIndx |
指向最大值的位置索引的指针。 |
非空 |
输出 |
返回值
- 成功:返回HMPP_STS_NO_ERR。
- 失败:返回错误码。
错误码
错误码 |
描述 |
---|---|
HMPP_STS_NULL_PTR_ERR |
src、min、minIndx、max、maxIndx这几个入参中存在空指针。 |
HMPP_STS_SIZE_ERR |
len小于或等于0。 |
示例
#define BUFFER_SIZE_T 10 void MinMaxIndxExample(void) { int16_t src[BUFFER_SIZE_T] = {3, 0, 2, -8, 3, 15, 26, -31, 1, 23}; int16_t min; int32_t minIndex; int16_t max; int32_t maxIndex; HmppResult result = HMPPS_MinMaxIndx_16s(src, BUFFER_SIZE_T, &min, &minIndex, &max, &maxIndex); printf("result = %d\n", result); if (result != HMPP_STS_NO_ERR) { return; } printf("min = %d, index of min is %d\n", min, minIndex); printf("max = %d, index of max is %d\n", max, maxIndex); }
运行结果:
result = 0 min = -31, index of min is 7 max = 26, index of max is 6