1 /* 2 Copyright (C) 2011 Fredrik Johansson 3 4 This file is part of FLINT. 5 6 FLINT is free software: you can redistribute it and/or modify it under 7 the terms of the GNU Lesser General Public License (LGPL) as published 8 by the Free Software Foundation; either version 2.1 of the License, or 9 (at your option) any later version. See <http://www.gnu.org/licenses/>. 10 */ 11 12 #include <stdlib.h> 13 #include "flint.h" 14 #include "fmpz_poly.h" 15 #include "fmpz_poly_mat.h" 16 17 void fmpz_poly_mat_init(fmpz_poly_mat_t A,slong rows,slong cols)18fmpz_poly_mat_init(fmpz_poly_mat_t A, slong rows, slong cols) 19 { 20 slong i; 21 22 if (rows != 0) 23 A->rows = (fmpz_poly_struct **) flint_malloc(rows * sizeof(fmpz_poly_struct *)); 24 else 25 A->rows = NULL; 26 27 if (rows != 0 && cols != 0) 28 { 29 A->entries = (fmpz_poly_struct *) flint_malloc(flint_mul_sizes(rows, cols) * sizeof(fmpz_poly_struct)); 30 31 for (i = 0; i < rows * cols; i++) 32 fmpz_poly_init(A->entries + i); 33 34 for (i = 0; i < rows; i++) 35 A->rows[i] = A->entries + i * cols; 36 } 37 else 38 { 39 A->entries = NULL; 40 if (rows != 0) 41 { 42 for (i = 0; i < rows; i++) 43 A->rows[i] = NULL; 44 } 45 } 46 47 A->r = rows; 48 A->c = cols; 49 } 50