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