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