Rate This Document
Findability
Accuracy
Completeness
Readability

Sqrt

Calculates the square root of each element in a vector.

The calculation formula is: .

For in-place operation functions, the calculation formula is: .

The formula for calculating the square root of a complex number is as follows:

.

The function interface declaration is as follows:

  • Operations on floating-point numbers:

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

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

    HmppResult HMPPS_Sqrt_32fc(const Hmpp32fc *src, Hmpp32fc *dst, int32_t len);

    HmppResult HMPPS_Sqrt_64fc(const Hmpp64fc *src, Hmpp64fc *dst, int32_t len);

  • Scaling of integers:

    HmppResult HMPPS_Sqrt_8u_S(const uint8_t *src, uint16_t *dst, int32_t len, double scale);

    HmppResult HMPPS_Sqrt_16u_S(const uint16_t *src, uint16_t *dst, int32_t len, double scale);

    HmppResult HMPPS_Sqrt_16s_S(const int16_t *src, int16_t *dst, int32_t len, double scale);

    HmppResult HMPPS_Sqrt_32s16s_S(const int32_t *src, int16_t *dst, int32_t len, double scale);

    HmppResult HMPPS_Sqrt_16sc_S(const Hmpp16sc *src, Hmpp16sc *dst, int32_t len, double scale);

  • In-place operations on floating-point numbers:

    HmppResult HMPPS_Sqrt_32f_I(float *srcDst, int32_t len);

    HmppResult HMPPS_Sqrt_64f_I(double *srcDst, int32_t len);

    HmppResult HMPPS_Sqrt_32fc_I(Hmpp32fc *srcDst, int32_t len);

    HmppResult HMPPS_Sqrt_64fc_I(Hmpp64fc *srcDst, int32_t len);

  • In-place scaling on integers:

    HmppResult HMPPS_Sqrt_8u_IS(uint8_t *srcDst, int32_t len, double scale);

    HmppResult HMPPS_Sqrt_16u_IS(uint16_t *srcDst, int32_t len, double scale);

    HmppResult HMPPS_Sqrt_16s_IS(int16_t *srcDst, int32_t len, double scale);

    HmppResult HMPPS_Sqrt_16sc_IS(Hmpp16sc *srcDst, int32_t len, double scale);

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

scale

Scale factor

scale = 2^n, where n is an integer. The value is within (0, INF).

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_SQRT_NEG_ARG

The number for which the square root is to be calculated is a negative number.

HMPP_STS_SCALE_ERR

The value of scale is not within the range (0, INF) or is NaN.

Example

#define  BUFFER_SIZE 10
void SqrtExample(void)
{
    float src[BUFFER_SIZE] = { 1.28, 4.53, 8.79, 4.23, 2.18, 9.69, 5.34, 8.03, 1.90, 8.76};
    float dst[BUFFER_SIZE] = { 0.00 };
    HmppResult result;
    int32_t i = 0;
    result = HMPPS_Sqrt_32f(src, dst, BUFFER_SIZE);
    printf("result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }

    printf("dst = ");
    for(; i < BUFFER_SIZE; ++i){
        printf(" %.2f", dst[i]);
    }
    printf("\n");
}

Output:

result = 0
dst = 1.13 2.13 2.96 2.06 1.48 3.11 2.31 2.83 1.38 2.96