1 //------------------------------------------------------------------------------
2 // GB_bitmap_assign_noM_accum:  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<>(I,J) += A            assign
10 // C(I,J)<> += A            subassign
11 
12 // C<repl>(I,J) += A        assign
13 // C(I,J)<repl> += A        subassign
14 
15 // C<!>(I,J) += A           assign: no work to do
16 // C(I,J)<!> += A           subassign: no work to do
17 
18 // C<!,repl>(I,J) += A      assign: just clear C(I,J) of all entries
19 // C(I,J)<!,repl> += A      subassign: just clear C(I,J) of all entries
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, row assign, col assign, or subassign (all the same)
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
33 // GB_bitmap_assign_noM_noaccum, with a scalar (which is unused).
34 
35 #include "GB_bitmap_assign_methods.h"
36 
37 #define GB_FREE_ALL ;
38 
GB_bitmap_assign_noM_accum(GrB_Matrix C,const bool C_replace,const GrB_Index * I,const int64_t nI,const int Ikind,const int64_t Icolon[3],const GrB_Index * J,const int64_t nJ,const int Jkind,const int64_t Jcolon[3],const bool Mask_comp,const bool Mask_struct,const GrB_BinaryOp accum,const GrB_Matrix A,const void * scalar,const GrB_Type scalar_type,const int assign_kind,GB_Context Context)39 GrB_Info GB_bitmap_assign_noM_accum
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_Index *I,         // I index list
46     const int64_t nI,
47     const int Ikind,
48     const int64_t Icolon [3],
49     const GrB_Index *J,         // J index list
50     const int64_t nJ,
51     const int Jkind,
52     const int64_t Jcolon [3],
53 //  const GrB_Matrix M,         // mask matrix, not present here
54     const bool Mask_comp,       // true for !M, false for M
55     const bool Mask_struct,     // true if M is structural, false if valued
56     const GrB_BinaryOp accum,   // present
57     const GrB_Matrix A,         // input matrix, not transposed
58     const void *scalar,         // input scalar
59     const GrB_Type scalar_type, // type of input scalar
60     const int assign_kind,      // row assign, col assign, assign, or subassign
61     GB_Context Context
62 )
63 {
64 
65     //--------------------------------------------------------------------------
66     // check inputs
67     //--------------------------------------------------------------------------
68 
69     GBURBLE_BITMAP_ASSIGN ("bit5", NULL, Mask_comp, accum,
70         Ikind, Jkind, assign_kind) ;
71     ASSERT_MATRIX_OK (C, "C for bitmap assign, no M, accum", GB0) ;
72     ASSERT_MATRIX_OK_OR_NULL (A, "A for bitmap assign, no M, accum", GB0) ;
73 
74     //--------------------------------------------------------------------------
75     // get inputs
76     //--------------------------------------------------------------------------
77 
78     GB_GET_C_BITMAP ;           // C must be bitmap TODO: C full is OK
79     GB_GET_A_AND_SCALAR
80     GB_GET_ACCUM_FOR_BITMAP
81 
82     //--------------------------------------------------------------------------
83     // do the assignment
84     //--------------------------------------------------------------------------
85 
86     if (!Mask_comp)
87     {
88 
89         //----------------------------------------------------------------------
90         // C(I,J) += A or += scalar
91         //----------------------------------------------------------------------
92 
93         if (A == NULL)
94         {
95 
96             //------------------------------------------------------------------
97             // scalar assignment: C(I,J) += scalar
98             //------------------------------------------------------------------
99 
100             // for all entries in IxJ
101             #define GB_IXJ_WORK(pC,ignore)          \
102             {                                       \
103                 int8_t cb = Cb [pC] ;               \
104                 if (cb == 0)                        \
105                 {                                   \
106                     /* Cx [pC] = scalar */          \
107                     GB_ASSIGN_SCALAR (pC) ;         \
108                     Cb [pC] = 1 ;                   \
109                     task_cnvals++ ;                 \
110                 }                                   \
111                 else                                \
112                 {                                   \
113                     /* Cx [pC] += scalar */         \
114                     GB_ACCUM_SCALAR (pC) ;          \
115                 }                                   \
116             }
117             #include "GB_bitmap_assign_IxJ_template.c"
118 
119         }
120         else
121         {
122 
123             //------------------------------------------------------------------
124             // matrix assignment: C(I,J) += A
125             //------------------------------------------------------------------
126 
127             // for all entries aij in A (A hyper, sparse, bitmap, or full)
128             //        if Cb(p) == 0
129             //            Cx(p) = aij
130             //            Cb(p) = 1       // C(iC,jC) is now present, insert
131             //        else // if Cb(p) == 1:
132             //            Cx(p) += aij    // C(iC,jC) still present, updated
133             //            task_cnvals++
134 
135             #define GB_AIJ_WORK(pC,pA)              \
136             {                                       \
137                 int8_t cb = Cb [pC] ;               \
138                 if (cb == 0)                        \
139                 {                                   \
140                     /* Cx [pC] = Ax [pA] */         \
141                     GB_ASSIGN_AIJ (pC, pA) ;        \
142                     Cb [pC] = 1 ;                   \
143                     task_cnvals++ ;                 \
144                 }                                   \
145                 else                                \
146                 {                                   \
147                     /* Cx [pC] += Ax [pA] */        \
148                     GB_ACCUM_AIJ (pC, pA) ;         \
149                 }                                   \
150             }
151             #include "GB_bitmap_assign_A_template.c"
152         }
153 
154     }
155 
156 #if 0
157     else if (C_replace)
158     {
159 
160         //----------------------------------------------------------------------
161         // This case is handled by GB_assign_prep and is thus not needed here.
162         //----------------------------------------------------------------------
163 
164         // mask not present yet complemented: C_replace phase only
165 
166         // for row assign: for all entries in C(i,:)
167         // for col assign: for all entries in C(:,j)
168         // for assign: for all entries in C(:,:)
169         // for subassign: for all entries in C(I,J)
170         //      M not present; so effective value of the mask is mij==0
171         //      set Cb(p) = 0
172 
173         #define GB_CIJ_WORK(pC)         \
174         {                               \
175             int8_t cb = Cb [pC] ;       \
176             Cb [pC] = 0 ;               \
177             task_cnvals -= (cb == 1) ;  \
178         }
179         #include "GB_bitmap_assign_C_template.c"
180     }
181 #endif
182 
183     //--------------------------------------------------------------------------
184     // return result
185     //--------------------------------------------------------------------------
186 
187     C->nvals = cnvals ;
188     ASSERT_MATRIX_OK (C, "C for bitmap assign, no M, accum", GB0) ;
189     return (GrB_SUCCESS) ;
190 }
191 
192