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