NormDiff
两个向量差值的1范数(L1)、2范数(L2)或∞范数(Inf)。计算公式如下:
函数接口声明如下:
- L1范数:
HmppResult HMPPS_NormDiff_L1_32f(const float* src1, const float* src2, int32_t len, float* norm);
HmppResult HMPPS_NormDiff_L1_64f(const double* src1, const double* src2, int32_t len, double* norm);
HmppResult HMPPS_NormDiff_L1_16s32f(const int16_t* src1, const int16_t* src2, int32_t len, float* norm);
HmppResult HMPPS_NormDiff_L1_32fc64f(const Hmpp32fc* src1, const Hmpp32fc* src2, int32_t len, double* norm);
HmppResult HMPPS_NormDiff_L1_64fc64f(const Hmpp64fc* src1, const Hmpp64fc* src2, int32_t len, double* norm);
- 有缩放的L1范数:
HmppResult HMPPS_NormDiff_L1_16s32s_S(const int16_t* src1, const int16_t* src2, int32_t len, int32_t* norm, double scale);
HmppResult HMPPS_NormDiff_L1_16s64s_S(const int16_t* src1, const int16_t* src2, int32_t len, int64_t* norm, double scale);
- L2范数:
HmppResult HMPPS_NormDiff_L2_32f(const float* src1, const float* src2, int32_t len, float* norm);
HmppResult HMPPS_NormDiff_L2_64f(const double* src1, const double* src2, int32_t len, double* norm);
HmppResult HMPPS_NormDiff_L2_16s32f(const int16_t* src1, const int16_t* src2, int32_t len, float* norm);
HmppResult HMPPS_NormDiff_L2_32fc64f(const Hmpp32fc* src1, const Hmpp32fc* src2, int32_t len, double* norm);
HmppResult HMPPS_NormDiff_L2_64fc64f(const Hmpp64fc* src1, const Hmpp64fc* src2, int32_t len, double* norm);
- 有缩放的L2范数:
HmppResult HMPPS_NormDiff_L2_16s32s_S(const int16_t* src1, const int16_t* src2, int32_t len, int32_t* norm, double scale);
- 有缩放的L2Sqr范数
HmppResult HMPPS_NormDiff_L2Sqr_16s64s_S(const int16_t* src1, const int16_t* src2, int32_t len, int64_t* norm, double scale);
- 无穷范数
HmppResult HMPPS_NormDiff_Inf_32f(const float* src1, const float* src2, int32_t len, float* norm);
HmppResult HMPPS_NormDiff_Inf_64f(const double* src1, const double* src2, int32_t len, double* norm);
HmppResult HMPPS_NormDiff_Inf_16s32f(const int16_t* src1, const int16_t* src2, int32_t len, float* norm);
HmppResult HMPPS_NormDiff_Inf_32fc32f(const Hmpp32fc* rc1, const Hmpp32fc* src2, int32_t len, float* norm);
HmppResult HMPPS_NormDiff_Inf_64fc64f(const Hmpp64fc* src1, const Hmpp64fc* src2, int32_t len, double* norm);
- 有缩放的无穷范数
HmppResult HMPPS_NormDiff_Inf_16s32s_S(const int16_t* src1, const int16_t* src2, int32_t len, int32_t* norm, double scale);
参数
参数名 |
描述 |
取值范围 |
输入/输出 |
---|---|---|---|
src1 |
指向被减数的指针。 |
非空 |
输入 |
src2 |
指向减数的指针。 |
非空 |
输入 |
len |
向量长度。 |
(0,INT_MAX] |
输入 |
norm |
指向范数的指针。 |
非空 |
输出 |
scale |
缩放因数。 |
(0,INF)且输入为2^n |
输入 |
返回值
- 成功:返回HMPP_STS_NO_ERR。
- 失败:返回错误码。
错误码
错误码 |
描述 |
---|---|
HMPP_STS_NULL_PTR_ERR |
src1、src2、norm这几个入参中存在空指针。 |
HMPP_STS_SIZE_ERR |
len小于或等于0。 |
HMPP_STS_SCALE_ERR |
scale不在(0,INF)范围内或输入为nan。 |
示例
#define BUFFER_SIZE_T 10 void NormDiffExample(void) { float src1[BUFFER_SIZE_T] = {3, 0, 2, -8, 3, 1, 7, 5, -2, 1}; float src2[BUFFER_SIZE_T] = {1, -7, 3, 7, 8, 2, 4, -8, 5, 5}; float norm1[1]; float norm2[1]; float norm3[1]; HmppResult sign1, sign2, sign3; sign1 = HMPPS_NormDiff_Inf_32f(src1, src2, BUFFER_SIZE_T, norm1); printf("NormDiffInf: result = %d\n", sign1); if (sign1 != HMPP_STS_NO_ERR) { return; } printf("Inf = %.2f\n", norm1[0]); sign2 = HMPPS_NormDiff_L1_32f(src1, src2, BUFFER_SIZE_T, norm2); printf("NormDiffL1: result = %d\n", sign2); if (sign2 != HMPP_STS_NO_ERR) { return; } printf("L1 = %.2f\n", norm2[0]); sign3 = HMPPS_NormDiff_L2_32f(src1, src2, BUFFER_SIZE_T, norm3); printf("NormDiffL2: result = %d\n", sign3); if (sign3 != HMPP_STS_NO_ERR) { return; } printf("L2 = %.2f\n", norm3[0]); printf("\n"); }
运行结果:
NormDiffInf: result = 0 Inf = 15.00 NormDiffL1: result = 0 L1 = 58.00 NormDiffL2: result = 0 L2 = 23.41