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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
|
//------------------------------------------------------------------------------
// GB_bitmap_assign_M_noaccum_whole: assign to C bitmap
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// C<M> = A assign
// C<M> = A subassign
// C<M,repl> = A assign
// C<M,repl> = A subassign
//------------------------------------------------------------------------------
// C: bitmap
// M: present, hypersparse or sparse, (not bitmap or full)
// Mask_comp: false
// Mask_struct: true or false
// C_replace: true or false
// accum: not present
// A: matrix (hyper, sparse, bitmap, or full), or scalar
// kind: assign or subassign (same action)
#include "GB_bitmap_assign_methods.h"
#define GB_FREE_ALL \
{ \
GB_WERK_POP (M_ek_slicing, int64_t) ; \
}
GrB_Info GB_bitmap_assign_M_noaccum_whole
(
// input/output:
GrB_Matrix C, // input/output matrix in bitmap format
// inputs:
const bool C_replace, // descriptor for C
const GrB_Matrix M, // mask matrix, which is not NULL here
// const bool Mask_comp, // false here
const bool Mask_struct, // true if M is structural, false if valued
// const GrB_BinaryOp accum, // not present
const GrB_Matrix A, // input matrix, not transposed
const void *scalar, // input scalar
const GrB_Type scalar_type, // type of input scalar
GB_Context Context
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
GBURBLE_BITMAP_ASSIGN ("bit4:whole", M, false, NULL,
GB_ALL, GB_ALL, GB_ASSIGN) ;
ASSERT (GB_IS_HYPERSPARSE (M) || GB_IS_SPARSE (M)) ;
ASSERT (GB_JUMBLED_OK (M)) ;
ASSERT_MATRIX_OK (C, "C for bitmap assign, M, noaccum", GB0) ;
ASSERT_MATRIX_OK (M, "M for bitmap assign, M, noaccum", GB0) ;
ASSERT_MATRIX_OK_OR_NULL (A, "A for bitmap assign, M, noaccum", GB0) ;
//--------------------------------------------------------------------------
// get inputs
//--------------------------------------------------------------------------
GB_GET_C_BITMAP ; // C must be bitmap
GB_SLICE_M
GB_GET_A_AND_SCALAR
//--------------------------------------------------------------------------
// C<M,repl or !repl>(I,J) = A or scalar
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// scatter A or the scalar into C
//--------------------------------------------------------------------------
if (A == NULL)
{
//----------------------------------------------------------------------
// scalar assignment: C<M or !M, repl or !repl> = scalar
//----------------------------------------------------------------------
if (C_replace)
{
// Cb [pC] += 2 for each entry M(i,j) in the mask
GB_bitmap_M_scatter_whole (C,
M, Mask_struct, GB_BITMAP_M_SCATTER_PLUS_2,
M_ek_slicing, M_ntasks, M_nthreads, Context) ;
// the bitmap of C now contains:
// Cb (i,j) = 0: cij not present, mij zero
// Cb (i,j) = 1: cij present, mij zero
// Cb (i,j) = 2: cij not present, mij 1
// Cb (i,j) = 3: cij present, mij 1
//------------------------------------------------------------------
// C<M,replace> = scalar
//------------------------------------------------------------------
#undef GB_CIJ_WORK
#define GB_CIJ_WORK(pC) \
{ \
switch (Cb [pC]) \
{ \
case 1: /* C(i,j) present, M(i,j) = 0 */ \
Cb [pC] = 0 ; \
task_cnvals-- ; \
break ; \
case 2: /* C(i,j) not present, M(i,j) = 1 */ \
/* Cx [pC] = scalar */ \
GB_ASSIGN_SCALAR (pC) ; \
Cb [pC] = 1 ; \
task_cnvals++ ; \
break ; \
case 3: /* C(i,j) present, M(i,j) = 1 */ \
/* Cx [pC] = scalar */ \
GB_ASSIGN_SCALAR (pC) ; \
Cb [pC] = 1 ; \
default: ; \
} \
}
#include "GB_bitmap_assign_C_whole_template.c"
}
else
{
//------------------------------------------------------------------
// C<M> = scalar
//------------------------------------------------------------------
#undef GB_MASK_WORK
#define GB_MASK_WORK(pC) \
{ \
if (Cb [pC]) \
{ \
/* C(i,j) present, M(i,j) = 1 */ \
/* Cx [pC] = scalar */ \
GB_ASSIGN_SCALAR (pC) ; \
} \
else \
{ \
/* C(i,j) not present, M(i,j) = 1 */ \
/* Cx [pC] = scalar */ \
GB_ASSIGN_SCALAR (pC) ; \
Cb [pC] = 1 ; \
task_cnvals++ ; \
} \
}
#include "GB_bitmap_assign_M_all_template.c"
}
}
else
{
//----------------------------------------------------------------------
// matrix assignment: C<M,repl or !repl> = A
//----------------------------------------------------------------------
if (GB_IS_BITMAP (A) || GB_IS_FULL (A))
{
//------------------------------------------------------------------
// C<M, replace or !replace> = A where A is bitmap or full
//------------------------------------------------------------------
if (C_replace)
{
//--------------------------------------------------------------
// C<M,replace> = A where A is bitmap or full
//--------------------------------------------------------------
// Cb [pC] += 2 for each entry M(i,j) in the mask
GB_bitmap_M_scatter_whole (C,
M, Mask_struct, GB_BITMAP_M_SCATTER_PLUS_2,
M_ek_slicing, M_ntasks, M_nthreads, Context) ;
// the bitmap of C now contains:
// Cb (i,j) = 0: cij not present, mij zero
// Cb (i,j) = 1: cij present, mij zero
// Cb (i,j) = 2: cij not present, mij 1
// Cb (i,j) = 3: cij present, mij 1
#undef GB_CIJ_WORK
#define GB_CIJ_WORK(pC) \
{ \
switch (Cb [pC]) \
{ \
case 1: /* C(i,j) present, M(i,j) = 0 */ \
Cb [pC] = 0 ; \
task_cnvals-- ; \
break ; \
case 2: /* C(i,j) not present, M(i,j) = 1 */ \
if (GBB (Ab, pC)) \
{ \
/* Cx [pC] = Ax [pC] */ \
GB_ASSIGN_AIJ (pC, pC) ; \
Cb [pC] = 1 ; \
task_cnvals++ ; \
} \
else \
{ \
/* clear the mask from C */ \
Cb [pC] = 0 ; \
} \
break ; \
case 3: /* C(i,j) present, M(i,j) = 1 */ \
if (GBB (Ab, pC)) \
{ \
/* Cx [pC] = Ax [pC] */ \
GB_ASSIGN_AIJ (pC, pC) ; \
Cb [pC] = 1 ; \
} \
else \
{ \
/* delete C(i,j) */ \
Cb [pC] = 0 ; \
task_cnvals-- ; \
} \
break ; \
default: ; \
} \
}
#include "GB_bitmap_assign_C_whole_template.c"
}
else
{
//--------------------------------------------------------------
// C<M> = A where A is bitmap or full
//--------------------------------------------------------------
#undef GB_MASK_WORK
#define GB_MASK_WORK(pC) \
{ \
if (Cb [pC]) \
{ \
/* C(i,j) present, M(i,j) = 1 */ \
if (GBB (Ab, pC)) \
{ \
/* Cx [pC] = Ax [pC] */ \
GB_ASSIGN_AIJ (pC, pC) ; \
} \
else \
{ \
/* delete C(i,j) */ \
Cb [pC] = 0 ; \
task_cnvals-- ; \
} \
} \
else \
{ \
/* C(i,j) not present, M(i,j) = 1 */ \
if (GBB (Ab, pC)) \
{ \
/* Cx [pC] = Ax [pC] */ \
GB_ASSIGN_AIJ (pC, pC) ; \
Cb [pC] = 1 ; \
task_cnvals++ ; \
} \
} \
}
#include "GB_bitmap_assign_M_all_template.c"
}
}
else
{
//------------------------------------------------------------------
// C<M, replace or !replace> = A where A is sparse or hyper
//------------------------------------------------------------------
if (C_replace)
{
//--------------------------------------------------------------
// C<M,replace> = A where A is sparse or hyper
//--------------------------------------------------------------
// Cb [pC] += 2 for each entry M(i,j) in the mask
GB_bitmap_M_scatter_whole (C,
M, Mask_struct, GB_BITMAP_M_SCATTER_PLUS_2,
M_ek_slicing, M_ntasks, M_nthreads, Context) ;
// the bitmap of C now contains:
// Cb (i,j) = 0: cij not present, mij zero
// Cb (i,j) = 1: cij present, mij zero
// Cb (i,j) = 2: cij not present, mij 1
// Cb (i,j) = 3: cij present, mij 1
// assign entries from A into C
#undef GB_AIJ_WORK
#define GB_AIJ_WORK(pC,pA) \
{ \
int8_t cb = Cb [pC] ; \
if (cb >= 2) \
{ \
/* M(i,j)=1 and A(i,j) present */ \
/* Cx [pC] = Ax [pA] ; */ \
GB_ASSIGN_AIJ (pC, pA) ; \
Cb [pC] = 4 ; \
task_cnvals += (cb == 2) ; \
} \
}
#include "GB_bitmap_assign_A_whole_template.c"
// clear the mask and delete entries not assigned
#undef GB_CIJ_WORK
#define GB_CIJ_WORK(pC) \
{ \
int8_t cb = Cb [pC] ; \
Cb [pC] = (cb == 4) ; \
task_cnvals -= (cb == 1 || cb == 3) ; \
}
#include "GB_bitmap_assign_C_whole_template.c"
}
else if (GB_nnz (A) == 0)
{
//--------------------------------------------------------------
// C<M> = A where A is sparse or hyper, with no entries
//--------------------------------------------------------------
GBURBLE ("(A empty) ") ;
// delete entries via the mask
#undef GB_MASK_WORK
#define GB_MASK_WORK(pC) \
{ \
int8_t cb = Cb [pC] ; \
Cb [pC] = 0 ; \
task_cnvals -= (cb == 1) ; \
}
#include "GB_bitmap_assign_M_all_template.c"
}
else
{
//--------------------------------------------------------------
// C<M> = A where A is sparse or hyper
//--------------------------------------------------------------
// Cb [pC] += 2 for each entry M(i,j) in the mask
GB_bitmap_M_scatter_whole (C,
M, Mask_struct, GB_BITMAP_M_SCATTER_PLUS_2,
M_ek_slicing, M_ntasks, M_nthreads, Context) ;
// the bitmap of C now contains:
// Cb (i,j) = 0: cij not present, mij zero
// Cb (i,j) = 1: cij present, mij zero
// Cb (i,j) = 2: cij not present, mij 1
// Cb (i,j) = 3: cij present, mij 1
// assign entries from A into C
#undef GB_AIJ_WORK
#define GB_AIJ_WORK(pC,pA) \
{ \
int8_t cb = Cb [pC] ; \
if (cb >= 2) \
{ \
/* M(i,j)=1 and A(i,j) present */ \
/* Cx [pC] = Ax [pA] ; */ \
GB_ASSIGN_AIJ (pC, pA) ; \
Cb [pC] = 1 ; \
task_cnvals += (cb == 2) ; \
} \
}
#include "GB_bitmap_assign_A_whole_template.c"
// clear the mask and delete entries not assigned
#undef GB_MASK_WORK
#define GB_MASK_WORK(pC) \
{ \
int8_t cb = Cb [pC] ; \
Cb [pC] = (cb == 1) ; \
task_cnvals -= (cb == 3) ; \
}
#include "GB_bitmap_assign_M_all_template.c"
}
}
}
//--------------------------------------------------------------------------
// free workspace and return result
//--------------------------------------------------------------------------
C->nvals = cnvals ;
GB_FREE_ALL ;
ASSERT_MATRIX_OK (C, "final C for bitmap assign, M, noaccum, whole", GB0) ;
return (GrB_SUCCESS) ;
}
|