Line data Source code
1 : //------------------------------------------------------------------------------
2 : // LAGraph/src/test/test_Cached_Symmetric_Structure.c
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 : //------------------------------------------------------------------------------
21 : // global variables
22 : //------------------------------------------------------------------------------
23 :
24 : LAGraph_Graph G = NULL ;
25 : char msg [LAGRAPH_MSG_LEN] ;
26 : GrB_Matrix A = NULL ;
27 : #define LEN 512
28 : char filename [LEN+1] ;
29 :
30 : //------------------------------------------------------------------------------
31 : // setup: start a test
32 : //------------------------------------------------------------------------------
33 :
34 1 : void setup (void)
35 : {
36 1 : OK (LAGraph_Init (msg)) ;
37 : // OK (LG_SET_BURBLE (true)) ;
38 1 : }
39 :
40 : //------------------------------------------------------------------------------
41 : // teardown: finalize a test
42 : //------------------------------------------------------------------------------
43 :
44 1 : void teardown (void)
45 : {
46 1 : OK (LAGraph_Finalize (msg)) ;
47 1 : }
48 :
49 : //------------------------------------------------------------------------------
50 : // test_Cached_Symmetric_Structure:
51 : //------------------------------------------------------------------------------
52 :
53 : typedef struct
54 : {
55 : bool symmetric_structure ;
56 : bool symmetric_values ;
57 : const char *name ;
58 : }
59 : matrix_info ;
60 :
61 : const matrix_info files [ ] =
62 : {
63 : 1, 1, "A.mtx",
64 : 1, 1, "LFAT5.mtx",
65 : 1, 1, "bcsstk13.mtx",
66 : // 1, 0, "complex.mtx",
67 : 0, 0, "cover.mtx",
68 : 0, 0, "cover_structure.mtx",
69 : 0, 0, "cryg2500.mtx",
70 : 0, 0, "empty.mtx",
71 : 1, 0, "full.mtx",
72 : 1, 1, "full_symmetric.mtx",
73 : 1, 1, "jagmesh7.mtx",
74 : 1, 1, "karate.mtx",
75 : 0, 0, "ldbc-cdlp-directed-example.mtx",
76 : 1, 1, "ldbc-cdlp-undirected-example.mtx",
77 : 0, 0, "ldbc-directed-example-bool.mtx",
78 : 0, 0, "ldbc-directed-example-unweighted.mtx",
79 : 0, 0, "ldbc-directed-example.mtx",
80 : 1, 1, "ldbc-undirected-example-bool.mtx",
81 : 1, 1, "ldbc-undirected-example-unweighted.mtx",
82 : 1, 1, "ldbc-undirected-example.mtx",
83 : 1, 1, "ldbc-wcc-example.mtx",
84 : 0, 0, "lp_afiro.mtx",
85 : 0, 0, "lp_afiro_structure.mtx",
86 : 0, 0, "matrix_bool.mtx",
87 : 0, 0, "matrix_fp32.mtx",
88 : 0, 0, "matrix_fp32_structure.mtx",
89 : 0, 0, "matrix_fp64.mtx",
90 : 0, 0, "matrix_int16.mtx",
91 : 0, 0, "matrix_int32.mtx",
92 : 0, 0, "matrix_int64.mtx",
93 : 0, 0, "matrix_int8.mtx",
94 : 0, 0, "matrix_uint16.mtx",
95 : 0, 0, "matrix_uint32.mtx",
96 : 0, 0, "matrix_uint64.mtx",
97 : 0, 0, "matrix_uint8.mtx",
98 : 0, 0, "msf1.mtx",
99 : 0, 0, "msf2.mtx",
100 : 0, 0, "msf3.mtx",
101 : 0, 0, "olm1000.mtx",
102 : 0, 0, "structure.mtx",
103 : 0, 0, "sample.mtx",
104 : 1, 1, "sample2.mtx",
105 : 1, 0, "skew_fp32.mtx",
106 : 1, 0, "skew_fp64.mtx",
107 : 1, 0, "skew_int16.mtx",
108 : 1, 0, "skew_int32.mtx",
109 : 1, 0, "skew_int64.mtx",
110 : 1, 0, "skew_int8.mtx",
111 : 0, 0, "sources_7.mtx",
112 : 1, 1, "tree-example.mtx",
113 : 0, 0, "west0067.mtx",
114 : 0, 0, "west0067_jumbled.mtx",
115 : 0, 0, ""
116 : } ;
117 :
118 1 : void test_Cached_Symmetric_Structure (void)
119 : {
120 1 : setup ( ) ;
121 :
122 1 : for (int k = 0 ; ; k++)
123 51 : {
124 :
125 : // load the matrix as A
126 52 : const char *aname = files [k].name ;
127 52 : bool sym_structure = files [k].symmetric_structure ;
128 52 : bool sym_values = files [k].symmetric_values ;
129 52 : if (strlen (aname) == 0) break;
130 : // printf ("%s:\n", aname) ;
131 51 : TEST_CASE (aname) ;
132 51 : snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
133 51 : FILE *f = fopen (filename, "r") ;
134 51 : TEST_CHECK (f != NULL) ;
135 51 : OK (LAGraph_MMRead (&A, f, msg)) ;
136 51 : OK (fclose (f)) ;
137 51 : TEST_MSG ("Loading of adjacency matrix failed") ;
138 :
139 : // construct a directed graph G with adjacency matrix A
140 51 : OK (LAGraph_New (&G, &A, LAGraph_ADJACENCY_DIRECTED, msg)) ;
141 51 : TEST_CHECK (A == NULL) ;
142 :
143 : // compute the is_symmetric_structure cached property
144 51 : OK (LAGraph_Cached_IsSymmetricStructure (G, msg)) ;
145 :
146 : // check the result
147 51 : if (sym_structure)
148 : {
149 20 : TEST_CHECK (G->is_symmetric_structure == LAGraph_TRUE) ;
150 : }
151 : else
152 : {
153 31 : TEST_CHECK (G->is_symmetric_structure == LAGraph_FALSE) ;
154 : }
155 :
156 : // delete all cached properties
157 51 : OK (LAGraph_DeleteCached (G, msg)) ;
158 :
159 : // try again, but precompute G->AT
160 51 : OK (LAGraph_Cached_AT (G, msg)) ;
161 51 : OK (LAGraph_Cached_IsSymmetricStructure (G, msg)) ;
162 :
163 : // check the result
164 51 : if (sym_structure)
165 : {
166 20 : TEST_CHECK (G->is_symmetric_structure == LAGraph_TRUE) ;
167 : }
168 : else
169 : {
170 31 : TEST_CHECK (G->is_symmetric_structure == LAGraph_FALSE) ;
171 : }
172 :
173 : // delete all cached properties
174 51 : OK (LAGraph_DeleteCached (G, msg)) ;
175 :
176 : // change the graph to directed, if matrix is symmetric
177 51 : if (sym_values)
178 : {
179 13 : G->kind = LAGraph_ADJACENCY_UNDIRECTED ;
180 : // recompute the symmetry cached property
181 13 : OK (LAGraph_Cached_IsSymmetricStructure (G, msg)) ;
182 13 : TEST_CHECK (G->is_symmetric_structure == LAGraph_TRUE) ;
183 : }
184 :
185 51 : OK (LAGraph_Delete (&G, msg)) ;
186 :
187 : }
188 :
189 : // check error handling
190 1 : int status = LAGraph_Cached_IsSymmetricStructure (NULL, msg) ;
191 1 : printf ("\nstatus: %d, msg: %s\n", status, msg) ;
192 1 : TEST_CHECK (status == GrB_NULL_POINTER) ;
193 :
194 1 : teardown ( ) ;
195 1 : }
196 :
197 : //-----------------------------------------------------------------------------
198 : // test_Cached_Symmetric_Structure_brutal
199 : //-----------------------------------------------------------------------------
200 :
201 : #if LG_BRUTAL_TESTS
202 1 : void test_Cached_Symmetric_Structure_brutal (void)
203 : {
204 1 : OK (LG_brutal_setup (msg)) ;
205 :
206 1 : for (int k = 0 ; ; k++)
207 51 : {
208 :
209 : // load the matrix as A
210 52 : const char *aname = files [k].name ;
211 52 : bool sym_structure = files [k].symmetric_structure ;
212 52 : bool sym_values = files [k].symmetric_values ;
213 52 : if (strlen (aname) == 0) break;
214 : // printf ("%s:\n", aname) ;
215 51 : TEST_CASE (aname) ;
216 51 : snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
217 51 : FILE *f = fopen (filename, "r") ;
218 51 : TEST_CHECK (f != NULL) ;
219 51 : OK (LAGraph_MMRead (&A, f, msg)) ;
220 51 : OK (fclose (f)) ;
221 51 : TEST_MSG ("Loading of adjacency matrix failed") ;
222 :
223 : // construct a directed graph G with adjacency matrix A
224 51 : OK (LAGraph_New (&G, &A, LAGraph_ADJACENCY_DIRECTED, msg)) ;
225 51 : TEST_CHECK (A == NULL) ;
226 :
227 : // compute the is_symmetric_structure cached property
228 357 : LG_BRUTAL (LAGraph_Cached_IsSymmetricStructure (G, msg)) ;
229 :
230 : // check the result
231 51 : if (sym_structure)
232 : {
233 20 : TEST_CHECK (G->is_symmetric_structure == LAGraph_TRUE) ;
234 : }
235 : else
236 : {
237 31 : TEST_CHECK (G->is_symmetric_structure == LAGraph_FALSE) ;
238 : }
239 :
240 : // delete all cached properties
241 51 : OK (LAGraph_DeleteCached (G, msg)) ;
242 :
243 : // try again, but precompute G->AT
244 322 : LG_BRUTAL (LAGraph_Cached_AT (G, msg)) ;
245 316 : LG_BRUTAL (LAGraph_Cached_IsSymmetricStructure (G, msg)) ;
246 :
247 : // check the result
248 51 : if (sym_structure)
249 : {
250 20 : TEST_CHECK (G->is_symmetric_structure == LAGraph_TRUE) ;
251 : }
252 : else
253 : {
254 31 : TEST_CHECK (G->is_symmetric_structure == LAGraph_FALSE) ;
255 : }
256 :
257 : // delete all cached properties
258 51 : OK (LAGraph_DeleteCached (G, msg)) ;
259 :
260 : // change the graph to directed, if matrix is symmetric
261 51 : if (sym_values)
262 : {
263 13 : G->kind = LAGraph_ADJACENCY_UNDIRECTED ;
264 : // recompute the symmetry cached property
265 13 : LG_BRUTAL (LAGraph_Cached_IsSymmetricStructure (G, msg)) ;
266 13 : TEST_CHECK (G->is_symmetric_structure == LAGraph_TRUE) ;
267 : }
268 :
269 51 : OK (LAGraph_Delete (&G, msg)) ;
270 : }
271 :
272 1 : OK (LG_brutal_teardown (msg)) ;
273 1 : }
274 : #endif
275 :
276 : //-----------------------------------------------------------------------------
277 : // TEST_LIST: the list of tasks for this entire test
278 : //-----------------------------------------------------------------------------
279 :
280 : TEST_LIST =
281 : {
282 : { "test_Symmetric_Structure", test_Cached_Symmetric_Structure },
283 : #if LG_BRUTAL_TESTS
284 : { "test_Symmetric_Structure_brutal",
285 : test_Cached_Symmetric_Structure_brutal },
286 : #endif
287 : { NULL, NULL }
288 : } ;
|