1 //------------------------------------------------------------------------------
2 // GB_convert_to_full: convert a matrix to full; deleting prior values
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 #include "GB.h"
11 
GB_convert_to_full(GrB_Matrix A)12 GrB_Info GB_convert_to_full     // convert matrix to full; delete prior values
13 (
14     GrB_Matrix A                // matrix to convert to full
15 )
16 {
17 
18     //--------------------------------------------------------------------------
19     // check inputs
20     //--------------------------------------------------------------------------
21 
22     GB_void *Ax_new = NULL ; size_t Ax_new_size = 0 ;
23     ASSERT_MATRIX_OK (A, "A converting to full", GB0) ;
24     GBURBLE ("(to full) ") ;
25     ASSERT (GB_ZOMBIES_OK (A)) ;
26     ASSERT (GB_JUMBLED_OK (A)) ;
27     ASSERT (GB_PENDING_OK (A)) ;
28     ASSERT (GB_IS_FULL (A) || GB_IS_BITMAP (A) || GB_IS_SPARSE (A) ||
29         GB_IS_HYPERSPARSE (A)) ;
30 
31     int64_t avdim = A->vdim ;
32     int64_t avlen = A->vlen ;
33     GrB_Index anzmax ;
34     bool ok = GB_Index_multiply (&anzmax, avlen, avdim) ;
35     if (!ok)
36     {
37         // problem too large
38         return (GrB_OUT_OF_MEMORY) ;
39     }
40 
41     //--------------------------------------------------------------------------
42     // free all prior content and allocate new space for A->x
43     //--------------------------------------------------------------------------
44 
45     GB_phbix_free (A) ;
46 
47     Ax_new = GB_MALLOC (anzmax * A->type->size, GB_void, &Ax_new_size) ;
48     if (Ax_new == NULL)
49     {
50         // out of memory
51         return (GrB_OUT_OF_MEMORY) ;
52     }
53 
54     //--------------------------------------------------------------------------
55     // transplant the new content into A
56     //--------------------------------------------------------------------------
57 
58     A->x = Ax_new ; A->x_size = Ax_new_size ;
59     A->plen = -1 ;
60     A->nvec = avdim ;
61     A->nvec_nonempty = (avlen == 0) ? 0 : avdim ;
62     A->nzmax = GB_IMAX (anzmax, 1) ;
63     A->magic = GB_MAGIC ;
64 
65     //--------------------------------------------------------------------------
66     // return result
67     //--------------------------------------------------------------------------
68 
69     ASSERT (GB_IS_FULL (A)) ;
70     ASSERT (!GB_ZOMBIES (A)) ;
71     ASSERT (!GB_JUMBLED (A)) ;
72     ASSERT (!GB_PENDING (A)) ;
73     return (GrB_SUCCESS) ;
74 }
75 
76