Sub
Subtracts a vector from another vector.
The function interface declaration is as follows:
- Operations on integers:
HmppResult HMPPS_Sub_16s(const int16_t *src1, const int16_t *src2, int16_t *dst, int32_t len);
- Operations on floating-point numbers:
HmppResult HMPPS_Sub_32f(const float *src1, const float *src2, float *dst, int32_t len);
HmppResult HMPPS_Sub_64f(const double *src1, const double *src2, double *dst, int32_t len);
HmppResult HMPPS_Sub_32fc(const Hmpp32fc *src1, const Hmpp32fc *src2, Hmpp32fc *dst, int32_t len);
HmppResult HMPPS_Sub_16s32f(const int16_t *src1, const int16_t *src2, float *dst, int32_t len);
HmppResult HMPPS_Sub_64fc(const Hmpp64fc *src1, const Hmpp64fc *src2, Hmpp64fc *dst, int32_t len);
- Operations on integers with scaling:
HmppResult HMPPS_Sub_16s_S(const int16_t *src1, const int16_t *src2, int16_t *dst, int32_t len, double scale);
HmppResult HMPPS_Sub_32s_S(const int32_t *src1, const int32_t *src2, int32_t *dst, int32_t len, double scale);
HmppResult HMPPS_Sub_8u_S(const uint8_t *src1, const uint8_t *src2, uint8_t *dst, int32_t len, double scale);
HmppResult HMPPS_Sub_16u_S(const uint16_t *src1, const uint16_t *src2, uint16_t *dst, int32_t len, double scale);
HmppResult HMPPS_Sub_16sc_S(const Hmpp16sc *src1, const Hmpp16sc *src2, Hmpp16sc *dst, int32_t len, double scale);
HmppResult HMPPS_Sub_32sc_S(const Hmpp32sc *src1, const Hmpp32sc *src2, Hmpp32sc *dst, int32_t len, int32_t scale);
- In-place operations on integers:
HmppResult HMPPS_Sub_16s_I(const int16_t *src, int16_t *srcDst, int32_t len);
- In-place operations on floating-point numbers:
HmppResult HMPPS_Sub_32f_I(const float *src, float *srcDst, int32_t len);
HmppResult HMPPS_Sub_64f_I(const double *src, double *srcDst, int32_t len);
HmppResult HMPPS_Sub_32fc_I(const Hmpp32fc *src, Hmpp32fc *srcDst, int32_t len);
HmppResult HMPPS_Sub_64fc_I(const Hmpp64fc *src, Hmpp64fc *srcDst, int32_t len);
- In-place operations on integers with scaling:
HmppResult HMPPS_Sub_16s_IS(const int16_t *src1, int16_t *srcDst, int32_t len, double scale);
HmppResult HMPPS_Sub_32s_IS(const int32_t *src1, int32_t *srcDst, int32_t len, doublescale);
HmppResult HMPPS_Sub_8u_IS(const uint8_t *src, uint8_t *srcDst, int32_t len, double scale);
HmppResult HMPPS_Sub_16u_IS(const uint16_t *src, uint16_t *srcDst, int32_t len, doublescale);
HmppResult HMPPS_Sub_16sc_IS(const Hmpp16sc *src, Hmpp16sc *srcDst, int32_t len, double scale);
HmppResult HMPPS_Sub_32sc_IS(const Hmpp32sc *src, Hmpp32sc *srcDst, int32_t len, double scale);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src1 |
Pointer to the subtrahend |
The value cannot be NULL. |
Input |
src2 |
Pointer to the minuend |
The value cannot be NULL. |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
src |
Pointer to the subtrahend vector for in-place operations |
The value cannot be NULL. |
Input |
srcDst |
Pointer to the minuend 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 src1, src2, dst, src, 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 SubExample(void)
{
float src1[BUFFER_SIZE_T] = { -1.40, 10.85, 7.26, 8.98, 0.26, 6.47, 10.42, 8.64, 3.22, 10.90};
float src2[BUFFER_SIZE_T] = { 10.11, 4.27, 0.53, 4.00, 4.73, -1.23, 6.44, 8.88, 0.78, 5.33};
float dst[BUFFER_SIZE_T];
(void)HMPPS_Zero_32f(dst, BUFFER_SIZE_T);
HmppResult result = HMPPS_Sub_32f(src1, src2, 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(" %.2f", dst[i]);
}
printf("\n");
}
Output:
sub: result = 0. dst = 11.51 -6.58 -6.73 -4.98 4.47 -7.70 -3.98 0.24 -2.44 -5.57