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_copy_q ( &mA, &mB ); /* set B = A, 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 a copy of a matrix from scratch:
Gan_Matrix *pmB; /* declare matrix B */ pmB = gan_mat_copy_s ( &mA ); /* create B and set B = A */
For special square matrices, use one of the functions
Gan_SquMatrix smA, smB, *psmB; /* declare matrices A & B */ /* ... create A & B using e.g. gan_diagmat_form(), and initialise A using e.g. gan_diagmat_fill_va() ... */ gan_squmat_copy_q ( &smA, &smB ); /* set B = A, reallocating B if necessary, OR */ psmB = gan_squmat_copy_s(&smA); /* set B = A, creating B */
Error detection: The matrix copy routines return NULL and invoke the Gandalf error handler upon failure.