---
title: CountInRange
description: "统计向量中在特定区间范围内数据的个数。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_hmpp_06_0057.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_hmpp_06_0057.html
indexId: d96d2314719e09caac026f0b842f9d6f6ca08591161421c76b35382fccf9a5ab77
---
# CountInRange

统计向量中在特定区间范围内数据的个数。

当向量元素满足lowerBound < src[n ] < upperBound时，pCounts = pCounts + 1。

函数接口声明如下：

HmppResult HMPPS_CountInRange_32s(const int32_t *src, int32_t len, int32_t *counts, int32_t lowerBound, int32_t upperBound);

#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| src | 指向源向量的指针。 | 非空 | 输入 |
| len | 向量长度。 | (0, INT\_MAX] | 输入 |
| counts | 指向统计结果的指针。 | 非空 | 输出 |
| lowerBound | 区间下界。 | [INT\_MIN, INT\_MAX] | 输入 |
| upperBound | 区间上界。 | [INT\_MIN, INT\_MAX] | 输入 |


#### 返回值

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


#### 错误码

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


#### 示例

```
#define BUFFER_SIZE_T 10
void CountInRangeExample(void)
{
int32_t src[BUFFER_SIZE_T] = {3, 5, 9, 9, 11, 10, 0, -7, -3, 1};
int32_t lower =0;
int32_t upper =10;
int32_t count;
HmppResult result = HMPPS_CountInRange_32s(src, BUFFER_SIZE_T, &count, lower, upper);
printf("result = %d  ", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("countInRange = %d\n", count);
}
```

运行结果：

```
result = 0  countInRange = 5
```
