Line data Source code
1 : //------------------------------------------------------------------------------
2 : // LAGraph_*TypeName: return the name of type of a matrix, vector, or scalar
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 : // On input, "char *name" is a pointer to a pre-allocated array of size at
19 : // least LAGRAPH_MAX_NAME_LEN. On output, the array is filled with a string
20 : // corresponding to the type of a GrB_Matrix, GrB_Vector, or GrB_Scalar.
21 : // For built-in types, the strings are defined as:
22 :
23 : // "bool" GrB_BOOL
24 : // "int8_t" GrB_INT8
25 : // "int16_t" GrB_INT16
26 : // "int32_t" GrB_INT32
27 : // "int64_t" GrB_INT64
28 : // "uint8_t" GrB_UINT8
29 : // "uint16_t" GrB_UINT16
30 : // "uint32_t" GrB_UINT32
31 : // "uint64_t" GrB_UINT64
32 : // "float" GrB_FP32
33 : // "double" GrB_FP64
34 :
35 : // For user-defined types, the GrB_NAME of the type is returned.
36 :
37 : #define LG_FREE_WORK LAGraph_Free ((void **) &t, NULL) ;
38 : #define LG_FREE_ALL LG_FREE_WORK
39 :
40 : #include "LG_internal.h"
41 :
42 : #define TYPENAME(object) \
43 : char *t = NULL ; \
44 : LG_CLEAR_MSG ; \
45 : LG_ASSERT (name != NULL, GrB_NULL_POINTER) ; \
46 : size_t len ; \
47 : name [0] = '\0' ; \
48 : int32_t typecode ; \
49 : GRB_TRY (GrB_get (object, &typecode, GrB_EL_TYPE_CODE)) ; \
50 : switch (typecode) \
51 : { \
52 : /* for user-defined types, return the GrB_EL_TYPE_STRING */ \
53 : default : \
54 : case GrB_UDT_CODE : \
55 : GRB_TRY (GrB_get (object, &len, GrB_EL_TYPE_STRING)) ; \
56 : LG_TRY (LAGraph_Malloc ((void **) &t, len+1, sizeof (char), msg)) ;\
57 : GRB_TRY (GrB_get (object, t, GrB_EL_TYPE_STRING)) ; \
58 : len = LAGRAPH_MIN (len, LAGRAPH_MAX_NAME_LEN) ; \
59 : strncpy (name, t, len) ; \
60 : name [LAGRAPH_MAX_NAME_LEN-1] = '\0' ; \
61 : LG_FREE_WORK ; \
62 : break ; \
63 : /* for built-in types, return the C type name */ \
64 : case GrB_BOOL_CODE : strcpy (name, "bool" ) ; break ; \
65 : case GrB_INT8_CODE : strcpy (name, "int8_t" ) ; break ; \
66 : case GrB_INT16_CODE : strcpy (name, "int16_t" ) ; break ; \
67 : case GrB_INT32_CODE : strcpy (name, "int32_t" ) ; break ; \
68 : case GrB_INT64_CODE : strcpy (name, "int64_t" ) ; break ; \
69 : case GrB_UINT8_CODE : strcpy (name, "uint8_t" ) ; break ; \
70 : case GrB_UINT16_CODE : strcpy (name, "uint16_t") ; break ; \
71 : case GrB_UINT32_CODE : strcpy (name, "uint32_t") ; break ; \
72 : case GrB_UINT64_CODE : strcpy (name, "uint64_t") ; break ; \
73 : case GrB_FP32_CODE : strcpy (name, "float" ) ; break ; \
74 : case GrB_FP64_CODE : strcpy (name, "double" ) ; break ; \
75 : /* case GxB_FC32_CODE : strcpy (name, "float complex" ) ; break ; */ \
76 : /* case GxB_FC64_CODE : strcpy (name, "double complex" ) ; break ; */ \
77 : } \
78 : return (GrB_SUCCESS) ;
79 :
80 : //------------------------------------------------------------------------------
81 : // LAGraph_Matrix_TypeName: return the name of the GrB_Type of a GrB_Matrix
82 : //------------------------------------------------------------------------------
83 :
84 31255 : int LAGraph_Matrix_TypeName
85 : (
86 : // output:
87 : char *name, // name of the type of the matrix A (user-provided array
88 : // of size at least LAGRAPH_MAX_NAME_LEN).
89 : // input:
90 : GrB_Matrix A, // matrix to query
91 : char *msg
92 : )
93 : {
94 31255 : TYPENAME (A) ;
95 : }
96 :
97 : //------------------------------------------------------------------------------
98 : // LAGraph_Vector_TypeName: return the name of the GrB_Type of a GrB_Vector
99 : //------------------------------------------------------------------------------
100 :
101 28821 : int LAGraph_Vector_TypeName
102 : (
103 : // output:
104 : char *name, // name of the type of the vector v (user-provided array
105 : // of size at least LAGRAPH_MAX_NAME_LEN).
106 : // input:
107 : GrB_Vector v, // vector to query
108 : char *msg
109 : )
110 : {
111 28821 : TYPENAME (v) ;
112 : }
113 :
114 : //------------------------------------------------------------------------------
115 : // LAGraph_Scalar_TypeName: return the name of the GrB_Type of a GrB_Scalar
116 : //------------------------------------------------------------------------------
117 :
118 3 : int LAGraph_Scalar_TypeName
119 : (
120 : // output:
121 : char *name, // name of the type of the scalar s (user-provided array
122 : // of size at least LAGRAPH_MAX_NAME_LEN).
123 : // input:
124 : GrB_Scalar s, // scalar to query
125 : char *msg
126 : )
127 : {
128 3 : TYPENAME (s) ;
129 : }
130 :
|