1 //------------------------------------------------------------------------------
2 // GB_hyper_pack: create a sparse shallow copy of a hypersparse 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 // The header of C itself is assumed to be statically allocated. On input C
11 // must exist but the content of the C header is uninitialized. No memory is
12 // allocated to construct C as the hyperpacked version of A. C is purely
13 // shallow.
14
15 #include "GB.h"
16 #include "GB_convert.h"
17
GB_hyper_pack(GrB_Matrix C,const GrB_Matrix A)18 GrB_Matrix GB_hyper_pack // return C
19 (
20 GrB_Matrix C, // output matrix
21 const GrB_Matrix A // input matrix, not modified.
22 )
23 {
24
25 //--------------------------------------------------------------------------
26 // check inputs
27 //--------------------------------------------------------------------------
28
29 ASSERT_MATRIX_OK (A, "hyperpack input", GB0) ;
30 ASSERT (C != NULL) ;
31 ASSERT (GB_IS_HYPERSPARSE (A)) ;
32
33 //--------------------------------------------------------------------------
34 // construct the shallow copy
35 //--------------------------------------------------------------------------
36
37 // copy the header
38 memcpy (C, A, sizeof (struct GB_Matrix_opaque)) ;
39
40 // flag the header of C as static
41 C->static_header = true ;
42
43 // remove the hyperlist
44 C->h = NULL ;
45 C->h_shallow = false ;
46
47 // flag all content of C as shallow
48 C->p_shallow = true ;
49 C->i_shallow = true ;
50 C->x_shallow = true ;
51
52 // C reduces in dimension to the # of vectors in A
53 C->vdim = C->nvec ;
54 C->plen = C->nvec ;
55 C->nvec_nonempty = C->nvec ;
56
57 //--------------------------------------------------------------------------
58 // return result
59 //--------------------------------------------------------------------------
60
61 ASSERT_MATRIX_OK (C, "hyperpack output", GB0) ;
62 ASSERT (GB_IS_SPARSE (C)) ;
63 return (C) ;
64 }
65
66