1 //------------------------------------------------------------------------------
2 // GB_dup: make a deep copy of a sparse matrix
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 // C = A, making a deep copy. Not user-callable; this function does the work
11 // for user-callable functions GrB_*_dup.
12
13 // if numeric is false, C->x is allocated but not initialized.
14
15 // There is little use for the following feature, but (*Chandle) and A might be
16 // identical, with GrB_dup (&A, A). The input matrix A will be lost, and will
17 // result in a memory leak, unless the user application does the following
18 // (which is valid and memory-leak free):
19
20 // B = A ;
21
22 // GrB_dup (&A, A) ;
23
24 // GrB_free (&A) ;
25
26 // GrB_free (&B) ;
27
28 // A is the new copy and B is the old copy. Each should be freed when done.
29
30 #include "GB.h"
31
32 #define GB_FREE_ALL ;
33
GB_dup(GrB_Matrix * Chandle,const GrB_Matrix A,GB_Context Context)34 GrB_Info GB_dup // make an exact copy of a matrix
35 (
36 GrB_Matrix *Chandle, // handle of output matrix to create
37 const GrB_Matrix A, // input matrix to copy
38 GB_Context Context
39 )
40 {
41
42 //--------------------------------------------------------------------------
43 // check inputs
44 //--------------------------------------------------------------------------
45
46 ASSERT (Chandle != NULL) ;
47 ASSERT_MATRIX_OK (A, "A to duplicate", GB0) ;
48 (*Chandle) = NULL ;
49
50 //--------------------------------------------------------------------------
51 // delete any lingering zombies and assemble any pending tuples
52 //--------------------------------------------------------------------------
53
54 GB_MATRIX_WAIT (A) ; // TODO: keep zombies and jumbled
55
56 //--------------------------------------------------------------------------
57 // C = A
58 //--------------------------------------------------------------------------
59
60 return (GB_dup2 (Chandle, A, true, NULL, Context)) ; // new user header
61 }
62
63