1 //------------------------------------------------------------------------------
2 // SLIP_LU/slip_sparse_realloc: double the space for a sparse mpz matrix
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 expands a CSC SLIP_matrix by doubling its size. This
12 * version merely expands x and i and does not initialize/allocate the values!
13 * The only purpose of this function is for the factorization, it does not work
14 * for general sparse matrices
15 */
16
17 #include "slip_internal.h"
18
slip_sparse_realloc(SLIP_matrix * A)19 SLIP_info slip_sparse_realloc
20 (
21 SLIP_matrix* A // the matrix to be expanded
22 )
23 {
24
25 //--------------------------------------------------------------------------
26 // check inputs
27 //--------------------------------------------------------------------------
28
29 SLIP_REQUIRE (A, SLIP_CSC, SLIP_MPZ) ;
30
31 //--------------------------------------------------------------------------
32 // double the size of A->x and A->i
33 //--------------------------------------------------------------------------
34
35 int64_t nzmax = A->nzmax ;
36
37 bool okx, oki ;
38 A->x.mpz = (mpz_t *)
39 SLIP_realloc (2*nzmax, nzmax, sizeof (mpz_t), A->x.mpz, &okx) ;
40 A->i = (int64_t *)
41 SLIP_realloc (2*nzmax, nzmax, sizeof (int64_t), A->i, &oki) ;
42 if (!oki || !okx)
43 {
44 return (SLIP_OUT_OF_MEMORY) ;
45 }
46
47 A->nzmax = 2*nzmax ;
48
49 //--------------------------------------------------------------------------
50 // set newly allocated mpz entries to NULL
51 //--------------------------------------------------------------------------
52
53 for (int64_t p = nzmax ; p < 2*nzmax ; p++)
54 {
55 SLIP_MPZ_SET_NULL (A->x.mpz [p]) ;
56 }
57
58 return (SLIP_OK) ;
59 }
60
61