File: GB_bitmap_assign_5_whole_template.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (209 lines) | stat: -rw-r--r-- 9,596 bytes parent folder | download | duplicates (2)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//------------------------------------------------------------------------------
// GB_bitmap_assign_5_whole_template: C bitmap, no M, with accum
//------------------------------------------------------------------------------

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

//------------------------------------------------------------------------------
// C<> += A            assign
// C<> += A            subassign

// C<repl> += A        assign
// C<repl> += A        subassign

// C<!> += A           assign: no work to do
// C<!> += A           subassign: no work to do

// C<!,repl> += A      assign: just clear C of all entries, not done here
// C<!,repl> += A      subassign: just clear C of all entries, not done here
//------------------------------------------------------------------------------

// C:           bitmap
// M:           none
// Mask_comp:   true or false
// Mask_struct: true or false
// C_replace:   true or false
// accum:       present
// A:           matrix (hyper, sparse, bitmap, or full), or scalar
// kind:        assign or subassign (same action)

// If Mask_comp is true, then an empty mask is complemented.  This case has
// already been handled by GB_assign_prep, which calls GB_clear, and thus
// Mask_comp is always false in this method.

// If C were full: entries can be deleted only if C_replace is true.

#undef  GB_FREE_ALL
#define GB_FREE_ALL GB_FREE_ALL_FOR_BITMAP

{

    //--------------------------------------------------------------------------
    // get inputs
    //--------------------------------------------------------------------------

    GB_GET_C_A_SCALAR_FOR_BITMAP
    GB_GET_ACCUM_FOR_BITMAP

    //--------------------------------------------------------------------------
    // do the assignment
    //--------------------------------------------------------------------------

    if (!GB_MASK_COMP)
    {

        //----------------------------------------------------------------------
        // C += A or += scalar
        //----------------------------------------------------------------------

        if (GB_SCALAR_ASSIGN)
        { 

            //------------------------------------------------------------------
            // scalar assignment: C += scalar
            //------------------------------------------------------------------

            #undef  GB_CIJ_WORK
            #define GB_CIJ_WORK(pC)                                 \
            {                                                       \
                int8_t cb = Cb [pC] ;                               \
                if (cb == 0)                                        \
                {                                                   \
                    /* Cx [pC] = scalar */                          \
                    GB_COPY_cwork_to_C (Cx, pC, cwork, C_iso) ;     \
                }                                                   \
                else                                                \
                {                                                   \
                    /* Cx [pC] += scalar */                         \
                    GB_ACCUMULATE_scalar (Cx, pC, ywork, C_iso) ;   \
                }                                                   \
            }
            if (!C_iso)
            {
                #include "template/GB_bitmap_assign_C_whole_template.c"
            }

            // free the bitmap or set it to all ones
            GB_bitmap_assign_to_full (C, nthreads_max) ;

        }
        else
        {

            //------------------------------------------------------------------
            // matrix assignment: C += A
            //------------------------------------------------------------------

            if (GB_IS_FULL (A))
            { 

                //--------------------------------------------------------------
                // C += A where C is bitmap and A is full
                //--------------------------------------------------------------

                #undef  GB_CIJ_WORK
                #define GB_CIJ_WORK(pC)                                     \
                {                                                           \
                    int8_t cb = Cb [pC] ;                                   \
                    if (cb == 0)                                            \
                    {                                                       \
                        /* Cx [pC] = Ax [pC] */                             \
                        GB_COPY_aij_to_C (Cx,pC,Ax,pC,A_iso,cwork,C_iso) ;  \
                    }                                                       \
                    else                                                    \
                    {                                                       \
                        /* Cx [pC] += Ax [pC] */                            \
                        GB_ACCUMULATE_aij (Cx,pC,Ax,pC,A_iso,ywork,C_iso) ; \
                    }                                                       \
                }
                if (!C_iso)
                {
                    #include "template/GB_bitmap_assign_C_whole_template.c"
                }

                // free the bitmap or set it to all ones
                GB_bitmap_assign_to_full (C, nthreads_max) ;

            }
            else if (GB_IS_BITMAP (A))
            { 

                //--------------------------------------------------------------
                // C += A where C and A are bitmap
                //--------------------------------------------------------------

                #undef  GB_CIJ_WORK
                #define GB_CIJ_WORK(pC)                                        \
                {                                                              \
                    if (Ab [pC])                                               \
                    {                                                          \
                        int8_t cb = Cb [pC] ;                                  \
                        if (cb == 0)                                           \
                        {                                                      \
                            /* Cx [pC] = Ax [pC] */                            \
                            GB_COPY_aij_to_C (Cx,pC,Ax,pC,A_iso,cwork,C_iso) ; \
                            Cb [pC] = 1 ;                                      \
                            task_cnvals++ ;                                    \
                        }                                                      \
                        else                                                   \
                        {                                                      \
                            /* Cx [pC] += Ax [pC] */                           \
                            GB_ACCUMULATE_aij (Cx,pC,Ax,pC,A_iso,ywork,C_iso) ;\
                        }                                                      \
                    }                                                          \
                }
                #include "template/GB_bitmap_assign_C_whole_template.c"
                C->nvals = cnvals ;

            }
            else
            { 

                //--------------------------------------------------------------
                // C += A where C is bitmap and A is sparse or hyper
                //--------------------------------------------------------------

                #undef  GB_AIJ_WORK
                #define GB_AIJ_WORK(pC,pA)                                  \
                {                                                           \
                    int8_t cb = Cb [pC] ;                                   \
                    if (cb == 0)                                            \
                    {                                                       \
                        /* Cx [pC] = Ax [pA] */                             \
                        GB_COPY_aij_to_C (Cx,pC,Ax,pA,A_iso,cwork,C_iso) ;  \
                        Cb [pC] = 1 ;                                       \
                        task_cnvals++ ;                                     \
                    }                                                       \
                    else                                                    \
                    {                                                       \
                        /* Cx [pC] += Ax [pA] */                            \
                        GB_ACCUMULATE_aij (Cx,pC,Ax,pA,A_iso,ywork,C_iso) ; \
                    }                                                       \
                }
                #include "template/GB_bitmap_assign_A_whole_template.c"
                C->nvals = cnvals ;
            }
        }
    }

#if 0
    else if (C_replace)
    {
        // The mask is not present yet complemented: C_replace phase only.  all
        // entries are deleted.  This is done by GB_clear in GB_assign_prep
        // and is thus not needed here.
        GB_memset (Cb, 0, cnzmax, nthreads_max) ;
        cnvals = 0 ;
    }
#endif

    //--------------------------------------------------------------------------
    // return result
    //--------------------------------------------------------------------------

    GB_FREE_ALL ;
    ASSERT_MATRIX_OK (C, "C for bitmap assign, no M, accum, whole", GB0) ;
    return (GrB_SUCCESS) ;
}