Line data Source code
1 : //------------------------------------------------------------------------------
2 : // LAGraph/src/test/test_export.c: test LG_check_export
3 : //------------------------------------------------------------------------------
4 :
5 : // LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved.
6 : // SPDX-License-Identifier: BSD-2-Clause
7 : //
8 : // For additional details (including references to third party source code and
9 : // other files) see the LICENSE file or contact permission@sei.cmu.edu. See
10 : // Contributors.txt for a full list of contributors. Created, in part, with
11 : // funding and support from the U.S. Government (see Acknowledgments.txt file).
12 : // DM22-0790
13 :
14 : // Contributed by Timothy A. Davis, Texas A&M University
15 :
16 : //------------------------------------------------------------------------------
17 :
18 : #include <LAGraph_test.h>
19 :
20 : char msg[LAGRAPH_MSG_LEN];
21 : LAGraph_Graph G = NULL;
22 : GrB_Type atype = NULL ;
23 : char atype_name [LAGRAPH_MAX_NAME_LEN] ;
24 :
25 : #define LEN 512
26 : char filename [LEN+1] ;
27 :
28 : typedef struct
29 : {
30 : LAGraph_Kind kind ;
31 : const char *name ;
32 : }
33 : matrix_info ;
34 :
35 : const matrix_info files [ ] =
36 : {
37 : { LAGraph_ADJACENCY_UNDIRECTED, "A.mtx" },
38 : { LAGraph_ADJACENCY_DIRECTED, "cover.mtx" },
39 : { LAGraph_ADJACENCY_UNDIRECTED, "jagmesh7.mtx" },
40 : { LAGraph_ADJACENCY_DIRECTED, "ldbc-cdlp-directed-example.mtx" },
41 : { LAGraph_ADJACENCY_UNDIRECTED, "ldbc-cdlp-undirected-example.mtx" },
42 : { LAGraph_ADJACENCY_DIRECTED, "ldbc-directed-example.mtx" },
43 : { LAGraph_ADJACENCY_UNDIRECTED, "ldbc-undirected-example.mtx" },
44 : { LAGraph_ADJACENCY_UNDIRECTED, "ldbc-wcc-example.mtx" },
45 : { LAGraph_ADJACENCY_UNDIRECTED, "LFAT5.mtx" },
46 : { LAGraph_ADJACENCY_DIRECTED, "msf1.mtx" },
47 : { LAGraph_ADJACENCY_DIRECTED, "msf2.mtx" },
48 : { LAGraph_ADJACENCY_DIRECTED, "msf3.mtx" },
49 : { LAGraph_ADJACENCY_DIRECTED, "sample2.mtx" },
50 : { LAGraph_ADJACENCY_DIRECTED, "sample.mtx" },
51 : { LAGraph_ADJACENCY_DIRECTED, "olm1000.mtx" },
52 : { LAGraph_ADJACENCY_UNDIRECTED, "bcsstk13.mtx" },
53 : { LAGraph_ADJACENCY_DIRECTED, "cryg2500.mtx" },
54 : { LAGraph_ADJACENCY_UNDIRECTED, "tree-example.mtx" },
55 : { LAGraph_ADJACENCY_DIRECTED, "west0067.mtx" },
56 : { LAGraph_ADJACENCY_UNDIRECTED, "karate.mtx" },
57 : { LAGraph_ADJACENCY_DIRECTED, "matrix_bool.mtx" },
58 : { LAGraph_ADJACENCY_DIRECTED, "matrix_int8.mtx" },
59 : { LAGraph_ADJACENCY_DIRECTED, "matrix_int16.mtx" },
60 : { LAGraph_ADJACENCY_DIRECTED, "matrix_int32.mtx" },
61 : { LAGraph_ADJACENCY_DIRECTED, "matrix_int64.mtx" },
62 : { LAGraph_ADJACENCY_DIRECTED, "matrix_uint8.mtx" },
63 : { LAGraph_ADJACENCY_DIRECTED, "matrix_uint16.mtx" },
64 : { LAGraph_ADJACENCY_DIRECTED, "matrix_int32.mtx" },
65 : { LAGraph_ADJACENCY_DIRECTED, "matrix_uint64.mtx" },
66 : { LAGraph_ADJACENCY_DIRECTED, "skew_fp32.mtx" },
67 : { LAGraph_ADJACENCY_UNDIRECTED, "pushpull.mtx" },
68 : { LAGRAPH_UNKNOWN, "" },
69 : } ;
70 :
71 : //------------------------------------------------------------------------------
72 : // test_export
73 : //------------------------------------------------------------------------------
74 :
75 1 : void test_export (void)
76 : {
77 1 : LAGraph_Init (msg);
78 1 : GrB_Matrix A = NULL, C = NULL ;
79 :
80 1 : for (int k = 0 ; ; k++)
81 31 : {
82 :
83 : // load the adjacency matrix as A
84 32 : const char *aname = files [k].name ;
85 32 : LAGraph_Kind kind = files [k].kind ;
86 32 : if (strlen (aname) == 0) break;
87 31 : TEST_CASE (aname) ;
88 31 : printf ("\nMatrix: %s\n", aname) ;
89 31 : snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
90 31 : FILE *f = fopen (filename, "r") ;
91 31 : TEST_CHECK (f != NULL) ;
92 31 : OK (LAGraph_MMRead (&A, f, msg)) ;
93 31 : OK (fclose (f)) ;
94 31 : TEST_MSG ("Loading of adjacency matrix failed") ;
95 31 : OK (LAGraph_Matrix_TypeName (atype_name, A, msg)) ;
96 31 : OK (LAGraph_TypeFromName (&atype, atype_name, msg)) ;
97 :
98 : // create the graph
99 31 : OK (LAGraph_New (&G, &A, kind, msg)) ;
100 31 : TEST_CHECK (A == NULL) ; // A has been moved into G->A
101 :
102 : // export the graph
103 31 : GrB_Index *Ap = NULL ;
104 31 : GrB_Index *Aj = NULL ;
105 31 : void *Ax = NULL ;
106 : GrB_Index Ap_len, Aj_len, Ax_len, nrows, ncols ;
107 : size_t typesize ;
108 31 : OK (GrB_Matrix_nrows (&nrows, G->A)) ;
109 31 : OK (GrB_Matrix_ncols (&ncols, G->A)) ;
110 :
111 31 : OK (LG_check_export (G, &Ap, &Aj, &Ax, &Ap_len, &Aj_len,
112 : &Ax_len, &typesize, msg)) ;
113 :
114 : #if LAGRAPH_SUITESPARSE
115 : #if GxB_IMPLEMENTATION >= GxB_VERSION (6,0,2)
116 31 : printf ("reimport and check result\n") ;
117 31 : OK (GxB_Matrix_import_CSR (&C, atype, nrows, ncols, &Ap, &Aj, &Ax,
118 : Ap_len * sizeof (GrB_Index),
119 : Aj_len * sizeof (GrB_Index),
120 : Ax_len * typesize,
121 : false, true, NULL)) ;
122 31 : OK (GrB_wait (C, GrB_MATERIALIZE)) ;
123 31 : bool ok = false ;
124 31 : OK (LAGraph_Matrix_IsEqual (&ok, G->A, C, msg)) ;
125 31 : TEST_CHECK (ok) ;
126 31 : OK (GrB_free (&C)) ;
127 : #endif
128 : #endif
129 :
130 31 : LAGraph_Free ((void **) &Ap, NULL) ;
131 31 : LAGraph_Free ((void **) &Aj, NULL) ;
132 31 : LAGraph_Free ((void **) &Ax, NULL) ;
133 31 : OK (LAGraph_Delete (&G, msg)) ;
134 : }
135 :
136 1 : LAGraph_Finalize(msg);
137 1 : }
138 :
139 : //------------------------------------------------------------------------------
140 : // test_export_brutal
141 : //------------------------------------------------------------------------------
142 :
143 : #if LAGRAPH_SUITESPARSE
144 1 : void test_export_brutal (void)
145 : {
146 1 : OK (LG_brutal_setup (msg)) ;
147 :
148 1 : GrB_Matrix A = NULL, C = NULL ;
149 :
150 1 : for (int k = 0 ; ; k++)
151 31 : {
152 :
153 : // load the adjacency matrix as A
154 32 : const char *aname = files [k].name ;
155 32 : LAGraph_Kind kind = files [k].kind ;
156 32 : if (strlen (aname) == 0) break;
157 31 : TEST_CASE (aname) ;
158 31 : printf ("\nMatrix: %s\n", aname) ;
159 31 : snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
160 31 : FILE *f = fopen (filename, "r") ;
161 31 : TEST_CHECK (f != NULL) ;
162 31 : OK (LAGraph_MMRead (&A, f, msg)) ;
163 31 : OK (fclose (f)) ;
164 31 : TEST_MSG ("Loading of adjacency matrix failed") ;
165 :
166 31 : OK (LAGraph_Matrix_TypeName (atype_name, A, msg)) ;
167 31 : OK (LAGraph_TypeFromName (&atype, atype_name, msg)) ;
168 :
169 : // create the graph
170 31 : OK (LAGraph_New (&G, &A, kind, msg)) ;
171 31 : TEST_CHECK (A == NULL) ; // A has been moved into G->A
172 :
173 : // export the graph
174 31 : GrB_Index *Ap = NULL ;
175 31 : GrB_Index *Aj = NULL ;
176 31 : void *Ax = NULL ;
177 : GrB_Index Ap_len, Aj_len, Ax_len, nrows, ncols ;
178 : size_t typesize ;
179 31 : OK (GrB_Matrix_nrows (&nrows, G->A)) ;
180 31 : OK (GrB_Matrix_ncols (&ncols, G->A)) ;
181 :
182 236 : LG_BRUTAL_BURBLE (LG_check_export (G, &Ap, &Aj, &Ax, &Ap_len, &Aj_len,
183 : &Ax_len, &typesize, msg)) ;
184 :
185 : #if GxB_IMPLEMENTATION >= GxB_VERSION (6,0,2)
186 31 : printf ("reimport and check result\n") ;
187 31 : OK (GxB_Matrix_import_CSR (&C, atype, nrows, ncols, &Ap, &Aj, &Ax,
188 : Ap_len * sizeof (GrB_Index),
189 : Aj_len * sizeof (GrB_Index),
190 : Ax_len * typesize,
191 : false, true, NULL)) ;
192 31 : OK (GrB_wait (C, GrB_MATERIALIZE)) ;
193 31 : bool ok = false ;
194 31 : OK (LAGraph_Matrix_IsEqual (&ok, G->A, C, msg)) ;
195 31 : TEST_CHECK (ok) ;
196 272 : LG_BRUTAL_BURBLE (LAGraph_Matrix_IsEqual (&ok, G->A, C, msg)) ;
197 31 : TEST_CHECK (ok) ;
198 31 : OK (GrB_free (&C)) ;
199 : #endif
200 :
201 31 : LAGraph_Free ((void **) &Ap, NULL) ;
202 31 : LAGraph_Free ((void **) &Aj, NULL) ;
203 31 : LAGraph_Free ((void **) &Ax, NULL) ;
204 31 : OK (LAGraph_Delete (&G, msg)) ;
205 : }
206 :
207 1 : OK (LG_brutal_teardown (msg)) ;
208 1 : }
209 : #endif
210 :
211 : //****************************************************************************
212 : //****************************************************************************
213 : TEST_LIST = {
214 : {"test_export", test_export },
215 : #if LAGRAPH_SUITESPARSE
216 : {"test_export_brutal", test_export_brutal },
217 : #endif
218 : {NULL, NULL}
219 : };
|