1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
//------------------------------------------------------------------------------
// gbtype: type of a GraphBLAS matrix struct, or any built-in variable
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// The input may be any built-in variable. If it is a GraphBLAS G.opaque
// struct, then its internal type is returned.
// Usage
// type = gbtype (X)
#include "gb_interface.h"
#define USAGE "usage: type = gbtype (X)"
void mexFunction
(
int nargout,
mxArray *pargout [ ],
int nargin,
const mxArray *pargin [ ]
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
gb_usage (nargin == 1 && nargout <= 1, USAGE) ;
//--------------------------------------------------------------------------
// get the type of the matrix
//--------------------------------------------------------------------------
mxArray *c = NULL ;
mxClassID class = mxGetClassID (pargin [0]) ;
bool is_complex = mxIsComplex (pargin [0]) ;
if (class == mxSTRUCT_CLASS)
{
// get the content of a GraphBLASv7_3 struct
mxArray *mx_type = mxGetField (pargin [0], 0, "GraphBLASv7_3") ;
if (mx_type == NULL)
{
// check if it is a GraphBLASv5_1 struct
mx_type = mxGetField (pargin [0], 0, "GraphBLASv5_1") ;
}
if (mx_type == NULL)
{
// check if it is a GraphBLASv5 struct
mx_type = mxGetField (pargin [0], 0, "GraphBLASv5") ;
}
if (mx_type == NULL)
{
// check if it is a GraphBLASv4 struct
mx_type = mxGetField (pargin [0], 0, "GraphBLASv4") ;
}
if (mx_type == NULL)
{
// check if it is a GraphBLASv3 struct
mx_type = mxGetField (pargin [0], 0, "GraphBLAS") ;
}
if (mx_type != NULL)
{
// the mxArray is a struct containing a GraphBLAS GrB_matrix;
// get its type
c = mxDuplicateArray (mx_type) ;
}
}
if (c == NULL)
{
// if c is still NULL, then it is not a GraphBLAS opaque struct.
// get the type of a built-in matrix
c = gb_mxclass_to_mxstring (class, is_complex) ;
}
//--------------------------------------------------------------------------
// return the result
//--------------------------------------------------------------------------
pargout [0] = c ;
GB_WRAPUP ;
}
|