1 //------------------------------------------------------------------------------
2 // GB_BinaryOp_check: check and print a binary operator
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 #include "GB.h"
11
12 GB_PUBLIC // accessed by the MATLAB tests in GraphBLAS/Test only
GB_BinaryOp_check(const GrB_BinaryOp op,const char * name,int pr,FILE * f)13 GrB_Info GB_BinaryOp_check // check a GraphBLAS binary operator
14 (
15 const GrB_BinaryOp op, // GraphBLAS operator to print and check
16 const char *name, // name of the operator
17 int pr, // print level
18 FILE *f // file for output
19 )
20 {
21
22 //--------------------------------------------------------------------------
23 // check inputs
24 //--------------------------------------------------------------------------
25
26 GBPR0 ("\n GraphBLAS BinaryOp: %s ", ((name != NULL) ? name : "")) ;
27
28 if (op == NULL)
29 {
30 // this may be an optional argument
31 GBPR0 ("NULL\n") ;
32 return (GrB_NULL_POINTER) ;
33 }
34
35 //--------------------------------------------------------------------------
36 // check object
37 //--------------------------------------------------------------------------
38
39 GB_CHECK_MAGIC (op, "BinaryOp") ;
40
41 GB_Opcode opcode = op->opcode ;
42 if (opcode >= GB_USER_opcode)
43 {
44 GBPR0 ("(user-defined) ") ;
45 }
46 else
47 {
48 GBPR0 ("(built-in) ") ;
49 }
50
51 GBPR0 ("z=%s(x,y)\n", op->name) ;
52
53 bool op_is_positional = GB_OPCODE_IS_POSITIONAL (opcode) ;
54 bool op_is_first = (opcode == GB_FIRST_opcode) ;
55 bool op_is_second = (opcode == GB_SECOND_opcode) ;
56 bool op_is_pair = (opcode == GB_PAIR_opcode) ;
57
58 if (!(op_is_positional || op_is_first || op_is_second)
59 && op->function == NULL)
60 {
61 GBPR0 (" BinaryOp has a NULL function pointer\n") ;
62 return (GrB_INVALID_OBJECT) ;
63 }
64
65 if (opcode < GB_FIRST_opcode || opcode > GB_USER_opcode)
66 {
67 GBPR0 (" BinaryOp has an invalid opcode\n") ;
68 return (GrB_INVALID_OBJECT) ;
69 }
70
71 GrB_Info info ;
72
73 info = GB_Type_check (op->ztype, "ztype", pr, f) ;
74 if (info != GrB_SUCCESS)
75 {
76 GBPR0 (" BinaryOp has an invalid ztype\n") ;
77 return (GrB_INVALID_OBJECT) ;
78 }
79
80 if (!op_is_positional && !op_is_pair)
81 {
82 if (!op_is_second)
83 {
84 info = GB_Type_check (op->xtype, "xtype", pr, f) ;
85 if (info != GrB_SUCCESS)
86 {
87 GBPR0 (" BinaryOp has an invalid xtype\n") ;
88 return (GrB_INVALID_OBJECT) ;
89 }
90 }
91
92 if (!op_is_first)
93 {
94 info = GB_Type_check (op->ytype, "ytype", pr, f) ;
95 if (info != GrB_SUCCESS)
96 {
97 GBPR0 (" BinaryOp has an invalid ytype\n") ;
98 return (GrB_INVALID_OBJECT) ;
99 }
100 }
101 }
102
103 return (GrB_SUCCESS) ;
104 }
105
106