1 //------------------------------------------------------------------------------
2 // GrB_Vector_eWiseMult: vector element-wise multiplication
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 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         false,                      /* eWiseMult                   */       \
36         Context) ;
37 
38 //------------------------------------------------------------------------------
39 // GrB_Vector_eWiseMult_BinaryOp: vector element-wise multiplication
40 //------------------------------------------------------------------------------
41 
GrB_Vector_eWiseMult_BinaryOp(GrB_Vector w,const GrB_Vector M,const GrB_BinaryOp accum,const GrB_BinaryOp mult,const GrB_Vector u,const GrB_Vector v,const GrB_Descriptor desc)42 GrB_Info GrB_Vector_eWiseMult_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 mult,        // 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_eWiseMult_BinaryOp "
59         "(w, M, accum, mult, u, v, desc)") ;
60     GB_BURBLE_START ("GrB_eWiseMult") ;
61     GB_RETURN_IF_NULL_OR_FAULTY (mult) ;
62 
63     //--------------------------------------------------------------------------
64     // apply the eWise kernel (using set intersection)
65     //--------------------------------------------------------------------------
66 
67     GB_EWISE (mult) ;
68     GB_BURBLE_END ;
69     return (info) ;
70 }
71 
72 //------------------------------------------------------------------------------
73 // GrB_Vector_eWiseMult_Monoid: vector element-wise multiplication
74 //------------------------------------------------------------------------------
75 
GrB_Vector_eWiseMult_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)76 GrB_Info GrB_Vector_eWiseMult_Monoid         // w<M> = accum (w, u.*v)
77 (
78     GrB_Vector w,                   // input/output vector for results
79     const GrB_Vector M,             // optional mask for w, unused if NULL
80     const GrB_BinaryOp accum,       // optional accum for z=accum(w,t)
81     const GrB_Monoid monoid,        // defines '.*' for t=u.*v
82     const GrB_Vector u,             // first input:  vector u
83     const GrB_Vector v,             // second input: vector v
84     const GrB_Descriptor desc       // descriptor for w and M
85 )
86 {
87 
88     //--------------------------------------------------------------------------
89     // check inputs
90     //--------------------------------------------------------------------------
91 
92     GB_WHERE (w, "GrB_Vector_eWiseMult_Monoid "
93         "(w, M, accum, monoid, u, v, desc)") ;
94     GB_BURBLE_START ("GrB_eWiseMult") ;
95     GB_RETURN_IF_NULL_OR_FAULTY (monoid) ;
96 
97     //--------------------------------------------------------------------------
98     // eWise multiply using the monoid operator
99     //--------------------------------------------------------------------------
100 
101     GB_EWISE (monoid->op) ;
102     GB_BURBLE_END ;
103     return (info) ;
104 }
105 
106 //------------------------------------------------------------------------------
107 // GrB_Vector_eWiseMult_Semiring: vector element-wise multiplication
108 //------------------------------------------------------------------------------
109 
GrB_Vector_eWiseMult_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)110 GrB_Info GrB_Vector_eWiseMult_Semiring       // w<M> = accum (w, u.*v)
111 (
112     GrB_Vector w,                   // input/output vector for results
113     const GrB_Vector M,             // optional mask for w, unused if NULL
114     const GrB_BinaryOp accum,       // optional accum for z=accum(w,t)
115     const GrB_Semiring semiring,    // defines '.*' for t=u.*v
116     const GrB_Vector u,             // first input:  vector u
117     const GrB_Vector v,             // second input: vector v
118     const GrB_Descriptor desc       // descriptor for w and M
119 )
120 {
121 
122     //--------------------------------------------------------------------------
123     // check inputs
124     //--------------------------------------------------------------------------
125 
126     GB_WHERE (w, "GrB_Vector_eWiseMult_Semiring "
127         "(w, M, accum, semiring, u, v, desc)") ;
128     GB_BURBLE_START ("GrB_eWiseMult") ;
129     GB_RETURN_IF_NULL_OR_FAULTY (semiring) ;
130 
131     //--------------------------------------------------------------------------
132     // eWise multiply using the semiring multiply operator
133     //--------------------------------------------------------------------------
134 
135     GB_EWISE (semiring->multiply) ;
136     GB_BURBLE_END ;
137     return (info) ;
138 }
139 
140