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 64 : 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 64 : LG_CLEAR_MSG_AND_BASIC_ASSERT (G, msg) ; 38 : 39 64 : if (G->emax != NULL) 40 : { 41 : // G->emax already computed 42 2 : return (GrB_SUCCESS) ; 43 : } 44 : 45 62 : G->emax_state = LAGRAPH_UNKNOWN ; 46 : 47 : //-------------------------------------------------------------------------- 48 : // determine the type of G->A and the corresponding max monoid 49 : //-------------------------------------------------------------------------- 50 : 51 62 : GrB_Type atype = NULL ; 52 : char atype_name [LAGRAPH_MAX_NAME_LEN] ; 53 62 : atype_name [0] = '\0' ; 54 62 : LAGraph_Matrix_TypeName (atype_name, G->A, msg) ; 55 62 : LAGraph_TypeFromName (&atype, atype_name, msg) ; 56 : GrB_Monoid monoid ; 57 62 : if (atype == GrB_BOOL ) monoid = GrB_LOR_MONOID_BOOL ; 58 45 : else if (atype == GrB_INT8 ) monoid = GrB_MAX_MONOID_INT8 ; 59 43 : else if (atype == GrB_INT16 ) monoid = GrB_MAX_MONOID_INT16 ; 60 41 : else if (atype == GrB_INT32 ) monoid = GrB_MAX_MONOID_INT32 ; 61 36 : else if (atype == GrB_INT64 ) monoid = GrB_MAX_MONOID_INT64 ; 62 28 : else if (atype == GrB_UINT8 ) monoid = GrB_MAX_MONOID_UINT8 ; 63 27 : else if (atype == GrB_UINT16) monoid = GrB_MAX_MONOID_UINT16 ; 64 26 : else if (atype == GrB_UINT32) monoid = GrB_MAX_MONOID_UINT32 ; 65 25 : else if (atype == GrB_UINT64) monoid = GrB_MAX_MONOID_UINT64 ; 66 24 : else if (atype == GrB_FP32 ) monoid = GrB_MAX_MONOID_FP32 ; 67 22 : else if (atype == GrB_FP64 ) monoid = GrB_MAX_MONOID_FP64 ; 68 : else 69 : { 70 1 : LG_ASSERT_MSG (false, GrB_NOT_IMPLEMENTED, "type not supported") ; 71 : } 72 : 73 : //-------------------------------------------------------------------------- 74 : // compute G->emax 75 : //-------------------------------------------------------------------------- 76 : 77 61 : GRB_TRY (GrB_Scalar_new (&(G->emax), atype)) ; 78 61 : GRB_TRY (GrB_reduce (G->emax, NULL, monoid, G->A, NULL)) ; 79 61 : G->emax_state = LAGraph_VALUE ; 80 61 : return (GrB_SUCCESS) ; 81 : }