中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

AddProduct

两向量的乘积与目的向量相加。

计算公式如下:srcDst[n] = srcDst[n] + src1[n] * src2[n],n的范围为[0,len)。

函数接口声明如下:

  • 浮点数的操作:

    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);

  • 有缩放的整型数操作:

    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);

参数

参数名

描述

取值范围

输入/输出

src1

指向第一个源向量的指针。

非空

输入

src2

指向第二个源向量的指针。

非空

输入

srcDst

指向目的向量的指针。

非空

输入/输出

len

向量长度。

(0, INT_MAX]

输入

scale

缩放因数。

(0,INF)且输入为2n

输入

返回值

  • 成功:返回HMPP_STS_NO_ERR
  • 失败:返回错误码。

错误码

错误码

描述

HMPP_STS_NULL_PTR_ERR

src1、src2、srcDst这几个入参中存在空指针。

HMPP_STS_SIZE_ERR

len小于或等于0。

HMPP_STS_SCALE_ERR

scale不在(0,INF)范围内或输入为NAN。

示例

#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]);
    }
}

运行结果:

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