LCOV - code coverage report
Current view: top level - experimental/test - test_SSaveSet.c (source / functions) Hit Total Coverage
Test: LAGraph code coverage report. Commit id: cc56ed4. Current time (UTC): 2024-08-30T17:14:30Z Lines: 34 34 100.0 %
Date: 2024-08-30 17:16:41 Functions: 1 1 100.0 %

          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           1 :     LAGraph_Init (msg) ;
      93           1 :     GrB_Descriptor desc = NULL ;
      94             :     #if LAGRAPH_SUITESPARSE
      95           1 :     OK (GrB_Descriptor_new (&desc)) ;
      96           1 :     OK (GxB_set (desc, GxB_COMPRESSION, GxB_COMPRESSION_LZ4HC + 9)) ;
      97             :     #endif
      98             : 
      99             :     // load all matrices into a single set
     100           1 :     GrB_Matrix *Set = NULL ;
     101           1 :     OK (LAGraph_Malloc ((void **) &Set, NFILES, sizeof (GrB_Matrix), msg)) ;
     102             : 
     103          52 :     for (int k = 0 ; k < NFILES ; k++)
     104             :     {
     105             :         // load the matrix as Set [k]
     106          51 :         const char *aname = files [k] ;
     107          51 :         if (strlen (aname) == 0) break;
     108          51 :         TEST_CASE (aname) ;
     109          51 :         snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
     110          51 :         FILE *f = fopen (filename, "r") ;
     111          51 :         TEST_CHECK (f != NULL) ;
     112          51 :         OK (LAGraph_MMRead (&(Set [k]), f, msg)) ;
     113          51 :         fclose (f) ;
     114             :     }
     115             : 
     116             :     // workaround for bug in v6.0.0 to v6.0.2:
     117             :     // ensure the matrix is not iso
     118             :     #if LAGRAPH_SUITESPARSE
     119             :     #if GxB_IMPLEMENTATION < GxB_VERSION (6,0,3)
     120             :     printf ("\nworkaround for bug in SS:GrB v6.0.2 (fixed in v6.0.3)\n") ;
     121             :     for (int k = 0 ; k < NFILES ; k++)
     122             :     {
     123             :         OK (GrB_Matrix_setElement (Set [k], 0, 0, 0)) ;
     124             :         OK (GrB_wait (Set [k], GrB_MATERIALIZE)) ;
     125             :     }
     126             :     #endif
     127             :     #endif
     128             : 
     129             :     // save the set of matrices in a single file
     130           1 :     OK (LAGraph_SSaveSet ("matrices.lagraph", Set, NFILES, "many test matrices",
     131             :         msg)) ;
     132             : 
     133             :     // load the matrices back in
     134           1 :     GrB_Matrix *Set2 = NULL ;
     135           1 :     GrB_Index nmatrices = 0 ;
     136           1 :     char *collection = NULL ;
     137             :     int r =
     138           1 :         LAGraph_SLoadSet ("matrices.lagraph", &Set2, &nmatrices, &collection,
     139             :         msg) ;
     140           1 :     printf ("nmatrices %g r %d msg %s\n", (double) nmatrices, r, msg) ;
     141           1 :     TEST_CHECK (nmatrices == NFILES) ;
     142           1 :     TEST_CHECK (Set2 != NULL) ;
     143           1 :     TEST_CHECK (strcmp (collection, "many test matrices") == 0) ;
     144             : 
     145             :     // check the matrices
     146          52 :     for (int k = 0 ; k < NFILES ; k++)
     147             :     {
     148             :         // ensure the matrices Set [k] and Set2 [k] are the same
     149             :         bool ok ;
     150          51 :         OK (LAGraph_Matrix_IsEqual (&ok, Set [k], Set2 [k], msg)) ;
     151          51 :         TEST_CHECK (ok) ;
     152             :     }
     153             : 
     154             :     // free all matrices
     155           1 :     LAGraph_SFreeSet (&Set, NFILES) ;
     156           1 :     LAGraph_SFreeSet (&Set2, NFILES) ;
     157           1 :     LAGraph_Free ((void **) &collection, NULL) ;
     158             : 
     159           1 :     OK (GrB_free (&desc)) ;
     160           1 :     LAGraph_Finalize (msg) ;
     161           1 : }
     162             : 
     163             : //****************************************************************************
     164             : 
     165             : TEST_LIST = {
     166             :     {"SSaveSet", test_SSaveSet},
     167             :     {NULL, NULL}
     168             : };

Generated by: LCOV version 1.14