1 //------------------------------------------------------------------------------
2 // GB_mx_string_to_Type.c: return the GrB_type from a string
3 //------------------------------------------------------------------------------
4
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7
8 //------------------------------------------------------------------------------
9
10 // Also returns the GrB_Type from the string.
11
12 #include "GB_mex.h"
13
GB_mx_string_to_Type(const mxArray * type_mx,const GrB_Type default_type)14 GrB_Type GB_mx_string_to_Type // GrB_Type from the string
15 (
16 const mxArray *type_mx, // string with type name
17 const GrB_Type default_type // default type if string empty
18 )
19 {
20
21 // get the string
22 #define LEN 256
23 char type [LEN+2] ;
24 int len = GB_mx_mxArray_to_string (type, LEN, type_mx) ;
25
26 if (len < 0) return (NULL) ;
27 if (len == 0) return (default_type) ;
28 if (MATCH (type, "logical")) return (GrB_BOOL) ;
29 if (MATCH (type, "bool" )) return (GrB_BOOL) ;
30 if (MATCH (type, "int8" )) return (GrB_INT8) ;
31 if (MATCH (type, "int16" )) return (GrB_INT16) ;
32 if (MATCH (type, "int32" )) return (GrB_INT32) ;
33 if (MATCH (type, "int64" )) return (GrB_INT64) ;
34 if (MATCH (type, "uint8" )) return (GrB_UINT8) ;
35 if (MATCH (type, "uint16" )) return (GrB_UINT16) ;
36 if (MATCH (type, "uint32" )) return (GrB_UINT32) ;
37 if (MATCH (type, "uint64" )) return (GrB_UINT64) ;
38 if (MATCH (type, "single" )) return (GrB_FP32) ;
39 if (MATCH (type, "double" )) return (GrB_FP64) ;
40 if (MATCH (type, "single complex" )) return (GxB_FC32) ;
41 if (MATCH (type, "double complex" )) return (Complex) ;
42 if (MATCH (type, "GxB_FC32_t" )) return (GxB_FC32) ;
43 if (MATCH (type, "GxB_FC64_t" )) return (GxB_FC64) ;
44
45 return (NULL) ;
46 }
47
48