File: GB_positional_idxunop_ijflip.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 (119 lines) | stat: -rw-r--r-- 3,770 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//------------------------------------------------------------------------------
// GB_positional_idxunop_ijflip: swap i and j in an index unary positional op
//------------------------------------------------------------------------------

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

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

// Flip i and j to handle the CSR/CSC variations, for index-unary positional
// ops.  The two operators GB_FLIPDIAG_INT[32,64] are only used internally
// and are not available to the user application.

#include "GB.h"

GrB_IndexUnaryOp GB_positional_idxunop_ijflip   // return flipped operator
(
    int64_t *ithunk,            // input/output: revised value of thunk
    GrB_IndexUnaryOp op         // operator to flip
)
{

    ASSERT (op != NULL) ;

    if (op->ztype == GrB_INT64)
    {
        switch (op->opcode)
        {

            case GB_ROWINDEX_idxunop_code  : 
                // i+thunk becomes j+thunk: no change to thunk
                return (GrB_COLINDEX_INT64) ;

            case GB_COLINDEX_idxunop_code  : 
                // j+thunk becomes i+thunk: no change to thunk
                return (GrB_ROWINDEX_INT64) ;

            case GB_DIAGINDEX_idxunop_code : 
                // j-(i+thunk) becomes i-(j+thunk): no change to thunk
                return (GxB_FLIPDIAGINDEX_INT64) ;

            default: ;
        }

    }
    else if (op->ztype == GrB_INT32)
    {

        switch (op->opcode)
        {

            case GB_ROWINDEX_idxunop_code  : 
                // i+thunk becomes j+thunk: no change to thunk
                return (GrB_COLINDEX_INT32) ;

            case GB_COLINDEX_idxunop_code  : 
                // j+thunk becomes i+thunk: no change to thunk
                return (GrB_ROWINDEX_INT32) ;

            case GB_DIAGINDEX_idxunop_code : 
                // j-(i+thunk) becomes i-(j+thunk): no change to thunk
                return (GxB_FLIPDIAGINDEX_INT32) ;

            default: ;
        }

    }
    else if (op->ztype == GrB_BOOL)
    {

        switch (op->opcode)
        {

            case GB_TRIL_idxunop_code      : 
                // (j <= (i+thunk)) becomes (i <= (j+thunk))
                // or (i-thunk) <= j which is j >= (i-thunk).
                // TRIL becomes TRIU and thunk must be negated.
                (*ithunk) = -(*ithunk) ;
                return (GrB_TRIU) ;

            case GB_TRIU_idxunop_code      : 
                // (j >= (i+thunk)) becomes (i >= (j+thunk))
                // or (i-thunk) >= j which is j <= (i-thunk).
                // TRIU becomes TRIL and thunk must be negated.
                (*ithunk) = -(*ithunk) ;
                return (GrB_TRIL) ;

            case GB_DIAG_idxunop_code      : 
            case GB_OFFDIAG_idxunop_code   : 
                // DIAG:    (j == (i+thunk))
                // OFFDIAG: (j != (i+thunk))
                // no change to DIAG and OFFDIAG, but negate the thunk
                (*ithunk) = -(*ithunk) ;
                return (op) ;

            case GB_COLLE_idxunop_code     : 
                // (j <= thunk) becomes (i <= thunk)
                return (GrB_ROWLE) ;

            case GB_COLGT_idxunop_code     : 
                // (j > thunk) becomes (i > thunk)
                return (GrB_ROWGT) ;

            case GB_ROWLE_idxunop_code     : 
                // (i <= thunk) becomes (j <= thunk)
                return (GrB_COLLE) ;

            case GB_ROWGT_idxunop_code     : 
                // (i > thunk) becomes (j > thunk)
                return (GrB_COLGT) ;

            default: ;
        }
    }

    // all other ops are not modified
    return (op) ;
}