1 //------------------------------------------------------------------------------
2 // GrB_Matrix_eWiseMult: matrix element-wise operations, using set intersection
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 // C<M> = accum (C,A.*B) and variations.
11 
12 #include "GB_ewise.h"
13 
14 #define GB_EWISE(op)                                                        \
15     /* check inputs */                                                      \
16     GB_RETURN_IF_NULL_OR_FAULTY (C) ;                                       \
17     GB_RETURN_IF_NULL_OR_FAULTY (A) ;                                       \
18     GB_RETURN_IF_NULL_OR_FAULTY (B) ;                                       \
19     GB_RETURN_IF_FAULTY (M) ;                                               \
20     /* get the descriptor */                                                \
21     GB_GET_DESCRIPTOR (info, desc, C_replace, Mask_comp, Mask_struct,       \
22         A_tran, B_tran, xx, xx7) ;                                          \
23     /* C<M> = accum (C,T) where T = A.*B, A'.*B, A.*B', or A'.*B' */        \
24     info = GB_ewise (                                                       \
25         C,              C_replace,  /* C and its descriptor        */       \
26         M, Mask_comp, Mask_struct,  /* mask and its descriptor     */       \
27         accum,                      /* accumulate operator         */       \
28         op,                         /* operator that defines '.*'  */       \
29         A,              A_tran,     /* A matrix and its descriptor */       \
30         B,              B_tran,     /* B matrix and its descriptor */       \
31         false,                      /* eWiseMult                   */       \
32         Context) ;
33 
34 //------------------------------------------------------------------------------
35 // GrB_Matrix_eWiseMult_BinaryOp: matrix element-wise multiplication
36 //------------------------------------------------------------------------------
37 
GrB_Matrix_eWiseMult_BinaryOp(GrB_Matrix C,const GrB_Matrix M,const GrB_BinaryOp accum,const GrB_BinaryOp mult,const GrB_Matrix A,const GrB_Matrix B,const GrB_Descriptor desc)38 GrB_Info GrB_Matrix_eWiseMult_BinaryOp       // C<M> = accum (C, A.*B)
39 (
40     GrB_Matrix C,                   // input/output matrix for results
41     const GrB_Matrix M,             // optional mask for C, unused if NULL
42     const GrB_BinaryOp accum,       // optional accum for Z=accum(C,T)
43     const GrB_BinaryOp mult,        // defines '.*' for T=A.*B
44     const GrB_Matrix A,             // first input:  matrix A
45     const GrB_Matrix B,             // second input: matrix B
46     const GrB_Descriptor desc       // descriptor for C, M, A, and B
47 )
48 {
49 
50     //--------------------------------------------------------------------------
51     // check inputs
52     //--------------------------------------------------------------------------
53 
54     GB_WHERE (C, "GrB_Matrix_eWiseMult_BinaryOp "
55         "(C, M, accum, mult, A, B, desc)") ;
56     GB_BURBLE_START ("GrB_eWiseMult") ;
57     GB_RETURN_IF_NULL_OR_FAULTY (mult) ;
58 
59     //--------------------------------------------------------------------------
60     // apply the eWise kernel (using set intersection)
61     //--------------------------------------------------------------------------
62 
63     GB_EWISE (mult) ;
64     GB_BURBLE_END ;
65     return (info) ;
66 }
67 
68 //------------------------------------------------------------------------------
69 // GrB_Matrix_eWiseMult_Monoid: matrix element-wise multiplication
70 //------------------------------------------------------------------------------
71 
72 // C<M> = accum (C,A.*B) and variations.
73 
GrB_Matrix_eWiseMult_Monoid(GrB_Matrix C,const GrB_Matrix M,const GrB_BinaryOp accum,const GrB_Monoid monoid,const GrB_Matrix A,const GrB_Matrix B,const GrB_Descriptor desc)74 GrB_Info GrB_Matrix_eWiseMult_Monoid         // C<M> = accum (C, A.*B)
75 (
76     GrB_Matrix C,                   // input/output matrix for results
77     const GrB_Matrix M,             // optional mask for C, unused if NULL
78     const GrB_BinaryOp accum,       // optional accum for Z=accum(C,T)
79     const GrB_Monoid monoid,        // defines '.*' for T=A.*B
80     const GrB_Matrix A,             // first input:  matrix A
81     const GrB_Matrix B,             // second input: matrix B
82     const GrB_Descriptor desc       // descriptor for C, M, A, and B
83 )
84 {
85 
86     //--------------------------------------------------------------------------
87     // check inputs
88     //--------------------------------------------------------------------------
89 
90     GB_WHERE (C, "GrB_Matrix_eWiseMult_Monoid "
91         "(C, M, accum, monoid, A, B, desc)") ;
92     GB_BURBLE_START ("GrB_eWiseMult") ;
93     GB_RETURN_IF_NULL_OR_FAULTY (monoid) ;
94 
95     //--------------------------------------------------------------------------
96     // eWise multiply using the monoid operator
97     //--------------------------------------------------------------------------
98 
99     GB_EWISE (monoid->op) ;
100     GB_BURBLE_END ;
101     return (info) ;
102 }
103 
104 //------------------------------------------------------------------------------
105 // GrB_Matrix_eWiseMult_Semiring: matrix element-wise multiplication
106 //------------------------------------------------------------------------------
107 
108 // C<M> = accum (C,A.*B) and variations.
109 
GrB_Matrix_eWiseMult_Semiring(GrB_Matrix C,const GrB_Matrix M,const GrB_BinaryOp accum,const GrB_Semiring semiring,const GrB_Matrix A,const GrB_Matrix B,const GrB_Descriptor desc)110 GrB_Info GrB_Matrix_eWiseMult_Semiring       // C<M> = accum (C, A.*B)
111 (
112     GrB_Matrix C,                   // input/output matrix for results
113     const GrB_Matrix M,             // optional mask for C, unused if NULL
114     const GrB_BinaryOp accum,       // optional accum for Z=accum(C,T)
115     const GrB_Semiring semiring,    // defines '.*' for T=A.*B
116     const GrB_Matrix A,             // first input:  matrix A
117     const GrB_Matrix B,             // second input: matrix B
118     const GrB_Descriptor desc       // descriptor for C, M, A, and B
119 )
120 {
121 
122     //--------------------------------------------------------------------------
123     // check inputs
124     //--------------------------------------------------------------------------
125 
126     GB_WHERE (C, "GrB_Matrix_eWiseMult_Semiring "
127         "(C, M, accum, semiring, A, B, 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