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

AddProduct

Adds the product of two vectors to the destination vector.

The calculation formula is as follows: srcDst[n] = srcDst[n] + src1[n] * src2[n], where n is within [0, len).

The function interface declaration is as follows:

  • Operations on floating-point numbers:

    HmppResult HMPPS_AddProduct_32f(const float *src1, const float *src2, float *srcDst, int32_t len);

    HmppResult HMPPS_AddProduct_64f(const double *src1, const double *src2, double *srcDst, int32_t len);

    HmppResult HMPPS_AddProduct_32fc(const Hmpp32fc *src1, const Hmpp32fc *src2, Hmpp32fc *srcDst, int32_t len);

    HmppResult HMPPS_AddProduct_64fc(const Hmpp64fc *src1, const Hmpp64fc *src2, Hmpp64fc *srcDst, int32_t len);

  • Operations on integers with scaling:

    HmppResult HMPPS_AddProduct_16s_S(const int16_t *src1, const int16_t *src2, int16_t *srcDst, int32_t len, double scale);

    HmppResult HMPPS_AddProduct_16s32s_S(const int16_t *src1, const int16_t *src2, int32_t *srcDst, int32_t len, double scale);

    HmppResult HMPPS_AddProduct_32s_S(const int32_t *src1, const int32_t *src2, int32_t *srcDst, int32_t len, double scale);

Parameters

Parameter

Description

Value Range

Input/Output

src1

Pointer to the first source vector

The value cannot be NULL.

Input

src2

Pointer to the second source vector

The value cannot be NULL.

Input

srcDst

Pointer to the destination vector

The value cannot be NULL.

Input/Output

len

Vector length

(0, INT_MAX]

Input

scale

Scale factor

scale = 2n, 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 src1, src2, or srcDst is NULL.

HMPP_STS_SIZE_ERR

The value of len is less than or equal to 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 AddProductExample(void)
{
    Hmpp64fc src1[BUFFER_SIZE_T] = {
        12130, -6322,  19151, -18246, 26700,  -6189, 10090, -5686, -17433, -29849,
        -1064, -12397, 9846,  -18348, -27613, 9270,  12561, 24201, -8793,  -3989
    };
    Hmpp64fc src2[BUFFER_SIZE_T] = {
        -26409, -11074, -16480, -2962, 8889,   15810, -25568, -16638, 15040,  13349,
        23212,  -27356, 6691,   26146, -17678, 15252, -20052, 25113,  -16404, 24897
    };
    Hmpp64fc srcDst[BUFFER_SIZE_T] = {
        -26409, -11074, -16480, -2962, 8889,   15810, -25568, -16638, 15040,  13349,
        23212,  -27356, 6691,   26146, -17678, 15252, -20052, 25113,  -16404, 24897
    };
    int32_t i;

    HmppResult result = HMPPS_AddProduct_64fc(src1, src2, srcDst, BUFFER_SIZE_T);
    printf("result = %d \n dst =", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }

    for (i = 0; i < BUFFER_SIZE_T; i++) {
        printf(" %f ", srcDst[i]);
    }
}

Output:

result = 0
 dst = -390377407.000000  -369669612.000000  335193279.000000  -352610356.000000  136277021.000000  -363806688.000000  545613085.000000  346738896.000000  -859652937.000000  243538101.000000