Adelsbach/VSIPL
Core Programming Reference Guide
DD-00016-015
Core

This manual is preliminary and incomplete.
While our Core implementation implements all functions given in the standard we are still working on completing this documentation.

Please refer to the VSIPL standard for a complete function reference of the Core profile until we have completed work on this documentation.

6.1.11 vsip_dmprodt_p - Matrix-Matrix Product with Transposition

void vsip_mprodt_f(const vsip_mview_f *a, const vsip_mview_f *b, const vsip_mview_f *r); 
void vsip_cmprodt_f(const vsip_cmview_f *a, const vsip_cmview_f *b, const vsip_cmview_f *r);
Description

This function computes the product of matrix A and the transpose of matrix B, storing the result in matrix R. The operation performed is:

     ∑︁n
ri,j=    ai,k·bj,k
     k=1

for all i and j, where A is an m × n matrix, B is an p ×n matrix, and R is the resulting m ×p matrix.

This operation is equivalent to the matrix product R= A ·BT.

Parameters
Example

vsip_mview_f *A, *B, *R; 
vsip_length m = 3, n = 4, p = 2; 
 
// Create matrices 
A = vsip_mcreate_f(m, n, VSIP_ROW, VSIP_MEM_NONE);  // 3x4 matrix 
B = vsip_mcreate_f(p, n, VSIP_ROW, VSIP_MEM_NONE);  // 2x4 matrix 
R = vsip_mcreate_f(m, p, VSIP_ROW, VSIP_MEM_NONE);  // 3x2 result matrix 
 
// Initialize matrices A and B with some values 
// Initialize matrix A (3x4) 
for (vsip_index i = 0; i < m; i++) { 
    for (vsip_index j = 0; j < n; j++) { 
        vsip_mput_f(A, i, j, (float)(i*n + j + 1)); 
    } 
} 
 
// Initialize matrix B (2x4) 
for (vsip_index i = 0; i < p; i++) { 
    for (vsip_index j = 0; j < n; j++) { 
        vsip_mput_f(B, i, j, (float)(i*n + j + 1)); 
    } 
} 
 
// Compute matrix product with transposition: R = A * B^T 
vsip_mprodt_f(A, B, R); 
 
// Print the matrices 
printf("Matrix A (%lux%lu):\n", m, n); 
for (vsip_index i = 0; i < m; i++) { 
    for (vsip_index j = 0; j < n; j++) { 
        printf("%8.2f ", vsip_mget_f(A, i, j)); 
    } 
    printf("\n"); 
} 
 
printf("\nMatrix B (%lux%lu):\n", p, n); 
for (vsip_index i = 0; i < p; i++) { 
    for (vsip_index j = 0; j < n; j++) { 
        printf("%8.2f ", vsip_mget_f(B, i, j)); 
    } 
    printf("\n"); 
} 
 
printf("\nResult matrix R = A * B^T (%lux%lu):\n", m, p); 
for (vsip_index i = 0; i < m; i++) { 
    for (vsip_index j = 0; j < p; j++) { 
        printf("%8.2f ", vsip_mget_f(R, i, j)); 
    } 
    printf("\n"); 
} 
 
// Clean up 
vsip_malldestroy_f(A); 
vsip_malldestroy_f(B); 
vsip_malldestroy_f(R);
Notes