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);
This function computes the transpose of matrix
and stores the result in matrix
. The transpose operation exchanges the
rows and columns of the matrix, such that element
of the output matrix is equal to element
of the input
matrix.
For an
input matrix
, the output matrix
must be of size
.
const vsip_dmview_p* a: Pointer to the input matrix of size
.
const vsip_dmview_p* c: Pointer to the output matrix of size
that will store the transposed result.
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);
The output matrix
must have dimensions
where the input matrix
has dimensions
.
For in-place transposition (when
), consider using vsip_dmtransview_p to create a transposed view.