1 //------------------------------------------------------------------------------
2 // GrB_Vector_eWiseAdd: vector element-wise operations, set union
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 // w<M> = accum (w,u+v)
11 
12 #include "GB_ewise.h"
13 
14 #define GB_EWISE(op)                                                        \
15     /* check inputs */                                                      \
16     GB_RETURN_IF_NULL_OR_FAULTY (w) ;                                       \
17     GB_RETURN_IF_NULL_OR_FAULTY (u) ;                                       \
18     GB_RETURN_IF_NULL_OR_FAULTY (v) ;                                       \
19     GB_RETURN_IF_FAULTY (M) ;                                               \
20     ASSERT (GB_VECTOR_OK (w)) ;                                             \
21     ASSERT (GB_VECTOR_OK (u)) ;                                             \
22     ASSERT (GB_VECTOR_OK (v)) ;                                             \
23     ASSERT (M == NULL || GB_VECTOR_OK (M)) ;                                \
24     /* get the descriptor */                                                \
25     GB_GET_DESCRIPTOR (info, desc, C_replace, Mask_comp, Mask_struct,       \
26         xx1, xx2, xx3, xx7) ;                                               \
27     /* w<M> = accum (w,t) where t = u+v, u'+v, u+v', or u'+v' */            \
28     info = GB_ewise (                                                       \
29         (GrB_Matrix) w, C_replace,  /* w and its descriptor        */       \
30         (GrB_Matrix) M, Mask_comp, Mask_struct, /* mask and its descriptor */\
31         accum,                      /* accumulate operator         */       \
32         op,                         /* operator that defines '+'   */       \
33         (GrB_Matrix) u, false,      /* u, never transposed         */       \
34         (GrB_Matrix) v, false,      /* v, never transposed         */       \
35         true,                       /* eWiseAdd                    */       \
36         Context)
37 
38 //------------------------------------------------------------------------------
39 // GrB_Vector_eWiseAdd_BinaryOp: vector addition
40 //------------------------------------------------------------------------------
41 
GrB_Vector_eWiseAdd_BinaryOp(GrB_Vector w,const GrB_Vector M,const GrB_BinaryOp accum,const GrB_BinaryOp add,const GrB_Vector u,const GrB_Vector v,const GrB_Descriptor desc)42 GrB_Info GrB_Vector_eWiseAdd_BinaryOp       // w<M> = accum (w, u+v)
43 (
44     GrB_Vector w,                   // input/output vector for results
45     const GrB_Vector M,             // optional mask for w, unused if NULL
46     const GrB_BinaryOp accum,       // optional accum for z=accum(w,t)
47     const GrB_BinaryOp add,         // defines '+' for t=u+v
48     const GrB_Vector u,             // first input:  vector u
49     const GrB_Vector v,             // second input: vector v
50     const GrB_Descriptor desc       // descriptor for w and M
51 )
52 {
53 
54     //--------------------------------------------------------------------------
55     // check inputs
56     //--------------------------------------------------------------------------
57 
58     GB_WHERE (w, "GrB_Vector_eWiseAdd_BinaryOp (w, M, accum, add, u, v, desc)");
59     GB_BURBLE_START ("GrB_eWiseAdd") ;
60     GB_RETURN_IF_NULL_OR_FAULTY (add) ;
61 
62     //--------------------------------------------------------------------------
63     // apply the eWise kernel (using set union)
64     //--------------------------------------------------------------------------
65 
66     GB_EWISE (add) ;
67     GB_BURBLE_END ;
68     return (info) ;
69 }
70 
71 //------------------------------------------------------------------------------
72 // GrB_Vector_eWiseAdd_Monoid: vector addition
73 //------------------------------------------------------------------------------
74 
GrB_Vector_eWiseAdd_Monoid(GrB_Vector w,const GrB_Vector M,const GrB_BinaryOp accum,const GrB_Monoid monoid,const GrB_Vector u,const GrB_Vector v,const GrB_Descriptor desc)75 GrB_Info GrB_Vector_eWiseAdd_Monoid         // w<M> = accum (w, u+v)
76 (
77     GrB_Vector w,                   // input/output vector for results
78     const GrB_Vector M,             // optional mask for w, unused if NULL
79     const GrB_BinaryOp accum,       // optional accum for z=accum(w,t)
80     const GrB_Monoid monoid,        // defines '+' for t=u+v
81     const GrB_Vector u,             // first input:  vector u
82     const GrB_Vector v,             // second input: vector v
83     const GrB_Descriptor desc       // descriptor for w and M
84 )
85 {
86 
87     //--------------------------------------------------------------------------
88     // check inputs
89     //--------------------------------------------------------------------------
90 
91     GB_WHERE (w, "GrB_Vector_eWiseAdd_Monoid "
92         "(w, M, accum, monoid, u, v, desc)") ;
93     GB_BURBLE_START ("GrB_eWiseAdd") ;
94     GB_RETURN_IF_NULL_OR_FAULTY (monoid) ;
95 
96     //--------------------------------------------------------------------------
97     // eWise add using the monoid operator
98     //--------------------------------------------------------------------------
99 
100     GB_EWISE (monoid->op) ;
101     GB_BURBLE_END ;
102     return (info) ;
103 }
104 
105 //------------------------------------------------------------------------------
106 // GrB_Vector_eWiseAdd_Semiring: vector addition
107 //------------------------------------------------------------------------------
108 
GrB_Vector_eWiseAdd_Semiring(GrB_Vector w,const GrB_Vector M,const GrB_BinaryOp accum,const GrB_Semiring semiring,const GrB_Vector u,const GrB_Vector v,const GrB_Descriptor desc)109 GrB_Info GrB_Vector_eWiseAdd_Semiring       // w<M> = accum (w, u+v)
110 (
111     GrB_Vector w,                   // input/output vector for results
112     const GrB_Vector M,             // optional mask for w, unused if NULL
113     const GrB_BinaryOp accum,       // optional accum for z=accum(w,t)
114     const GrB_Semiring semiring,    // defines '+' for t=u+v
115     const GrB_Vector u,             // first input:  vector u
116     const GrB_Vector v,             // second input: vector v
117     const GrB_Descriptor desc       // descriptor for w and M
118 )
119 {
120 
121     //--------------------------------------------------------------------------
122     // check inputs
123     //--------------------------------------------------------------------------
124 
125     GB_WHERE (w, "GrB_Vector_eWiseAdd_Semiring "
126         "(w, M, accum, semiring, u, v, desc)") ;
127     GB_BURBLE_START ("GrB_eWiseAdd") ;
128     GB_RETURN_IF_NULL_OR_FAULTY (semiring) ;
129 
130     //--------------------------------------------------------------------------
131     // eWise add using the semiring monoid operator
132     //--------------------------------------------------------------------------
133 
134     GB_EWISE (semiring->add->op) ;
135     GB_BURBLE_END ;
136     return (info) ;
137 }
138 
139