1 //------------------------------------------------------------------------------
2 // GB_mx_Type: get GraphBLAS type of a MATLAB matrix
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 // Given a MATLAB matrix, return the equivalent GraphBLAS type.  For GxB_FC64,
11 // the Complex type is returned.  This may equal GxB_FC64, or it might be the
12 // user-defined type, as determined by Complex_init in
13 // GraphBLAS/Demo/Source/usercomplex.c.
14 
15 #include "GB_mex.h"
16 
GB_mx_Type(const mxArray * X)17 GrB_Type GB_mx_Type                    // returns a GraphBLAS type
18 (
19     const mxArray *X                   // MATLAB matrix to query
20 )
21 {
22 
23     GrB_Type xtype ;
24 
25     if (X == NULL)
26     {
27         return (NULL) ;
28     }
29 
30     if (mxIsComplex (X))
31     {
32         switch (mxGetClassID (X))
33         {
34             // only single complex and double complex are supported
35             case mxSINGLE_CLASS   : return (GxB_FC32  ) ;
36             case mxDOUBLE_CLASS   : return (Complex   ) ;
37             default               : return (NULL      ) ;
38         }
39     }
40     else
41     {
42         switch (mxGetClassID (X))
43         {
44             // all GraphBLAS built-in types are supported
45             case mxLOGICAL_CLASS  : return (GrB_BOOL  ) ;
46             case mxINT8_CLASS     : return (GrB_INT8  ) ;
47             case mxINT16_CLASS    : return (GrB_INT16 ) ;
48             case mxINT32_CLASS    : return (GrB_INT32 ) ;
49             case mxINT64_CLASS    : return (GrB_INT64 ) ;
50             case mxUINT8_CLASS    : return (GrB_UINT8 ) ;
51             case mxUINT16_CLASS   : return (GrB_UINT16) ;
52             case mxUINT32_CLASS   : return (GrB_UINT32) ;
53             case mxUINT64_CLASS   : return (GrB_UINT64) ;
54             case mxSINGLE_CLASS   : return (GrB_FP32  ) ;
55             case mxDOUBLE_CLASS   : return (GrB_FP64  ) ;
56             default               : return (NULL      ) ;
57         }
58     }
59 }
60 
61