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

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph_Cached_OutDegree: determine G->out_degree
       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             : // LAGraph_Cached_OutDegree computes G->out_degree, where G->out_degree(i) is
      19             : // the number of entries in G->A (i,:).  If there are no entries in G->A (i,:),
      20             : // G->rowdgree(i) is not present in the structure of G->out_degree.  That is,
      21             : // G->out_degree contains no explicit zero entries.
      22             : 
      23             : #define LG_FREE_WORK            \
      24             : {                               \
      25             :     GrB_free (&x) ;             \
      26             : }
      27             : 
      28             : #define LG_FREE_ALL             \
      29             : {                               \
      30             :     LG_FREE_WORK ;              \
      31             :     GrB_free (&out_degree) ;    \
      32             : }
      33             : 
      34             : #include "LG_internal.h"
      35             : 
      36        1583 : int LAGraph_Cached_OutDegree
      37             : (
      38             :     // input/output:
      39             :     LAGraph_Graph G,    // graph to determine G->out_degree
      40             :     char *msg
      41             : )
      42             : {
      43             : 
      44             :     //--------------------------------------------------------------------------
      45             :     // clear msg and check G
      46             :     //--------------------------------------------------------------------------
      47             : 
      48        1583 :     GrB_Vector out_degree = NULL, x = NULL ;
      49        1583 :     LG_CLEAR_MSG_AND_BASIC_ASSERT (G, msg) ;
      50             : 
      51        1582 :     if (G->out_degree != NULL)
      52             :     {
      53             :         // G->out_degree already computed
      54         538 :         return (GrB_SUCCESS) ;
      55             :     }
      56             : 
      57             :     //--------------------------------------------------------------------------
      58             :     // determine the size of A
      59             :     //--------------------------------------------------------------------------
      60             : 
      61        1044 :     GrB_Matrix A = G->A ;
      62             :     GrB_Index nrows, ncols ;
      63        1044 :     GRB_TRY (GrB_Matrix_nrows (&nrows, A)) ;
      64        1044 :     GRB_TRY (GrB_Matrix_ncols (&ncols, A)) ;
      65             : 
      66             :     //--------------------------------------------------------------------------
      67             :     // compute the out_degree
      68             :     //--------------------------------------------------------------------------
      69             : 
      70        1044 :     GRB_TRY (GrB_Vector_new (&out_degree, GrB_INT64, nrows)) ;
      71             :     // x = zeros (ncols,1)
      72         910 :     GRB_TRY (GrB_Vector_new (&x, GrB_INT64, ncols)) ;
      73         776 :     GRB_TRY (GrB_assign (x, NULL, NULL, 0, GrB_ALL, ncols, NULL)) ;
      74             : 
      75         709 :     GRB_TRY (GrB_mxv (out_degree, NULL, NULL, LAGraph_plus_one_int64,
      76             :         A, x, NULL)) ;
      77             : 
      78         590 :     G->out_degree = out_degree ;
      79             : 
      80         590 :     LG_FREE_WORK ;
      81         590 :     return (GrB_SUCCESS) ;
      82             : }

Generated by: LCOV version 1.14