Rate This Document
Findability
Accuracy
Completeness
Readability

ThresholdVal

Uses a constant to set the threshold for elements in a vector. Different from the Threshold interface, the vector element that is not within the threshold range is set to the specified value.

The comparison operations are classified into the following types, which are specified by interface functions:

  • HMPPS_Threshold_LTVal

    For the less-than operation, the calculation formula is as follows:

    If the source vector src is a complex sequence, the parameter level must be a real number. The calculation formula is as follows:

  • HMPPS_Threshold_GTVal

    For the greater-than operation, the calculation formula is as follows:

    If the source vector src is a complex sequence, the parameter level must be a real number. The calculation formula is as follows:

  • HMPPS_Threshold_LTValGTVal

    This mode requires that the elements of the source vector meet the conditions of being greater than the lower boundary and less than the upper boundary at the same time. levelLT is the lower boundary, and levelGT is the upper boundary. Elements whose values are smaller than levelLT are set to valueLT, and elements whose values are greater than levelGT are set to valueGT. The value of levelLT must be less than or equal to the value of levelGT. The formula is as follows:

The function interface declaration is as follows:

  • Operations on integers:

    HmppResult HMPPS_Threshold_LTVal_16s(const int16_t* src, int16_t* dst, int32_t len, int16_t level, int16_t value);

    HmppResult HMPPS_Threshold_GTVal_16s(const int16_t* src, int16_t* dst, int32_t len, int16_t level, int16_t value);

    HmppResult HMPPS_Threshold_LTValGTVal_16s(const int16_t* src, int16_t* dst, int32_t len, int16_t levelLT, int16_t valueLT, int16_t levelGT, int16_t valueGT);

    HmppResult HMPPS_Threshold_LTValGTVal_32s(const int32_t* src, int32_t* dst, int32_t len, int32_t levelLT, int32_t valueLT, int32_t levelGT, int32_t valueGT);

  • Operations on floating-point numbers:

    HmppResult HMPPS_Threshold_LTVal_32f(const float* src, float* dst, int32_t len, float level, float value);

    HmppResult HMPPS_Threshold_LTVal_64f(const double* src, double* dst, int32_t len, double level, double value);

    HmppResult HMPPS_Threshold_LTVal_32fc(const Hmpp32fc* src, Hmpp32fc* dst, int32_t len, float level, Hmpp32fc value);

    HmppResult HMPPS_Threshold_GTVal_32f(const float* src, float* dst, int32_t len, float level, float value);

    HmppResult HMPPS_Threshold_GTVal_64f(const double* src, double* dst, int32_t len, double level, double value);

    HmppResult HMPPS_Threshold_GTVal_32fc(const Hmpp32fc* src, Hmpp32fc* dst, int32_t len, float level, Hmpp32fc value);

    HmppResult HMPPS_Threshold_LTValGTVal_32f(const float* src, float* dst, int32_t len, float levelLT, float valueLT, float levelGT, float valueGT);

    HmppResult HMPPS_Threshold_LTValGTVal_64f(const double* src, double* dst, int32_t len, double levelLT, double valueLT, double levelGT, double valueGT);

  • In-place operations on integers:

    HmppResult HMPPS_Threshold_LTVal_16s_I(int16_t* srcDst, int32_t len, int16_t level, int16_t value);

    HmppResult HMPPS_Threshold_GTVal_16s_I(int16_t* srcDst, int32_t len, int16_t level, int16_t value);

    HmppResult HMPPS_Threshold_LTValGTVal_16s_I(int16_t* srcDst, int32_t len, int16_t levelLT, int16_t valueLT, int16_t levelGT, int16_t valueGT);

    HmppResult HMPPS_Threshold_LTValGTVal_32s_I(int32_t* srcDst, int32_t len, int32_t levelLT, int32_t valueLT, int32_t levelGT, int32_t valueGT);

  • In-place operations on floating-point numbers:

    HmppResult HMPPS_Threshold_LTVal_32f_I(float* srcDst, int32_t len, float level, float value);

    HmppResult HMPPS_Threshold_LTVal_64f_I(double* srcDst, int32_t len, double level, double value);

    HmppResult HMPPS_Threshold_LTVal_32fc_I(Hmpp32fc* srcDst, int32_t len, float level, Hmpp32fc value);

    HmppResult HMPPS_Threshold_GTVal_32f_I(float* srcDst, int32_t len, float level, float value);

    HmppResult HMPPS_Threshold_GTVal_64f_I(double* srcDst, int32_t len, double level, double value);

    HmppResult HMPPS_Threshold_GTVal_32fc_I(Hmpp32fc* srcDst, int32_t len, float level, Hmpp32fc value);

    HmppResult HMPPS_Threshold_LTValGTVal_32f_I(float* srcDst, int32_t len, float levelLT, float valueLT, float levelGT, float valueGT);

    HmppResult HMPPS_Threshold_LTValGTVal_64f_I(double* srcDst, int32_t len, double levelLT, double valueLT, double levelGT, double valueGT);

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

value

A specified value

Not limited, depending on the type

Input

levelLT

Lower threshold

Less than or equal to the value of levelGT

Input

levelGT

Upper limit of the threshold

Greater than levelLT

Input

valueLT

Replacement value of the lower bound

Not limited, depending on the type

Input

valueGT

Replacement value of the upper bound

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_THRESHOLD_ERR

The lower threshold is greater than the upper threshold.

HMPP_STS_THRESH_NEG_LEVEL_ERR

The threshold is less than 0.

Note

In operations on complex numbers, level must be a positive number.

Example

#define  BUFFER_SIZE_T 20

void ThresholdValExample(void)
{
    float src[BUFFER_SIZE_T] = {-1.63, 0.92, 6.15, 3.34, -1.28, 4.53, 8.79, 4.23, 2.18,  9.69,
                              5.34,  8.03, 1.90, 8.76, 4.58,  0.98, 4.30, 8.03, 11.19, 8.41};
    float dst[BUFFER_SIZE_T] = {0.00};

    int32_t i;
    HmppResult result = HMPPS_Threshold_LTVal_32f(src, dst, BUFFER_SIZE_T, 3.14, -2.71);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    printf("Threshold1: result = %d.\ndst1 = ", result);
    for (i = 0; i < BUFFER_SIZE_T; i++) {
        printf(" %.2f   ", dst[i]);
    }
    HMPPS_Zero_32f(dst, BUFFER_SIZE_T);
    result = HMPPS_Threshold_GTVal_32f(src, dst, BUFFER_SIZE_T, 8.51, 2.71);
    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]);
    }
    HMPPS_Zero_32f(dst, BUFFER_SIZE_T);
    result = HMPPS_Threshold_LTValGTVal_32f(src, dst, BUFFER_SIZE_T, 3.14, 2.71, 8.51, -2.71);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    printf("\nThreshold3: result = %d.\ndst3 = ", result);
    for (i = 0; i < BUFFER_SIZE_T; i++) {
        printf(" %.2f   ", dst[i]);
    }
}

Output:

Threshold1: result = 0.
dst1 = -2.71    -2.71    6.15    3.34    -2.71    4.53    8.79    4.23    -2.71    9.69    5.34    8.03    -2.71    8.76    4.58    -2.71    4.30    8.03    11.19    8.41
Threshold2: result = 0.
dst2 = -1.63    0.92    6.15    3.34    -1.28    4.53    2.71    4.23    2.18    2.71    5.34    8.03    1.90    2.71    4.58    0.98    4.30    8.03    2.71    8.41
Threshold3: result = 0.
dst3 = 2.71    2.71    6.15    3.34    2.71    4.53    -2.71    4.23    2.71    -2.71    5.34    8.03    2.71    -2.71    4.58    2.71    4.30    8.03    -2.71    8.41