Line data Source code
1 : //----------------------------------------------------------------------------
2 : // LAGraph/src/test/test_SWrite.c: test cases for LAGraph_SWrite and SRead
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 <stdio.h>
19 : #include <acutest.h>
20 : #include <LAGraphX.h>
21 : #include <LAGraph_test.h>
22 :
23 : char msg [LAGRAPH_MSG_LEN] ;
24 : LAGraph_Graph G = NULL ;
25 : GrB_Matrix A = NULL ;
26 : GrB_Matrix B = NULL ;
27 : GrB_Matrix *S = NULL ;
28 :
29 : #define LEN 512
30 : char filename [LEN+1] ;
31 :
32 : #define NFILES 51
33 : const char *files [ ] =
34 : {
35 : "A.mtx",
36 : "cover.mtx",
37 : "cover_structure.mtx",
38 : "jagmesh7.mtx",
39 : "ldbc-cdlp-directed-example.mtx",
40 : "ldbc-cdlp-undirected-example.mtx",
41 : "ldbc-directed-example-bool.mtx",
42 : "ldbc-directed-example.mtx",
43 : "ldbc-directed-example-unweighted.mtx",
44 : "ldbc-undirected-example-bool.mtx",
45 : "ldbc-undirected-example.mtx",
46 : "ldbc-undirected-example-unweighted.mtx",
47 : "ldbc-wcc-example.mtx",
48 : "LFAT5.mtx",
49 : "msf1.mtx",
50 : "msf2.mtx",
51 : "msf3.mtx",
52 : "sample2.mtx",
53 : "sample.mtx",
54 : "sources_7.mtx",
55 : "olm1000.mtx",
56 : "bcsstk13.mtx",
57 : "cryg2500.mtx",
58 : "tree-example.mtx",
59 : "west0067.mtx",
60 : "lp_afiro.mtx",
61 : "lp_afiro_structure.mtx",
62 : "karate.mtx",
63 : "matrix_bool.mtx",
64 : "matrix_int8.mtx",
65 : "matrix_int16.mtx",
66 : "matrix_int32.mtx",
67 : "matrix_int64.mtx",
68 : "matrix_uint8.mtx",
69 : "matrix_uint16.mtx",
70 : "matrix_uint32.mtx",
71 : "matrix_uint64.mtx",
72 : "matrix_fp32.mtx",
73 : "matrix_fp32_structure.mtx",
74 : "matrix_fp64.mtx",
75 : "west0067_jumbled.mtx",
76 : "skew_fp32.mtx",
77 : "skew_fp64.mtx",
78 : "skew_int8.mtx",
79 : "skew_int16.mtx",
80 : "skew_int32.mtx",
81 : "skew_int64.mtx",
82 : "structure.mtx",
83 : "full.mtx",
84 : "full_symmetric.mtx",
85 : "empty.mtx",
86 : "",
87 : } ;
88 :
89 : //****************************************************************************
90 1 : void test_SSaveSet (void)
91 : {
92 : #if LAGRAPH_SUITESPARSE
93 1 : LAGraph_Init (msg) ;
94 :
95 : // load all matrices into a single set
96 1 : GrB_Matrix *Set = NULL ;
97 1 : OK (LAGraph_Malloc ((void **) &Set, NFILES, sizeof (GrB_Matrix), msg)) ;
98 :
99 52 : for (int k = 0 ; k < NFILES ; k++)
100 : {
101 : // load the matrix as Set [k]
102 51 : const char *aname = files [k] ;
103 51 : if (strlen (aname) == 0) break;
104 51 : TEST_CASE (aname) ;
105 51 : snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
106 51 : FILE *f = fopen (filename, "r") ;
107 51 : TEST_CHECK (f != NULL) ;
108 51 : OK (LAGraph_MMRead (&(Set [k]), f, msg)) ;
109 51 : fclose (f) ;
110 : }
111 :
112 : // save the set of matrices in a single file
113 1 : OK (LAGraph_SSaveSet ("matrices.lagraph", Set, NFILES, "many test matrices",
114 : msg)) ;
115 :
116 : // load the matrices back in
117 1 : GrB_Matrix *Set2 = NULL ;
118 1 : GrB_Index nmatrices = 0 ;
119 1 : char *collection = NULL ;
120 : int r =
121 1 : LAGraph_SLoadSet ("matrices.lagraph", &Set2, &nmatrices, &collection,
122 : msg) ;
123 1 : printf ("nmatrices %g r %d msg %s\n", (double) nmatrices, r, msg) ;
124 1 : TEST_CHECK (nmatrices == NFILES) ;
125 1 : TEST_CHECK (Set2 != NULL) ;
126 1 : TEST_CHECK (collection != NULL) ;
127 1 : if (collection != NULL)
128 : {
129 1 : TEST_CHECK (strcmp (collection, "many test matrices") == 0) ;
130 : }
131 :
132 : // check the matrices
133 52 : for (int k = 0 ; k < NFILES ; k++)
134 : {
135 : // ensure the matrices Set [k] and Set2 [k] are the same
136 : bool ok ;
137 51 : OK (LAGraph_Matrix_IsEqual (&ok, Set [k], Set2 [k], msg)) ;
138 51 : TEST_CHECK (ok) ;
139 : }
140 :
141 : // free all matrices
142 1 : LAGraph_SFreeSet (&Set, NFILES) ;
143 1 : LAGraph_SFreeSet (&Set2, NFILES) ;
144 1 : LAGraph_Free ((void **) &collection, NULL) ;
145 :
146 1 : LAGraph_Finalize (msg) ;
147 : #endif
148 1 : }
149 :
150 : //****************************************************************************
151 :
152 : TEST_LIST = {
153 : {"SSaveSet", test_SSaveSet},
154 : {NULL, NULL}
155 : };
|