File: GB_binop_pattern.c

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (57 lines) | stat: -rw-r--r-- 2,045 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//------------------------------------------------------------------------------
// GB_binop_pattern: determine if values of A and B will be used by C=op(A,B)
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

// Given the opcode of a operator z = op (x,y), and a flipxy flag, determine if
// C=op(A,B) will use just the pattern of A and/or B.  op(A,B) is the multiply
// operator for C=A*B, or the ewise operator for eWiseMult.

#include "GB.h"
#include "GB_binop.h"

void GB_binop_pattern
(
    // outputs:
    bool *A_is_pattern,     // true if A is pattern-only, because of the op
    bool *B_is_pattern,     // true if B is pattern-only, because of the op
    // inputs:
    const bool flipxy,      // if true,  z = op (b,a) will be computed
                            // if false, z = op (a,b) will be computed
    const GB_Opcode opcode  // opcode of binary op
)
{

    //--------------------------------------------------------------------------
    // determine A_is_pattern and B_is_pattern
    //--------------------------------------------------------------------------

    bool op_is_positional = GB_OPCODE_IS_POSITIONAL (opcode) ;
    bool op_is_first  = (opcode == GB_FIRST_binop_code) ;
    bool op_is_second = (opcode == GB_SECOND_binop_code) ;
    bool op_is_pair   = (opcode == GB_PAIR_binop_code) ;

    if (op_is_positional || op_is_pair)
    { 
        // mult (x,y) does not depend on the values of x or y
        (*A_is_pattern) = true ;
        (*B_is_pattern) = true ;
    }
    else if (flipxy)
    { 
        // z = mult (b,a) will be computed
        (*A_is_pattern) = op_is_first  ;
        (*B_is_pattern) = op_is_second ;
    }
    else
    { 
        // z = mult (a,b) will be computed
        (*A_is_pattern) = op_is_second ;
        (*B_is_pattern) = op_is_first  ;
    }
}