1 //------------------------------------------------------------------------------
2 // gb_mxstring_to_binop: get a GraphBLAS operator from a MATLAB string
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: GPL-3.0-or-later
7 
8 //------------------------------------------------------------------------------
9 
10 #include "gb_matlab.h"
11 
gb_mxstring_to_binop(const mxArray * mxstring,const GrB_Type atype,const GrB_Type btype)12 GrB_BinaryOp gb_mxstring_to_binop       // return binary operator from a string
13 (
14     const mxArray *mxstring,            // MATLAB string
15     const GrB_Type atype,               // type of A
16     const GrB_Type btype                // type of B
17 )
18 {
19 
20     //--------------------------------------------------------------------------
21     // check inputs
22     //--------------------------------------------------------------------------
23 
24     if (gb_mxarray_is_empty (mxstring))
25     {
26         // no operator is present, or present and empty; this is not yet an
27         // error, since many uses of GraphBLAS functions use an optional accum
28         // operator.
29         return (NULL) ;
30     }
31 
32     //--------------------------------------------------------------------------
33     // get the string
34     //--------------------------------------------------------------------------
35 
36     #define LEN 256
37     char opstring [LEN+2] ;
38     gb_mxstring_to_string (opstring, LEN, mxstring, "binary operator") ;
39 
40     //--------------------------------------------------------------------------
41     // convert the string to a binary operator
42     //--------------------------------------------------------------------------
43 
44     return (gb_string_to_binop (opstring, atype, btype)) ;
45 }
46 
47