1 //------------------------------------------------------------------------------
2 // GB_subassign_scalar: C(Rows,Cols)<M> = accum (C(Rows,Cols),x)
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 // Assigns a single scalar to a submatrix:
11 
12 // C(Rows,Cols)<M> = accum (C(Rows,Cols),x)
13 
14 // This function does the work for GxB_Matrix_subassign_TYPE and
15 // GxB_Vector_subassign_[type], where [type] is one of the 11 types, or the
16 // type-generic macro suffix, "_UDT".
17 
18 // Compare with GB_assign_scalar, which uses M and C_replace differently
19 
20 #include "GB_subassign.h"
21 
GB_subassign_scalar(GrB_Matrix C,const GrB_Matrix M,const GrB_BinaryOp accum,const void * scalar,const GB_Type_code scalar_code,const GrB_Index * Rows,const GrB_Index nRows,const GrB_Index * Cols,const GrB_Index nCols,const GrB_Descriptor desc,GB_Context Context)22 GrB_Info GB_subassign_scalar        // C(Rows,Cols)<M> += x
23 (
24     GrB_Matrix C,                   // input/output matrix for results
25     const GrB_Matrix M,             // mask for C(Rows,Cols), unused if NULL
26     const GrB_BinaryOp accum,       // accum for Z=accum(C(Rows,Cols),T)
27     const void *scalar,             // scalar to assign to C(Rows,Cols)
28     const GB_Type_code scalar_code, // type code of scalar to assign
29     const GrB_Index *Rows,          // row indices
30     const GrB_Index nRows,          // number of row indices
31     const GrB_Index *Cols,          // column indices
32     const GrB_Index nCols,          // number of column indices
33     const GrB_Descriptor desc,      // descriptor for C(Rows,Cols) and M
34     GB_Context Context
35 )
36 {
37 
38     //--------------------------------------------------------------------------
39     // check inputs
40     //--------------------------------------------------------------------------
41 
42     // C may be aliased with M
43 
44     GB_RETURN_IF_NULL (scalar) ;
45     ASSERT (scalar_code <= GB_UDT_code) ;
46 
47     // get the descriptor
48     GB_GET_DESCRIPTOR (info, desc, C_replace, Mask_comp, Mask_struct,
49         xx1, xx2, xx3, xx7) ;
50 
51     //--------------------------------------------------------------------------
52     // C(Rows,Cols)<M> = accum (C(Rows,Cols), scalar)
53     //--------------------------------------------------------------------------
54 
55     info = (GB_subassign (
56         C,          C_replace,      // C matrix and its descriptor
57         M, Mask_comp, Mask_struct,  // mask matrix and its descriptor
58         false,                      // do not transpose the mask
59         accum,                      // for accum (C(Rows,Cols),scalar)
60         NULL,       false,          // no explicit matrix A
61         Rows, nRows,                // row indices
62         Cols, nCols,                // column indices
63         true,                       // do scalar expansion
64         scalar,                     // scalar to assign, expands to become A
65         scalar_code,                // type code of scalar to expand
66         Context)) ;
67     return (info) ;
68 }
69 
70