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.9 vsip_dmvprod_p - Matrix-Vector Product

void vsip_mvprod_f(const vsip_mview_f *a, const vsip_vview_f *b, const vsip_vview_f *r); 
void vsip_cmvprod_f(const vsip_cmview_f *a, const vsip_cvview_f *b, const vsip_cvview_f *r);
Description

This function computes the product of a matrix and a vector, storing the result in an output vector. The operation performed is:

r =∑︁n a  ·b
 i j=1 i,j  j

for i= 1,2,...,m, where a is an m ×n matrix, b is a vector of length n, and r is the resulting vector of length m.

This operation is equivalent to the matrix-vector product r= a·b.

Parameters
Example

vsip_mview_f *A; 
vsip_vview_f *b, *r; 
vsip_length m = 4, n = 3; 
 
// Create matrix and vectors 
A = vsip_mcreate_f(m, n, VSIP_ROW, VSIP_MEM_NONE); 
b = vsip_vcreate_f(n, VSIP_MEM_NONE); 
r = vsip_vcreate_f(m, VSIP_MEM_NONE); 
 
// Initialize matrix A and vector b with some values 
// Initialize A (4x3 matrix) 
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 vector b 
vsip_vramp_f(1.0f, 1.0f, b);  // b = [1, 2, 3] 
 
// Compute matrix-vector product: r = A * b 
vsip_mvprod_f(A, b, r); 
 
// Print the result 
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("\nVector b (%lu):\n", n); 
for (vsip_index i = 0; i < n; i++) { 
    printf("%8.2f ", vsip_vget_f(b, i)); 
} 
printf("\n"); 
 
printf("\nResult vector r (%lu):\n", m); 
for (vsip_index i = 0; i < m; i++) { 
    printf("%8.2f ", vsip_vget_f(r, i)); 
} 
printf("\n"); 
 
// Clean up 
vsip_malldestroy_f(A); 
vsip_valldestroy_f(b); 
vsip_valldestroy_f(r);
Notes