File: GB_printf.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 (140 lines) | stat: -rw-r--r-- 4,681 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//------------------------------------------------------------------------------
// GB_printf.c: printing for GraphBLAS *check functions
//------------------------------------------------------------------------------

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

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

#include "GB.h"

void GB_burble_assign
(
    const bool C_replace,       // descriptor for C
    const int Ikind,
    const int Jkind,
    const GrB_Matrix M,         // mask matrix, which is not NULL here
    const bool Mask_comp,       // true for !M, false for M
    const bool Mask_struct,     // true if M is structural, false if valued
    const GrB_BinaryOp accum,   // present here
    const GrB_Matrix A,         // input matrix, not transposed
    const int assign_kind       // row assign, col assign, assign, or subassign
)
{

    //--------------------------------------------------------------------------
    // quick return if burble is disabled
    //--------------------------------------------------------------------------

    if (!GB_Global_burble_get ( ))
    {
        return ;
    }

    //--------------------------------------------------------------------------
    // construct the accum operator string
    //--------------------------------------------------------------------------

    char *Op ;
    if (accum == NULL)
    {
        // no accum operator is present
        Op = "" ;
    }
    else
    {
        // use a simpler version of accum->name
        if (accum->opcode == GB_USER_binop_code) Op = "op" ;
        else if (GB_STRING_MATCH (accum->name, "plus")) Op = "+" ;
        else if (GB_STRING_MATCH (accum->name, "minus")) Op = "-" ;
        else if (GB_STRING_MATCH (accum->name, "times")) Op = "*" ;
        else if (GB_STRING_MATCH (accum->name, "div")) Op = "/" ;
        else if (GB_STRING_MATCH (accum->name, "or")) Op = "|" ;
        else if (GB_STRING_MATCH (accum->name, "and")) Op = "&" ;
        else if (GB_STRING_MATCH (accum->name, "xor")) Op = "^" ;
        else Op = accum->name ;
    }

    //--------------------------------------------------------------------------
    // construct the Mask string
    //--------------------------------------------------------------------------

    #define GB_STRLEN 128
    const char *Mask ;
    char Mask_string [GB_STRLEN+1] ;
    if (M == NULL)
    {
        // M is not present
        if (Mask_comp)
        {
            Mask = C_replace ? "<!,replace>" : "<!>" ;
        }
        else
        {
            Mask = C_replace ? "<replace>" : "" ;
        }
    }
    else
    {
        // M is present
        snprintf (Mask_string, GB_STRLEN, "<%sM%s%s%s>",
            (Mask_comp) ? "!" : "",
            GB_IS_BITMAP (M) ? ",bitmap" : (GB_IS_FULL (M) ? ",full" : ""),
            Mask_struct ? ",struct" : "",
            C_replace ? ",replace" : "") ;
        Mask = Mask_string ;
    }

    //--------------------------------------------------------------------------
    // construct the string for A or the scalar
    //--------------------------------------------------------------------------

    const char *S = (A == NULL) ? "scalar" : "A" ;

    //--------------------------------------------------------------------------
    // construct the string for (I,J)
    //--------------------------------------------------------------------------

    const char *Istr = (Ikind == GB_ALL) ? ":" : "I" ;
    const char *Jstr = (Jkind == GB_ALL) ? ":" : "J" ;
    char IJ [GB_STRLEN+1] ;
    snprintf (IJ, GB_STRLEN, "(%s,%s)", Istr, Jstr) ;
    if (Ikind == GB_ALL && Jkind == GB_ALL)
    {
        // do not print the (I,J) indices
        IJ [0] = '\0' ;
    }

    //--------------------------------------------------------------------------
    // burble the final result
    //--------------------------------------------------------------------------

    switch (assign_kind)
    {
        case GB_ROW_ASSIGN:
            // C(i,J) = A
            snprintf (IJ, GB_STRLEN, "(i,%s)", Jstr) ;
            GBURBLE ("C%s%s %s= A ", Mask, IJ, Op) ;
            break ;

        case GB_COL_ASSIGN:
            // C(I,j) = A
            snprintf (IJ, GB_STRLEN, "(%s,j)", Istr) ;
            GBURBLE ("C%s%s %s= A ", Mask, IJ, Op) ;
            break ;

        case GB_ASSIGN:
            // C(I,J) = A
            GBURBLE ("C%s%s %s= %s ", Mask, IJ, Op, S) ;
            break ;

        case GB_SUBASSIGN:
            // C(i,J) = A
            GBURBLE ("C%s%s %s= %s ", IJ, Mask, Op, S) ;
            break ;

        default: ;
    }
}