1 //------------------------------------------------------------------------------
2 // GrB_Matrix_assign_[SCALAR]: assign a scalar to matrix, via scalar expansion
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 matrix:
11 
12 // C<M>(Rows,Cols) = accum(C(Rows,Cols),x)
13 
14 // The scalar x is implicitly expanded into a matrix A of size nRows-by-nCols,
15 // with each entry in A equal to x.
16 
17 // Compare with GxB_Matrix_subassign_scalar,
18 // which uses M and C_Replace differently.
19 
20 // The actual work is done in GB_assign_scalar.c.
21 
22 #include "GB_assign.h"
23 
24 #define GB_ASSIGN_SCALAR(prefix,type,T,ampersand)                              \
25 GrB_Info GB_EVAL3 (prefix, _Matrix_assign_, T) /* C<M>(Rows,Cols) += x */      \
26 (                                                                              \
27     GrB_Matrix C,                   /* input/output matrix for results      */ \
28     const GrB_Matrix M,             /* optional mask for C                  */ \
29     const GrB_BinaryOp accum,       /* accum for Z=accum(C(Rows,Cols),x)    */ \
30     type x,                         /* scalar to assign to C(Rows,Cols)     */ \
31     const GrB_Index *Rows,          /* row indices                          */ \
32     GrB_Index nRows,                /* number of row indices                */ \
33     const GrB_Index *Cols,          /* column indices                       */ \
34     GrB_Index nCols,                /* number of column indices             */ \
35     const GrB_Descriptor desc       /* descriptor for C and M               */ \
36 )                                                                              \
37 {                                                                              \
38     GB_WHERE (C, "GrB_Matrix_assign_" GB_STR(T)                                \
39         " (C, M, accum, x, Rows, nRows, Cols, nCols, desc)") ;                 \
40     GB_BURBLE_START ("GrB_assign") ;                                           \
41     GB_RETURN_IF_NULL_OR_FAULTY (C) ;                                          \
42     GB_RETURN_IF_FAULTY (M) ;                                                  \
43     GrB_Info info = GB_assign_scalar (C, M, accum, ampersand x,                \
44         GB_## T ## _code, Rows, nRows, Cols, nCols, desc, Context) ;           \
45     GB_BURBLE_END ;                                                            \
46     return (info) ;                                                            \
47 }
48 
49 GB_ASSIGN_SCALAR (GrB, bool      , BOOL   , &)
50 GB_ASSIGN_SCALAR (GrB, int8_t    , INT8   , &)
51 GB_ASSIGN_SCALAR (GrB, uint8_t   , UINT8  , &)
52 GB_ASSIGN_SCALAR (GrB, int16_t   , INT16  , &)
53 GB_ASSIGN_SCALAR (GrB, uint16_t  , UINT16 , &)
54 GB_ASSIGN_SCALAR (GrB, int32_t   , INT32  , &)
55 GB_ASSIGN_SCALAR (GrB, uint32_t  , UINT32 , &)
56 GB_ASSIGN_SCALAR (GrB, int64_t   , INT64  , &)
57 GB_ASSIGN_SCALAR (GrB, uint64_t  , UINT64 , &)
58 GB_ASSIGN_SCALAR (GrB, float     , FP32   , &)
59 GB_ASSIGN_SCALAR (GrB, double    , FP64   , &)
60 GB_ASSIGN_SCALAR (GxB, GxB_FC32_t, FC32   , &)
61 GB_ASSIGN_SCALAR (GxB, GxB_FC64_t, FC64   , &)
62 GB_ASSIGN_SCALAR (GrB, void *    , UDT    ,  )
63 
64