ThresholdAbs
Sets a threshold for the absolute values of elements in a vector. The comparison operations are specified by the interface function names, including:
- HMPPS_Threshold_LTAbs
For the less-than operation, that is, level is the lower boundary of the vector:

- HMPPS_Threshold_GTAbs
For the greater-than operation, that is, level is the upper boundary of the vector:

The function interface declaration is as follows:
- Operations on integers:
HmppResult HMPPS_Threshold_LTAbs_16s(const int16_t* src, int16_t* dst, int32_t len, int16_t level);
HmppResult HMPPS_Threshold_LTAbs_32s(const int32_t* src, int32_t* dst, int32_t len, int32_t level);
HmppResult HMPPS_Threshold_GTAbs_16s(const int16_t* src, int16_t* dst, int32_t len, int16_t level);
HmppResult HMPPS_Threshold_GTAbs_32s(const int32_t* src, int32_t* dst, int32_t len, int32_t level);
- Operations on floating-point numbers:
HmppResult HMPPS_Threshold_LTAbs_32f(const float* src, float* dst, int32_t len, float level);
HmppResult HMPPS_Threshold_LTAbs_64f(const double* src, double* dst, int32_t len, double level);
HmppResult HMPPS_Threshold_GTAbs_32f(const float* src, float* dst, int32_t len, float level);
HmppResult HMPPS_Threshold_GTAbs_64f(const double* src, double* dst, int32_t len, double level);
- In-place operations on integers:
HmppResult HMPPS_Threshold_LTAbs_16s_I(int16_t* srcDst, int32_t len, int16_t level);
HmppResult HMPPS_Threshold_LTAbs_32s_I(int32_t* srcDst, int32_t len, int32_t level);
HmppResult HMPPS_Threshold_GTAbs_16s_I(int16_t* srcDst, int32_t len, int16_t level);
HmppResult HMPPS_Threshold_GTAbs_32s_I(int32_t* srcDst, int32_t len, int32_t level);
- In-place operations on floating-point numbers:
HmppResult HMPPS_Threshold_LTAbs_32f_I(float* srcDst, int32_t len, float level);
HmppResult HMPPS_Threshold_LTAbs_64f_I(double* srcDst, int32_t len, double level);
HmppResult HMPPS_Threshold_GTAbs_32f_I(float* srcDst, int32_t len, float level);
HmppResult HMPPS_Threshold_GTAbs_64f_I(double* srcDst, int32_t len, double level)
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
srcDst |
Pointer to the source vector for in-place operations |
The value cannot be NULL. |
Input/Output |
len |
Vector length |
(0, INT_MAX] |
Input |
level |
Threshold |
Not limited, depending on the type |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of src, dst, or srcDst is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
HMPP_STS_THRESH_NEG_LEVEL_ERR |
The threshold is less than 0. |
Example
#define BUFFER_SIZE_T 20
void ThresholdAbsExample(void)
{
float src[BUFFER_SIZE_T] = {1.46, 9.40, 10.73, 5.90, 5.74, -0.96, 8.55, -1.39, 1.71, 2.32, 9.99, 5.42, 10.58, 5.20, 9.12, 0.86, 10.13, 5.94, -0.62, 9.19};
float dst[BUFFER_SIZE_T] = {0.00};
HmppResult result;
int32_t i;
result = HMPPS_Threshold_LTAbs_32f(src, dst, BUFFER_SIZE_T, 3.14);
printf("Threshold1: result = %d.\ndst1 = ", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
for (i = 0; i < BUFFER_SIZE_T; i++) {
printf(" %.2f ", dst[i]);
}
HMPPS_Zero_32f(dst, BUFFER_SIZE_T);
result = HMPPS_Threshold_GTAbs_32f(src, dst, BUFFER_SIZE_T, 3.14);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("\nThreshold2: result = %d.\ndst2 = ", result);
for (i = 0; i < BUFFER_SIZE_T; i++) {
printf(" %.2f ", dst[i]);
}
}
Output:
Threshold1: result = 0. dst1 = 3.14 9.40 10.73 5.90 5.74 -3.14 8.55 -3.14 3.14 3.14 9.99 5.42 10.58 5.20 9.12 3.14 10.13 5.94 -3.14 9.19 Threshold2: result = 0. dst2 = 1.46 3.14 3.14 3.14 3.14 -0.96 3.14 -1.39 1.71 2.32 3.14 3.14 3.14 3.14 3.14 0.86 3.14 3.14 -0.62 3.14