1 //------------------------------------------------------------------------------
2 // GB_UnaryOp_check: check and print a unary 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_UnaryOp_check(const GrB_UnaryOp op,const char * name,int pr,FILE * f)13 GrB_Info GB_UnaryOp_check // check a GraphBLAS unary operator
14 (
15 const GrB_UnaryOp 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 UnaryOp: %s ", ((name != NULL) ? name : "")) ;
27
28 if (op == NULL)
29 {
30 GBPR0 ("NULL\n") ;
31 return (GrB_NULL_POINTER) ;
32 }
33
34 //--------------------------------------------------------------------------
35 // check object
36 //--------------------------------------------------------------------------
37
38 GB_CHECK_MAGIC (op, "UnaryOp") ;
39
40 GB_Opcode opcode = op->opcode ;
41 if (opcode >= GB_USER_opcode)
42 {
43 GBPR0 ("(user-defined) ") ;
44 }
45 else
46 {
47 GBPR0 ("(built-in) ") ;
48 }
49
50 GBPR0 ("z=%s(x)\n", op->name) ;
51
52 bool op_is_positional = GB_OPCODE_IS_POSITIONAL (opcode) ;
53 bool op_is_one = (opcode == GB_ONE_opcode) ;
54
55 if (!op_is_positional && op->function == NULL)
56 {
57 GBPR0 (" function pointer is NULL\n") ;
58 return (GrB_INVALID_OBJECT) ;
59 }
60
61 if (opcode != GB_USER_opcode)
62 {
63 if (opcode < GB_ONE_opcode || opcode >= GB_FIRST_opcode)
64 {
65 GBPR0 (" invalid opcode\n") ;
66 return (GrB_INVALID_OBJECT) ;
67 }
68 }
69
70 GrB_Info info ;
71
72 info = GB_Type_check (op->ztype, "ztype", pr, f) ;
73 if (info != GrB_SUCCESS)
74 {
75 GBPR0 (" UnaryOP has an invalid ztype\n") ;
76 return (GrB_INVALID_OBJECT) ;
77 }
78
79 if (!op_is_positional && !op_is_one)
80 {
81 info = GB_Type_check (op->xtype, "xtype", pr, f) ;
82 if (info != GrB_SUCCESS)
83 {
84 GBPR0 (" UnaryOP has an invalid xtype\n") ;
85 return (GrB_INVALID_OBJECT) ;
86 }
87 }
88
89 return (GrB_SUCCESS) ;
90 }
91
92