LCOV - code coverage report
Current view: top level - src/test - test_Cached_SymmetricStructure.c (source / functions) Hit Total Coverage
Test: LAGraph code coverage report. Commit id: 3b461aa. Current time (UTC): 2024-01-25T16:04:32Z Lines: 79 79 100.0 %
Date: 2024-01-25 16:05:28 Functions: 4 4 100.0 %

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

Generated by: LCOV version 1.14