1 //------------------------------------------------------------------------------
2 // SLIP_LU/slip_create_mpz_array: create a dense mpz array
3 //------------------------------------------------------------------------------
4 
5 // SLIP_LU: (c) 2019-2020, Chris Lourenco, Jinhao Chen, Erick Moreno-Centeno,
6 // Timothy A. Davis, Texas A&M University.  All Rights Reserved.  See
7 // SLIP_LU/License for the license.
8 
9 //------------------------------------------------------------------------------
10 
11 /* Purpose: This function creates an mpz array of size n.
12  * Utilized internally for creating SLIP_MPZ matrices
13  */
14 
15 #include "slip_internal.h"
16 
slip_create_mpz_array(int64_t n)17 mpz_t* slip_create_mpz_array
18 (
19     int64_t n            // size of the array
20 )
21 {
22 
23     //--------------------------------------------------------------------------
24     // check inputs
25     //--------------------------------------------------------------------------
26 
27     if (n <= 0) {return NULL;}
28 
29     //--------------------------------------------------------------------------
30 
31     // Malloc space
32     mpz_t* x = (mpz_t*) SLIP_calloc(n, sizeof(mpz_t));
33     if (!x) {return NULL;}
34     for (int64_t i = 0; i < n; i++)
35     {
36         if (SLIP_mpz_init(x[i]) != SLIP_OK)
37         {
38             // Out of memory
39             SLIP_MPZ_SET_NULL(x[i]);
40             for (int64_t j = 0; j < n; j++)
41             {
42                 if ( x[j] != NULL)
43                 {
44                     SLIP_MPZ_CLEAR( x[j]);
45                 }
46             }
47             SLIP_FREE(x);
48             return NULL;
49         }
50     }
51     return x;
52 }
53 
54