Line data Source code
1 : //------------------------------------------------------------------------------ 2 : // LAGraph_TypeFromName: return the GrB_Type corresponding to its given name 3 : //------------------------------------------------------------------------------ 4 : 5 : // LAGraph, (c) 2019-2023 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 : // This method works for any GraphBLAS library. On input, name is a char array 19 : // of length at least LAGRAPH_MAX_NAME_LEN. 20 : 21 : // Only built-in types are supported. User-defined types are not supported. 22 : 23 : #include "LG_internal.h" 24 : 25 14463 : int LAGraph_TypeFromName 26 : ( 27 : // output: 28 : GrB_Type *type, // GraphBLAS type 29 : // input: 30 : char *name, // name of the type: a null-terminated string 31 : char *msg 32 : ) 33 : { 34 : 35 : //-------------------------------------------------------------------------- 36 : // check inputs 37 : //-------------------------------------------------------------------------- 38 : 39 14463 : LG_CLEAR_MSG ; 40 14463 : LG_ASSERT (type != NULL, GrB_NULL_POINTER) ; 41 14463 : LG_ASSERT (name != NULL, GrB_NULL_POINTER) ; 42 : 43 : //-------------------------------------------------------------------------- 44 : // determine the GrB_Type from its name 45 : //-------------------------------------------------------------------------- 46 : 47 : #define MATCH2(s1,s2) MATCHNAME (name, s1) || MATCHNAME (name, s2) 48 : 49 14463 : if (MATCH2 ("bool" , "GrB_BOOL" )) (*type) = GrB_BOOL ; 50 12109 : else if (MATCH2 ("int8_t" , "GrB_INT8" )) (*type) = GrB_INT8 ; 51 11766 : else if (MATCH2 ("int16_t" , "GrB_INT16" )) (*type) = GrB_INT16 ; 52 11419 : else if (MATCH2 ("int32_t" , "GrB_INT32" )) (*type) = GrB_INT32 ; 53 6166 : else if (MATCH2 ("int64_t" , "GrB_INT64" )) (*type) = GrB_INT64 ; 54 4654 : else if (MATCH2 ("uint8_t" , "GrB_UINT8" )) (*type) = GrB_UINT8 ; 55 4494 : else if (MATCH2 ("uint16_t", "GrB_UINT16" )) (*type) = GrB_UINT16 ; 56 4334 : else if (MATCH2 ("uint32_t", "GrB_UINT32" )) (*type) = GrB_UINT32 ; 57 3961 : else if (MATCH2 ("uint64_t", "GrB_UINT64" )) (*type) = GrB_UINT64 ; 58 3388 : else if (MATCH2 ("float" , "GrB_FP32" )) (*type) = GrB_FP32 ; 59 3000 : else if (MATCH2 ("double" , "GrB_FP64" )) (*type) = GrB_FP64 ; 60 : // if complex types from SuiteSparse:GraphBLAS are added to LAGraph: 61 : // else if (MATCH2 ("float complex", "GxB_FC32") || 62 : // MATCHNAME (name, "float _Complex" )) (*type) = GxB_FC32 ; 63 : // else if (MATCH2 ("double complex", "GxB_FC64") || 64 : // MATCHNAME (name, "double _Complex")) (*type) = GxB_FC64 ; 65 : else 66 : { 67 3 : (*type) = NULL ; 68 3 : LG_ASSERT_MSGF (false, GrB_NOT_IMPLEMENTED, 69 : "type \"%s\" not supported", name) ; 70 : } 71 14460 : return (GrB_SUCCESS) ; 72 : } 73 :