1 //------------------------------------------------------------------------------
2 // GB_bitmap_assign_noM_accum_whole: assign to C bitmap, mask M is not present
3 //------------------------------------------------------------------------------
4
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7
8 //------------------------------------------------------------------------------
9 // C<> += A assign
10 // C<> += A subassign
11
12 // C<repl> += A assign
13 // C<repl> += A subassign
14
15 // C<!> += A assign: no work to do
16 // C<!> += A subassign: no work to do
17
18 // C<!,repl> += A assign: just clear C of all entries, not done here
19 // C<!,repl> += A subassign: just clear C of all entries, not done here
20 //------------------------------------------------------------------------------
21
22 // C: bitmap
23 // M: none
24 // Mask_comp: true or false
25 // Mask_struct: true or false
26 // C_replace: true or false
27 // accum: present
28 // A: matrix (hyper, sparse, bitmap, or full), or scalar
29 // kind: assign or subassign (same action)
30
31 // If Mask_comp is true, then an empty mask is complemented. This case has
32 // already been handled by GB_assign_prep, which calls GB_clear, and thus
33 // Mask_comp is always false in this method.
34
35 #include "GB_bitmap_assign_methods.h"
36
37 #define GB_FREE_ALL ;
38
GB_bitmap_assign_noM_accum_whole(GrB_Matrix C,const bool C_replace,const bool Mask_comp,const bool Mask_struct,const GrB_BinaryOp accum,const GrB_Matrix A,const void * scalar,const GrB_Type scalar_type,GB_Context Context)39 GrB_Info GB_bitmap_assign_noM_accum_whole
40 (
41 // input/output:
42 GrB_Matrix C, // input/output matrix in bitmap format
43 // inputs:
44 const bool C_replace, // descriptor for C
45 // const GrB_Matrix M, // mask matrix, not present here
46 const bool Mask_comp, // true for !M, false for M
47 const bool Mask_struct, // true if M is structural, false if valued
48 const GrB_BinaryOp accum, // present
49 const GrB_Matrix A, // input matrix, not transposed
50 const void *scalar, // input scalar
51 const GrB_Type scalar_type, // type of input scalar
52 GB_Context Context
53 )
54 {
55
56 //--------------------------------------------------------------------------
57 // check inputs
58 //--------------------------------------------------------------------------
59
60 GBURBLE_BITMAP_ASSIGN ("bit5:whole", NULL, Mask_comp, accum,
61 GB_ALL, GB_ALL, GB_ASSIGN) ;
62 ASSERT_MATRIX_OK (C, "C for bitmap assign, no M, accum", GB0) ;
63 ASSERT_MATRIX_OK_OR_NULL (A, "A for bitmap assign, no M, accum", GB0) ;
64
65 //--------------------------------------------------------------------------
66 // get inputs
67 //--------------------------------------------------------------------------
68
69 GB_GET_C_BITMAP ; // C must be bitmap
70 GB_GET_A_AND_SCALAR
71 GB_GET_ACCUM_FOR_BITMAP
72
73 //--------------------------------------------------------------------------
74 // do the assignment
75 //--------------------------------------------------------------------------
76
77 if (!Mask_comp)
78 {
79
80 //----------------------------------------------------------------------
81 // C += A or += scalar
82 //----------------------------------------------------------------------
83
84 if (A == NULL)
85 {
86
87 //------------------------------------------------------------------
88 // scalar assignment: C += scalar
89 //------------------------------------------------------------------
90
91 #undef GB_CIJ_WORK
92 #define GB_CIJ_WORK(pC) \
93 { \
94 int8_t cb = Cb [pC] ; \
95 if (cb == 0) \
96 { \
97 /* Cx [pC] = scalar */ \
98 GB_ASSIGN_SCALAR (pC) ; \
99 } \
100 else \
101 { \
102 /* Cx [pC] += scalar */ \
103 GB_ACCUM_SCALAR (pC) ; \
104 } \
105 }
106 #include "GB_bitmap_assign_C_whole_template.c"
107
108 // free the bitmap or set it to all ones
109 GB_bitmap_assign_to_full (C, nthreads_max) ;
110
111 }
112 else
113 {
114
115 //------------------------------------------------------------------
116 // matrix assignment: C += A
117 //------------------------------------------------------------------
118
119 if (GB_IS_FULL (A))
120 {
121
122 //--------------------------------------------------------------
123 // C += A where C is bitmap and A is full
124 //--------------------------------------------------------------
125
126 #undef GB_CIJ_WORK
127 #define GB_CIJ_WORK(pC) \
128 { \
129 int8_t cb = Cb [pC] ; \
130 if (cb == 0) \
131 { \
132 /* Cx [pC] = Ax [pC] */ \
133 GB_ASSIGN_AIJ (pC, pC) ; \
134 } \
135 else \
136 { \
137 /* Cx [pC] += Ax [pC] */ \
138 GB_ACCUM_AIJ (pC, pC) ; \
139 } \
140 }
141 #include "GB_bitmap_assign_C_whole_template.c"
142
143 // free the bitmap or set it to all ones
144 GB_bitmap_assign_to_full (C, nthreads_max) ;
145
146 }
147 else if (GB_IS_BITMAP (A))
148 {
149
150 //--------------------------------------------------------------
151 // C += A where C and A are bitmap
152 //--------------------------------------------------------------
153
154 #undef GB_CIJ_WORK
155 #define GB_CIJ_WORK(pC) \
156 { \
157 if (Ab [pC]) \
158 { \
159 int8_t cb = Cb [pC] ; \
160 if (cb == 0) \
161 { \
162 /* Cx [pC] = Ax [pC] */ \
163 GB_ASSIGN_AIJ (pC, pC) ; \
164 Cb [pC] = 1 ; \
165 task_cnvals++ ; \
166 } \
167 else \
168 { \
169 /* Cx [pC] += Ax [pC] */ \
170 GB_ACCUM_AIJ (pC, pC) ; \
171 } \
172 } \
173 }
174 #include "GB_bitmap_assign_C_whole_template.c"
175 C->nvals = cnvals ;
176
177 }
178 else
179 {
180
181 //--------------------------------------------------------------
182 // C += A where C is bitmap and A is sparse or hyper
183 //--------------------------------------------------------------
184
185 #undef GB_AIJ_WORK
186 #define GB_AIJ_WORK(pC,pA) \
187 { \
188 int8_t cb = Cb [pC] ; \
189 if (cb == 0) \
190 { \
191 /* Cx [pC] = Ax [pA] */ \
192 GB_ASSIGN_AIJ (pC, pA) ; \
193 Cb [pC] = 1 ; \
194 task_cnvals++ ; \
195 } \
196 else \
197 { \
198 /* Cx [pC] += Ax [pA] */ \
199 GB_ACCUM_AIJ (pC, pA) ; \
200 } \
201 }
202 #include "GB_bitmap_assign_A_whole_template.c"
203 C->nvals = cnvals ;
204 }
205 }
206 }
207
208 #if 0
209 else if (C_replace)
210 {
211 // The mask is not present yet complemented: C_replace phase only. all
212 // entries are deleted. This is done by GB_clear in GB_assign_prep
213 // and is thus not needed here.
214 GB_memset (Cb, 0, cnzmax, nthreads_max) ;
215 cnvals = 0 ;
216 }
217 #endif
218
219 //--------------------------------------------------------------------------
220 // return result
221 //--------------------------------------------------------------------------
222
223 ASSERT_MATRIX_OK (C, "C for bitmap assign, no M, accum, whole", GB0) ;
224 return (GrB_SUCCESS) ;
225 }
226
227