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

MMul

Multiplies one matrix by another matrix.

op(A) is an m*k matrix, op(B) is a k*n matrix, and C is an m*n matrix.

The function interface declaration is as follows:

HmppResult HMPPS_MMul_32f(const float* src1, const float *src2, float dst, int32_t mlen, int32_t nlen, int32_t klen);

HmppResult HMPPS_MMul_64f(const double* src1, const double *src2, double dst, int32_t mlen, int32_t nlen, int32_t klen);

HmppResult HMPPS_MMul_32fc(const Hmpp32fc * src1, const Hmpp32fc *src2, Hmpp32fc dst, int32_t mlen, int32_t nlen, int32_t klen);

HmppResult HMPPS_MMul_64fc(const Hmpp64fc * src1, const Hmpp64fc *src2, Hmpp64fc dst, int32_t mlen, int32_t nlen, int32_t klen);

Parameters

Parameter

Description

Value Range

Input/Output

src1

Matrix A

The value cannot be NULL.

Input

src2

Matrix B

The value cannot be NULL.

Input

dst

Destination matrix C

The value cannot be NULL.

Output

mlen

Rows of matrix A and matrix C

> 0

Input

nlen

Columns of matrix B and matrix C

> 0

Input

klen

Rows of matrix B and columns of matrix A

> 0

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 dst is NULL.

HMPP_STS_SIZE_ERR

The value of mlen, nlen, or klen is less than or equal to 0.

HMPP_STS_NO_ERR

No error occurs.

Note

The matrix of this interface is in the row-major order.

Example

#define BUFFER_SIZE1_T 12
#define BUFFER_SIZE2_T 16
void MMulExample(void)
{
    float src1[BUFFER_SIZE1_T] = {0.340188, -0.105617, 0.283099, 
                                    0.298440, 0.411647, -0.302449, 
                                   -0.164777, 0.268230, -0.222225, 
                                    0.053970, -0.022603, 0.128871};
    float src2[BUFFER_SIZE1_T] = {-0.135216, 0.013401, 0.452230, 0.416195, 
                                     0.135712, 0.217297, -0.358397, 0.106969, 
                                    -0.483699, -0.257113, -0.362768, 0.304177};
    float  dst[BUFFER_SIZE2_T];
    (void)HMPPS_Zero_32f(dst, BUFFER_SIZE2_T); //Initialize all elements of dst to 0.

    HmppResult result = HMPPS_MMul_32f(src1, src2, dst, 4, 4, 3);
    printf("result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }

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

Output:

result = 0
dst = -0.197267 -0.091180 0.088997 0.216399 0.161806 0.171213 0.097149 0.076245 0.166173 0.113214 -0.090034 -0.107483 -0.072700 -0.037323 -0.014243 0.059244