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.4 vsip_dmtrans_p - Matrix Transposition

void vsip_mtrans_f(const vsip_mview_f *a, const vsip_mview_f *c); 
void vsip_cmtrans_f(const vsip_cmview_f *a, const vsip_cmview_f *c);
Description

This function computes the transpose of matrix A and stores the result in matrix C. The transpose operation exchanges the rows and columns of the matrix, such that element ci,j of the output matrix is equal to element aj,i of the input matrix.

For an m ×n input matrix A, the output matrix C must be of size n ×m.

Parameters
Example

vsip_mview_f *A, *C; 
vsip_length m = 3, n = 4; 
 
// Create input matrix (3x4) 
A = vsip_mcreate_f(m, n, VSIP_ROW, VSIP_MEM_NONE); 
 
// Initialize matrix A with some values 
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)); 
    } 
} 
 
// Create output matrix (4x3) for the transpose 
C = vsip_mcreate_f(n, m, VSIP_ROW, VSIP_MEM_NONE); 
 
// Compute the transpose: C = A^T 
vsip_mtrans_f(A, C); 
 
// Print the original and transposed matrices 
printf("Original matrix A (%lux%lu):\n", m, n); 
for (vsip_index i = 0; i < m; i++) { 
    for (vsip_index j = 0; j < n; j++) { 
        printf("%6.1f ", vsip_mget_f(A, i, j)); 
    } 
    printf("\n"); 
} 
 
printf("\nTransposed matrix C (%lux%lu):\n", n, m); 
for (vsip_index i = 0; i < n; i++) { 
    for (vsip_index j = 0; j < m; j++) { 
        printf("%6.1f ", vsip_mget_f(C, i, j)); 
    } 
    printf("\n"); 
} 
 
// Clean up 
vsip_malldestroy_f(A); 
vsip_malldestroy_f(C);
Notes