1 //------------------------------------------------------------------------------
2 // GB_convert_any_to_sparse: convert any matrix to sparse
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 #define GB_FREE_ALL ;
12
GB_convert_any_to_sparse(GrB_Matrix A,GB_Context Context)13 GrB_Info GB_convert_any_to_sparse // convert to sparse
14 (
15 GrB_Matrix A, // matrix to convert to sparse
16 GB_Context Context
17 )
18 {
19
20 //--------------------------------------------------------------------------
21 // check inputs
22 //--------------------------------------------------------------------------
23
24 GrB_Info info ;
25 ASSERT_MATRIX_OK (A, "A being converted to sparse", GB0) ;
26 ASSERT (GB_ZOMBIES_OK (A)) ;
27 ASSERT (GB_JUMBLED_OK (A)) ;
28 ASSERT (GB_PENDING_OK (A)) ;
29
30 //--------------------------------------------------------------------------
31 // convert A to sparse
32 //--------------------------------------------------------------------------
33
34 if (GB_IS_HYPERSPARSE (A))
35 {
36 // convert from hypersparse to sparse
37 GB_OK (GB_convert_hyper_to_sparse (A, Context)) ;
38 }
39 else if (GB_IS_FULL (A))
40 {
41 // convert from full to sparse
42 GB_OK (GB_convert_full_to_sparse (A, Context)) ;
43 }
44 else if (GB_IS_BITMAP (A))
45 {
46 // convert from bitmap to sparse
47 GB_OK (GB_convert_bitmap_to_sparse (A, Context)) ;
48 }
49 else
50 {
51 // already sparse; nothing to do
52 ;
53 }
54
55 //--------------------------------------------------------------------------
56 // return result
57 //--------------------------------------------------------------------------
58
59 ASSERT_MATRIX_OK (A, "A to sparse", GB0) ;
60 ASSERT (GB_IS_SPARSE (A)) ;
61 ASSERT (GB_ZOMBIES_OK (A)) ;
62 ASSERT (GB_JUMBLED_OK (A)) ;
63 ASSERT (GB_PENDING_OK (A)) ;
64 return (GrB_SUCCESS) ;
65 }
66
67