我要评分
获取效率
正确性
完整性
易理解

ThresholdNorm

Uses a constant to set the threshold for elements in a vector. Different from the Threshold interface, this interface does not contain the relOp parameter. The comparison mode is directly specified by the interface function name. There are two comparison modes:

  • HMPPS_Threshold_LT

    For the less-than operation, that is, level is the lower boundary of the source vector, the calculation formula is as follows:

    If src[n] is a complex number sequence, then:

  • HMPPS_Threshold_GT

    For the greater-than operation, that is, level is the upper boundary of the source vector, the calculation formula is as follows:

    If src[n] is a complex number sequence, then:

The function interface is declared as follows:

  • Operations on integers:

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

    HmppResult HMPPS_Threshold_LT_32s(const int32_t* src, int32_t* dst, int32_t len, int32_t level);

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

    HmppResult HMPPS_Threshold_GT_32s(const int32_t* src, int32_t* dst, int32_t len, int32_t level);

  • Operations on floating-point numbers:

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

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

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

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

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

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

  • In-place operations on integers:

    HmppResult HMPPS_Threshold_LT_16s_I(int16_t* srcDst, int32_t len, int16_t level);

    HmppResult HMPPS_Threshold_LT_32s_I(int32_t* srcDst, int32_t len, int32_t level);

    HmppResult HMPPS_Threshold_GT_16s_I(int16_t* srcDst, int32_t len, int16_t level);

    HmppResult HMPPS_Threshold_GT_32s_I(int32_t* srcDst, int32_t len, int32_t level);

  • In-place operations on floating-point numbers:

    HmppResult HMPPS_Threshold_LT_32f_I(float* srcDst, int32_t len, float level);

    HmppResult HMPPS_Threshold_LT_64f_I(double* srcDst, int32_t len, double level);

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

    HmppResult HMPPS_Threshold_GT_32f_I(float* srcDst, int32_t len, float level);

    HmppResult HMPPS_Threshold_GT_64f_I(double* srcDst, int32_t len, double level);

    HmppResult HMPPS_Threshold_GT_32fc_I(Hmpp32fc* srcDst, int32_t len, float 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 ThresholdNormExample(void)
{
    float src[BUFFER_SIZE_T] = {4.52,  5.92, 6.15, 8.17,  9.93,  6.04, 11.17, 2.79, 3.58, 0.71,
                                -0.15, 9.68, 9.13, 11.04, 10.37, 0.21, 7.47,  0.05, 2.33, -1.58};
    float dst1[BUFFER_SIZE_T] = {0.00};
    float dst2[BUFFER_SIZE_T] = {0.00};
    HmppResult result;
    result = HMPPS_Threshold_LT_32f(src, dst1, BUFFER_SIZE_T, 3.14);
    printf("Threshold1: result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    printf("dst1 =");
    for (int i = 0; i < BUFFER_SIZE_T; i++) {
        printf(" %.2f", dst1[i]);
    }
    result = HMPPS_Threshold_GT_32f(src, dst2, BUFFER_SIZE_T, 3.14);
    printf("\nThreshold2: result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    printf("dst2 =");
    for (int i = 0; i < BUFFER_SIZE_T; i++) {
        printf(" %.2f", dst2[i]);
    }
    printf("\n");
}

Output:

Threshold1: result = 0
dst1 = 4.52 5.92 6.15 8.17 9.93 6.04 11.17 3.14 3.58 3.14 3.14 9.68 9.13 11.04 10.37 3.14 7.47 3.14 3.14 3.14
Threshold2: result = 0
dst2 = 3.14 3.14 3.14 3.14 3.14 3.14 3.14 2.79 3.14 0.71 -0.15 3.14 3.14 3.14 3.14 0.21 3.14 0.05 2.33 -1.58