1 //------------------------------------------------------------------------------
2 // GrB_Matrix_eWiseAdd: matrix 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 // 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         true,                       /* eWiseAdd                    */       \
32         Context) ;
33 
34 //------------------------------------------------------------------------------
35 // GrB_Matrix_eWiseAdd_BinaryOp: matrix addition
36 //------------------------------------------------------------------------------
37 
GrB_Matrix_eWiseAdd_BinaryOp(GrB_Matrix C,const GrB_Matrix M,const GrB_BinaryOp accum,const GrB_BinaryOp add,const GrB_Matrix A,const GrB_Matrix B,const GrB_Descriptor desc)38 GrB_Info GrB_Matrix_eWiseAdd_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 add,         // 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_eWiseAdd_BinaryOp (C, M, accum, add, A, B, desc)");
55     GB_BURBLE_START ("GrB_eWiseAdd") ;
56     GB_RETURN_IF_NULL_OR_FAULTY (add) ;
57 
58     //--------------------------------------------------------------------------
59     // apply the eWise kernel (using set union)
60     //--------------------------------------------------------------------------
61 
62     GB_EWISE (add) ;
63     GB_BURBLE_END ;
64     return (info) ;
65 }
66 
67 //------------------------------------------------------------------------------
68 // GrB_Matrix_eWiseAdd_Monoid: matrix addition
69 //------------------------------------------------------------------------------
70 
71 // C<M> = accum (C,A+B) and variations.
72 
GrB_Matrix_eWiseAdd_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)73 GrB_Info GrB_Matrix_eWiseAdd_Monoid         // C<M> = accum (C, A+B)
74 (
75     GrB_Matrix C,                   // input/output matrix for results
76     const GrB_Matrix M,             // optional mask for C, unused if NULL
77     const GrB_BinaryOp accum,       // optional accum for Z=accum(C,T)
78     const GrB_Monoid monoid,        // defines '+' for T=A+B
79     const GrB_Matrix A,             // first input:  matrix A
80     const GrB_Matrix B,             // second input: matrix B
81     const GrB_Descriptor desc       // descriptor for C, M, A, and B
82 )
83 {
84 
85     //--------------------------------------------------------------------------
86     // check inputs
87     //--------------------------------------------------------------------------
88 
89     GB_WHERE (C, "GrB_Matrix_eWiseAdd_Monoid "
90         "(C, M, accum, monoid, A, B, desc)") ;
91     GB_BURBLE_START ("GrB_eWiseAdd") ;
92     GB_RETURN_IF_NULL_OR_FAULTY (monoid) ;
93 
94     //--------------------------------------------------------------------------
95     // eWiseAdd using the monoid operator
96     //--------------------------------------------------------------------------
97 
98     GB_EWISE (monoid->op) ;
99     GB_BURBLE_END ;
100     return (info) ;
101 }
102 
103 //------------------------------------------------------------------------------
104 // GrB_Matrix_eWiseAdd_Semiring: matrix addition
105 //------------------------------------------------------------------------------
106 
107 // C<M> = accum (C,A+B) and variations.
108 
GrB_Matrix_eWiseAdd_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)109 GrB_Info GrB_Matrix_eWiseAdd_Semiring       // C<M> = accum (C, A+B)
110 (
111     GrB_Matrix C,                   // input/output matrix for results
112     const GrB_Matrix M,             // optional mask for C, unused if NULL
113     const GrB_BinaryOp accum,       // optional accum for Z=accum(C,T)
114     const GrB_Semiring semiring,    // defines '+' for T=A+B
115     const GrB_Matrix A,             // first input:  matrix A
116     const GrB_Matrix B,             // second input: matrix B
117     const GrB_Descriptor desc       // descriptor for C, M, A, and B
118 )
119 {
120 
121     //--------------------------------------------------------------------------
122     // check inputs
123     //--------------------------------------------------------------------------
124 
125     GB_WHERE (C, "GrB_Matrix_eWiseAdd_Semiring (C, M, accum, semiring, A, B,"
126         " 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