1 //------------------------------------------------------------------------------
2 // GB_Mask_compatible: check input and operators for type compatibility
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 // check the type and dimensions of the mask
11 
12 #include "GB.h"
13 
GB_Mask_compatible(const GrB_Matrix M,const bool Mask_struct,const GrB_Matrix C,const GrB_Index nrows,const GrB_Index ncols,GB_Context Context)14 GrB_Info GB_Mask_compatible     // check type and dimensions of mask
15 (
16     const GrB_Matrix M,         // mask to check
17     const bool Mask_struct,     // true if M is structural
18     const GrB_Matrix C,         // C<M>= ...
19     const GrB_Index nrows,      // size of output if C is NULL (see GB*assign)
20     const GrB_Index ncols,
21     GB_Context Context
22 )
23 {
24 
25     //--------------------------------------------------------------------------
26     // check the mask M
27     //--------------------------------------------------------------------------
28 
29     if (M != NULL)
30     {
31 
32         if (!Mask_struct)
33         {
34             // M is typecast to boolean
35             if (!GB_Type_compatible (M->type, GrB_BOOL))
36             {
37                 GB_ERROR (GrB_DOMAIN_MISMATCH,
38                     "M of type [%s] cannot be typecast to boolean",
39                     M->type->name) ;
40             }
41         }
42 
43         // check the mask dimensions
44         GrB_Index cnrows = (C == NULL) ? nrows : GB_NROWS (C) ;
45         GrB_Index cncols = (C == NULL) ? ncols : GB_NCOLS (C) ;
46         if (GB_NROWS (M) != cnrows || GB_NCOLS (M) != cncols)
47         {
48             GB_ERROR (GrB_DIMENSION_MISMATCH,
49                 "M is " GBd "-by-" GBd "; "
50                 "does not match output dimensions (" GBu "-by-" GBu ")",
51                 GB_NROWS (M), GB_NCOLS (M), cnrows, cncols) ;
52         }
53     }
54 
55     return (GrB_SUCCESS) ;
56 }
57 
58