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

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph_Graph_Print: print the contents of a graph
       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 "LG_internal.h"
      19             : 
      20         350 : int LAGraph_Graph_Print
      21             : (
      22             :     // input:
      23             :     const LAGraph_Graph G,  // graph to display
      24             :     LAGraph_PrintLevel pr,  // print level (0 to 5)
      25             :     FILE *f,                // file to write to, must already be open
      26             :     char *msg
      27             : )
      28             : {
      29             : 
      30             :     //--------------------------------------------------------------------------
      31             :     // clear the msg and check the graph
      32             :     //--------------------------------------------------------------------------
      33             : 
      34         350 :     LG_CLEAR_MSG ;
      35         350 :     LG_ASSERT (f != NULL, GrB_NULL_POINTER) ;
      36         350 :     LG_TRY (LAGraph_CheckGraph (G, msg)) ;
      37         345 :     int prl = (int) pr ;
      38         345 :     prl = LAGRAPH_MAX (prl, 0) ;
      39         345 :     prl = LAGRAPH_MIN (prl, 5) ;
      40         345 :     if (prl == 0) return (GrB_SUCCESS) ;
      41             : 
      42             :     //--------------------------------------------------------------------------
      43             :     // display the primary graph components
      44             :     //--------------------------------------------------------------------------
      45             : 
      46         329 :     GrB_Matrix A = G->A ;
      47         329 :     LAGraph_Kind kind = G->kind ;
      48             : 
      49             :     GrB_Index n, nvals ;
      50         329 :     GRB_TRY (GrB_Matrix_nrows (&n, A)) ;
      51         329 :     GRB_TRY (GrB_Matrix_nvals (&nvals, A)) ;
      52             :     char typename [LAGRAPH_MAX_NAME_LEN] ;
      53             :     char kindname [LAGRAPH_MAX_NAME_LEN] ;
      54         329 :     LG_TRY (LAGraph_Matrix_TypeName (typename, A, msg)) ;
      55         329 :     LG_TRY (LG_KindName (kindname, kind, msg)) ;
      56             : 
      57             :     // print the basic cached scalar properties
      58         329 :     FPRINTF (f, "Graph: kind: %s, nodes: %g entries: %g type: %s\n",
      59             :         kindname, (double)n, (double)nvals, typename) ;
      60             : 
      61             :     // print the scalar cached properties
      62         329 :     FPRINTF (f, "  structural symmetry: ") ;
      63         329 :     switch (G->is_symmetric_structure)
      64             :     {
      65         128 :         case LAGraph_FALSE : FPRINTF (f, "unsymmetric") ; break ;
      66         154 :         case LAGraph_TRUE  : FPRINTF (f, "symmetric")   ; break ;
      67          47 :         default            : FPRINTF (f, "unknown")     ; break ;
      68             :     }
      69         329 :     if (G->nself_edges >= 0)
      70             :     {
      71          84 :         FPRINTF (f, "  self-edges: %g", (double) G->nself_edges) ;
      72             :     }
      73         329 :     FPRINTF (f, "\n") ;
      74             : 
      75         329 :     FPRINTF (f, "  adjacency matrix: ") ;
      76             : 
      77         329 :     LAGraph_PrintLevel pr2 = (LAGraph_PrintLevel) prl ;
      78         329 :     LG_TRY (LAGraph_Matrix_Print (A, pr2, stdout, msg)) ;
      79             : 
      80             :     //--------------------------------------------------------------------------
      81             :     // display the cached properties
      82             :     //--------------------------------------------------------------------------
      83             : 
      84         269 :     GrB_Matrix AT = G->AT ;
      85         269 :     if (AT != NULL)
      86             :     {
      87         172 :         FPRINTF (f, "  adjacency matrix transposed: ") ;
      88         172 :         LG_TRY (LAGraph_Matrix_Print (AT, pr2, stdout, msg)) ;
      89             :     }
      90             : 
      91         247 :     GrB_Vector out_degree = G->out_degree ;
      92         247 :     if (out_degree != NULL)
      93             :     {
      94         181 :         FPRINTF (f, "  out degree: ") ;
      95         181 :         LG_TRY (LAGraph_Vector_Print (out_degree, pr2, stdout, msg)) ;
      96             :     }
      97             : 
      98         247 :     GrB_Vector in_degree = G->in_degree ;
      99         247 :     if (in_degree != NULL)
     100             :     {
     101         125 :         FPRINTF (f, "  in degree: ") ;
     102         125 :         LG_TRY (LAGraph_Vector_Print (in_degree, pr2, stdout, msg)) ;
     103             :     }
     104             : 
     105         247 :     return (GrB_SUCCESS) ;
     106             : }

Generated by: LCOV version 1.14