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