1 //------------------------------------------------------------------------------
2 // GxB_Matrix_export_CSR: export a matrix in CSR format
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_export.h"
11
12 #define GB_FREE_ALL ;
13
GxB_Matrix_export_CSR(GrB_Matrix * A,GrB_Type * type,GrB_Index * nrows,GrB_Index * ncols,GrB_Index ** Ap,GrB_Index ** Aj,void ** Ax,GrB_Index * Ap_size,GrB_Index * Aj_size,GrB_Index * Ax_size,bool * is_uniform,bool * jumbled,const GrB_Descriptor desc)14 GrB_Info GxB_Matrix_export_CSR // export and free a CSR matrix
15 (
16 GrB_Matrix *A, // handle of matrix to export and free
17 GrB_Type *type, // type of matrix exported
18 GrB_Index *nrows, // number of rows of the matrix
19 GrB_Index *ncols, // number of columns of the matrix
20
21 GrB_Index **Ap, // row "pointers"
22 GrB_Index **Aj, // column indices
23 void **Ax, // values
24 GrB_Index *Ap_size, // size of Ap in bytes
25 GrB_Index *Aj_size, // size of Aj in bytes
26 GrB_Index *Ax_size, // size of Ax in bytes
27 bool *is_uniform, // if true, A has uniform values (TODO:::unsupported)
28
29 bool *jumbled, // if true, indices in each row may be unsorted
30 const GrB_Descriptor desc
31 )
32 {
33
34 //--------------------------------------------------------------------------
35 // check inputs and get the descriptor
36 //--------------------------------------------------------------------------
37
38 GB_WHERE1 ("GxB_Matrix_export_CSR (&A, &type, &nrows, &ncols, "
39 "&Ap, &Aj, &Ax, &Ap_size, &Aj_size, &Ax_size, &is_uniform, "
40 "&jumbled, desc)") ;
41 GB_BURBLE_START ("GxB_Matrix_export_CSR") ;
42 GB_RETURN_IF_NULL (A) ;
43 GB_RETURN_IF_NULL_OR_FAULTY (*A) ;
44 GB_GET_DESCRIPTOR (info, desc, xx1, xx2, xx3, xx4, xx5, xx6, xx7) ;
45 ASSERT_MATRIX_OK (*A, "A to export as CSR", GB0) ;
46
47 //--------------------------------------------------------------------------
48 // ensure the matrix is sparse CSR
49 //--------------------------------------------------------------------------
50
51 if ((*A)->is_csc)
52 {
53 // A = A', done in-place, to put A in CSR format
54 GBURBLE ("(transpose) ") ;
55 GB_OK (GB_transpose (NULL, NULL, false, *A, // in_place_A
56 NULL, NULL, NULL, false, Context)) ;
57 }
58
59 //--------------------------------------------------------------------------
60 // finish any pending work
61 //--------------------------------------------------------------------------
62
63 if (jumbled == NULL)
64 {
65 // the exported matrix cannot be jumbled
66 GB_MATRIX_WAIT (*A) ;
67 }
68 else
69 {
70 // the exported matrix is allowed to be jumbled
71 GB_MATRIX_WAIT_IF_PENDING_OR_ZOMBIES (*A) ;
72 }
73
74 //--------------------------------------------------------------------------
75 // ensure the matrix is sparse
76 //--------------------------------------------------------------------------
77
78 GB_OK (GB_convert_any_to_sparse (*A, Context)) ;
79
80 //--------------------------------------------------------------------------
81 // export the matrix
82 //--------------------------------------------------------------------------
83
84 ASSERT (GB_IS_SPARSE (*A)) ;
85 ASSERT (!((*A)->is_csc)) ;
86 ASSERT (!GB_ZOMBIES (*A)) ;
87 ASSERT (GB_IMPLIES (jumbled == NULL, !GB_JUMBLED (*A))) ;
88 ASSERT (!GB_PENDING (*A)) ;
89
90 int sparsity ;
91 bool is_csc ;
92
93 info = GB_export (A, type, ncols, nrows, false,
94 Ap, Ap_size, // Ap
95 NULL, NULL, // Ah
96 NULL, NULL, // Ab
97 Aj, Aj_size, // Ai
98 Ax, Ax_size, // Ax
99 NULL, jumbled, NULL, // jumbled or not
100 &sparsity, &is_csc, // sparse by row
101 is_uniform, Context) ;
102
103 if (info == GrB_SUCCESS)
104 {
105 ASSERT (sparsity == GxB_SPARSE) ;
106 ASSERT (!is_csc) ;
107 }
108 GB_BURBLE_END ;
109 return (info) ;
110 }
111
112