1 //------------------------------------------------------------------------------
2 // GB_transplant_conform: transplant T into C, then conform C
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 = (type) T, then conform C to its desired sparsity structure. T is freed.
11 // All prior content of C is cleared; zombies and pending tuples are abandoned
12 // in C. C and T can have any sparsity structure on input.
13
14 #include "GB.h"
15
GB_transplant_conform(GrB_Matrix C,GrB_Type ctype,GrB_Matrix * Thandle,GB_Context Context)16 GrB_Info GB_transplant_conform // transplant and conform sparsity structure
17 (
18 GrB_Matrix C, // destination matrix to transplant into
19 GrB_Type ctype, // type to cast into
20 GrB_Matrix *Thandle, // source matrix
21 GB_Context Context
22 )
23 {
24
25 //--------------------------------------------------------------------------
26 // check inputs
27 //--------------------------------------------------------------------------
28
29 ASSERT (C != NULL) ;
30 ASSERT (Thandle != NULL) ;
31 ASSERT_MATRIX_OK (*Thandle, "T to transplant into C", GB0) ;
32 ASSERT_TYPE_OK (ctype, "ctype for transplant into C", GB0) ;
33 ASSERT (GB_ZOMBIES_OK (*Thandle)) ;
34 ASSERT (GB_JUMBLED_OK (*Thandle)) ;
35 ASSERT (GB_PENDING_OK (*Thandle)) ;
36
37 //--------------------------------------------------------------------------
38 // transplant and typecast T into C, and free T
39 //--------------------------------------------------------------------------
40
41 GrB_Info info = GB_transplant (C, ctype, Thandle, Context) ;
42
43 // T is always freed, even if the transplant runs out of memory
44 ASSERT (*Thandle == NULL ||
45 (*Thandle != NULL && (*Thandle)->static_header)) ;
46
47 if (info != GrB_SUCCESS)
48 {
49 // out of memory
50 return (info) ;
51 }
52
53 ASSERT_MATRIX_OK (C, "C transplanted", GB0) ;
54
55 //--------------------------------------------------------------------------
56 // conform C to its desired sparsity structure
57 //--------------------------------------------------------------------------
58
59 info = GB_conform (C, Context) ;
60 if (info != GrB_SUCCESS)
61 {
62 // out of memory
63 return (info) ;
64 }
65
66 ASSERT_MATRIX_OK (C, "C conformed", GB0) ;
67 return (GrB_SUCCESS) ;
68 }
69
70