Rate This Document
Findability
Accuracy
Completeness
Readability

Sqr

Calculates the square of each element in src, and then stores the data in dst. The calculation process is as follows: .

When the in-place mode is used for calculation, the function obtains data from srcDst for calculation. The obtained calculation result is written into the memory area to which srcDst points, that is, .

When calculating the square of an integer, the output result may be saturated because it exceeds the value range of the corresponding data type. To obtain a more accurate result, you need to use the scale factor.

The function interface declaration is as follows:

  • Scaling of integers:

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

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

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

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

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

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

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

    HmppResult HMPPS_Sqr_16s_IS(int16_t *srcDst, int32_t len, doublescale);

  • Scaling of floating-point numbers:

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

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

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

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

  • In-place operations on floating-point numbers:

    HmppResult HMPPS_Sqr_32f_I(float *srcDst, int32_t len);

    HmppResult HMPPS_Sqr_32fc_I(Hmpp32fc *srcDst, int32_t len);

    HmppResult HMPPS_Sqr_64f_I(double *srcDst, int32_t len);

    HmppResult HMPPS_Sqr_64fc_I(Hmpp64fc *srcDst, int32_t len);

Parameters

Parameter

Description

Value Range

Input/Output

dst

Pointer to the destination vector

The value cannot be NULL.

Input

src

Pointer to the source vector

The value cannot be NULL.

Input

srcDst

Pointer to the destination address of the source data.

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 must be greater than 0.

HMPP_STS_SCALE_ERR

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

Example

#define BUFFER_SIZE_T 10

void SqrExample(void)
{
    float src[BUFFER_SIZE_T] = {1.64, 1.63, -1.09, 0.71, -3.20, -0.43, 0.41, -4.83, 5.36, -4.40};
    float dst[BUFFER_SIZE_T];
    (void)HMPPS_Zero_32f(dst, BUFFER_SIZE_T); //Initialize all elements of dst to 0.

    HmppResult result = HMPPS_Sqr_32f(src, dst, BUFFER_SIZE_T);
    printf("result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }

    printf("dst =");
    for (int i = 0; i < BUFFER_SIZE_T; i++) {
        printf(" %f", dst[i]);
    }
    printf("\n");
}

Output:

result = 0
dst = 2.689600 2.656900 1.188100 0.504100 10.240001 0.184900 0.168100 23.328899 28.729601 19.360001