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

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph_Cached_EMax: determine G->emax
       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             : #define LG_FREE_ALL             \
      19             : {                               \
      20             :     GrB_free (&G->emax) ;       \
      21             : }
      22             : 
      23             : #include "LG_internal.h"
      24             : 
      25          67 : int LAGraph_Cached_EMax
      26             : (
      27             :     // input/output:
      28             :     LAGraph_Graph G,    // graph to determine G->emax
      29             :     char *msg
      30             : )
      31             : {
      32             : 
      33             :     //--------------------------------------------------------------------------
      34             :     // clear msg and check G
      35             :     //--------------------------------------------------------------------------
      36             : 
      37          67 :     LG_CLEAR_MSG_AND_BASIC_ASSERT (G, msg) ;
      38             : 
      39          67 :     if (G->emax != NULL)
      40             :     {
      41             :         // G->emax already computed
      42           2 :         return (GrB_SUCCESS) ;
      43             :     }
      44             : 
      45          65 :     G->emax_state = LAGRAPH_UNKNOWN ;
      46             : 
      47             :     //--------------------------------------------------------------------------
      48             :     // determine the type of G->A and the corresponding max monoid
      49             :     //--------------------------------------------------------------------------
      50             : 
      51             :     char atype_name [LAGRAPH_MAX_NAME_LEN] ;
      52          65 :     LG_TRY (LAGraph_Matrix_TypeName (atype_name, G->A, msg)) ;
      53             :     GrB_Type atype ;
      54          65 :     LG_TRY (LAGraph_TypeFromName (&atype, atype_name, msg)) ;
      55             :     GrB_Monoid monoid ;
      56          65 :     if      (atype == GrB_BOOL  ) monoid = GrB_LOR_MONOID_BOOL  ;
      57          48 :     else if (atype == GrB_INT8  ) monoid = GrB_MAX_MONOID_INT8   ;
      58          46 :     else if (atype == GrB_INT16 ) monoid = GrB_MAX_MONOID_INT16  ;
      59          44 :     else if (atype == GrB_INT32 ) monoid = GrB_MAX_MONOID_INT32  ;
      60          38 :     else if (atype == GrB_INT64 ) monoid = GrB_MAX_MONOID_INT64  ;
      61          30 :     else if (atype == GrB_UINT8 ) monoid = GrB_MAX_MONOID_UINT8  ;
      62          29 :     else if (atype == GrB_UINT16) monoid = GrB_MAX_MONOID_UINT16 ;
      63          28 :     else if (atype == GrB_UINT32) monoid = GrB_MAX_MONOID_UINT32 ;
      64          27 :     else if (atype == GrB_UINT64) monoid = GrB_MAX_MONOID_UINT64 ;
      65          26 :     else if (atype == GrB_FP32  ) monoid = GrB_MAX_MONOID_FP32   ;
      66          24 :     else if (atype == GrB_FP64  ) monoid = GrB_MAX_MONOID_FP64   ;
      67             :     else
      68             :     {
      69           1 :         LG_ASSERT_MSG (false, GrB_NOT_IMPLEMENTED, "type not supported") ;
      70             :     }
      71             : 
      72             :     //--------------------------------------------------------------------------
      73             :     // compute G->emax
      74             :     //--------------------------------------------------------------------------
      75             : 
      76          64 :     GRB_TRY (GrB_Scalar_new (&(G->emax), atype)) ;
      77          64 :     GRB_TRY (GrB_reduce (G->emax, NULL, monoid, G->A, NULL)) ;
      78          64 :     G->emax_state = LAGraph_VALUE ;
      79          64 :     return (GrB_SUCCESS) ;
      80             : }

Generated by: LCOV version 1.14