1 /* 2 Copyright (C) 2010 William Hart 3 Copyright (C) 2014 Abhinav Baid 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 "d_mat.h" 14 15 void d_mat_init(d_mat_t mat,slong rows,slong cols)16d_mat_init(d_mat_t mat, slong rows, slong cols) 17 { 18 if (rows != 0 && cols != 0) /* Allocate space for r*c small entries */ 19 { 20 slong i; 21 mat->entries = (double *) flint_calloc(flint_mul_sizes(rows, cols), sizeof(double)); 22 mat->rows = (double **) flint_malloc(rows*sizeof(double *)); /* Initialise rows */ 23 24 for (i = 0; i < rows; i++) 25 mat->rows[i] = mat->entries + i * cols; 26 } 27 else 28 { 29 mat->entries = NULL; 30 mat->rows = NULL; 31 } 32 33 mat->r = rows; 34 mat->c = cols; 35 } 36