1 /*
2     Copyright (C) 2010 Fredrik Johansson
3     Copyright (C) 2012 Sebastian Pancratz
4 
5     This file is part of FLINT.
6 
7     FLINT is free software: you can redistribute it and/or modify it under
8     the terms of the GNU Lesser General Public License (LGPL) as published
9     by the Free Software Foundation; either version 2.1 of the License, or
10     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
11 */
12 
13 #include <stdlib.h>
14 #include "fmpz_poly_mat.h"
15 
16 void
fmpz_poly_mat_transpose(fmpz_poly_mat_t B,const fmpz_poly_mat_t A)17 fmpz_poly_mat_transpose(fmpz_poly_mat_t B, const fmpz_poly_mat_t A)
18 {
19     slong i, j;
20 
21     if (B->r != A->c || B->c != A->r)
22     {
23         flint_printf("Exception (fmpz_poly_mat_transpose). Incompatible dimensions.\n");
24         flint_abort();
25     }
26 
27     if (A == B)  /* In-place, guaranteed to be square */
28     {
29         for (i = 0; i < A->r - 1; i++)
30             for (j = i + 1; j < A->c; j++)
31                 fmpz_poly_swap(fmpz_poly_mat_entry(B, i, j),
32                                fmpz_poly_mat_entry(B, j, i));
33     }
34     else  /* Not aliased; general case */
35     {
36         for (i = 0; i < B->r; i++)
37             for (j = 0; j < B->c; j++)
38                 fmpz_poly_set(fmpz_poly_mat_entry(B, i, j),
39                               fmpz_poly_mat_entry(A, j, i));
40     }
41 }
42