1 //------------------------------------------------------------------------------
2 // GB_SelectOp_check: check and print a select 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_SelectOp_check(const GxB_SelectOp op,const char * name,int pr,FILE * f)13 GrB_Info GB_SelectOp_check  // check a GraphBLAS select operator
14 (
15     const GxB_SelectOp 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 SelectOp: %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, "SelectOp") ;
39 
40     if (op->opcode >= GB_USER_SELECT_opcode)
41     {
42         GBPR0 ("(user-defined) ") ;
43     }
44     else
45     {
46         GBPR0 ("(built-in) ") ;
47     }
48 
49     GBPR0 ("C=%s(A,k)\n", op->name) ;
50 
51     if (op->function == NULL && op->opcode >= GB_USER_SELECT_opcode)
52     {
53         GBPR0 ("    function pointer is NULL\n") ;
54         return (GrB_INVALID_OBJECT) ;
55     }
56 
57     if (op->opcode < GB_TRIL_opcode || op->opcode > GB_USER_SELECT_opcode)
58     {
59         GBPR0 ("    invalid opcode\n") ;
60         return (GrB_INVALID_OBJECT) ;
61     }
62 
63     if (op->xtype != NULL)
64     {
65         GrB_Info info = GB_Type_check (op->xtype, "xtype", pr, f) ;
66         if (info != GrB_SUCCESS)
67         {
68             GBPR0 ("    SelectOp has an invalid xtype\n") ;
69             return (GrB_INVALID_OBJECT) ;
70         }
71     }
72 
73     if (op->ttype != NULL)
74     {
75         GrB_Info info = GB_Type_check (op->ttype, "ttype", pr, f) ;
76         if (info != GrB_SUCCESS)
77         {
78             GBPR0 ("    SelectOp has an invalid ttype\n") ;
79             return (GrB_INVALID_OBJECT) ;
80         }
81     }
82 
83     return (GrB_SUCCESS) ;
84 }
85 
86