Gan_Matrix mA, mB; /* declare matrices A & B */ gan_mat_form ( &mA, 0, 0 ); /* create matrix A */ gan_mat_form ( &mB, 0, 0 ); /* create matrix B */ /* reallocate & initialise A */ gan_mat_fill_va ( &mA, 2, 3, 11.0, 9.0, 7.0, 5.0, 3.0, 1.0 ); gan_mat_tpose_q ( &mA, &mB ); /* set B = A^T, reallocating B */The last two lines reallocate first and then , because both were created with zero size. Note that may have previosly been filled with other values, which are now lost.
There is also a version that creates the transpose of a matrix from scratch:
Gan_Matrix *pmB; /* declare matrix B */ pmB = gan_mat_tpose_s ( &mA ); /* create B and set B = A */If in this case matrix happens to be square, Gandalf supports in-place transpose:
/* A have the same number of rows and columns */ gan_mat_tpose_i ( &mA ); /* replace A = A^T */
There is no explicit transpose implemented in Gandalf for special square matrices. With the current matrix types supported by Gandalf, it would only be relevant anyway for triangular matrices. Implicit transpose can handle every practical situation.
Error detection: The matrix transpose routines return NULL and invoke the Gandalf error handler upon failure.