1 //------------------------------------------------------------------------------
2 // GB_AxB_pattern: determine if the values of A and B will be used by C=A*B
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 // Given the opcode of a multiplicative operator z = mult (x,y), and a flipxy
11 // flag, determine if C=A*B will use just the pattern of A and/or B.
12 
13 #include "GB_mxm.h"
14 
GB_AxB_pattern(bool * A_is_pattern,bool * B_is_pattern,const bool flipxy,const GB_Opcode mult_opcode)15 void GB_AxB_pattern
16 (
17     // outputs:
18     bool *A_is_pattern,     // true if A is pattern-only, because of the mult
19     bool *B_is_pattern,     // true if B is pattern-only, because of the mult
20     // inputs:
21     const bool flipxy,      // if true,  z = mult (b,a) will be computed
22                             // if false, z = mult (a,b) will be computed
23     const GB_Opcode mult_opcode // opcode of multiply operator
24 )
25 {
26 
27     //--------------------------------------------------------------------------
28     // determine A_is_pattern and B_is_pattern
29     //--------------------------------------------------------------------------
30 
31     bool op_is_positional = GB_OPCODE_IS_POSITIONAL (mult_opcode) ;
32     bool op_is_first  = (mult_opcode == GB_FIRST_opcode) ;
33     bool op_is_second = (mult_opcode == GB_SECOND_opcode) ;
34     bool op_is_pair   = (mult_opcode == GB_PAIR_opcode) ;
35 
36     if (op_is_positional || op_is_pair)
37     {
38         // mult (x,y) does not depend on the values of x or y
39         (*A_is_pattern) = true ;
40         (*B_is_pattern) = true ;
41     }
42     else if (flipxy)
43     {
44         // z = mult (b,a) will be computed
45         (*A_is_pattern) = op_is_first  ;
46         (*B_is_pattern) = op_is_second ;
47     }
48     else
49     {
50         // z = mult (a,b) will be computed
51         (*A_is_pattern) = op_is_second ;
52         (*B_is_pattern) = op_is_first  ;
53     }
54 }
55 
56