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

6.1.10 vsip_dmprod_p - Matrix-Matrix Product

void vsip_mprod_f(const vsip_mview_f *a, const vsip_mview_f *b, const vsip_mview_f *r); 
void vsip_cmprod_f(const vsip_cmview_f *a, const vsip_cmview_f *b, const vsip_cmview_f *r);
Description

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

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

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

Parameters
Example

vsip_mview_f *A, *B, *R; 
vsip_length m = 3, n = 2, p = 4; 
 
// Create matrices 
A = vsip_mcreate_f(m, n, VSIP_ROW, VSIP_MEM_NONE); 
B = vsip_mcreate_f(n, p, VSIP_ROW, VSIP_MEM_NONE); 
R = vsip_mcreate_f(m, p, VSIP_ROW, VSIP_MEM_NONE); 
 
// Initialize matrices A and B with some values 
// Initialize matrix A (3x2) 
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 < n; i++) { 
    for (vsip_index j = 0; j < p; j++) { 
        vsip_mput_f(B, i, j, (float)(i*p + j + 1)); 
    } 
} 
 
// Compute matrix product: R = A * B 
vsip_mprod_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", n, p); 
for (vsip_index i = 0; i < n; i++) { 
    for (vsip_index j = 0; j < p; j++) { 
        printf("%8.2f ", vsip_mget_f(B, i, j)); 
    } 
    printf("\n"); 
} 
 
printf("\nResult matrix R (%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