@@ -11,7 +11,7 @@ union equivalent see [`eadd!`](@ref).
11
11
# Arguments
12
12
- `C::GBArray`: the output vector or matrix.
13
13
- `A, B::GBArray`: A GBVector or GBMatrix, possibly transposed.
14
- - `op::Union{Function, AbstractBinaryOp, Monoid} = *`: the binary operation which is
14
+ - `op::Union{Function, AbstractBinaryOp, Monoid} = *`: the binary operation which is
15
15
applied such that `C[i,j] = op(A[i,j], B[i,j])` for all `i,j` present in both `A` and `B`.
16
16
17
17
# Keywords
53
53
"""
54
54
emul(A::GBArray, B::GBArray, op = *; kwargs...)::GBMatrix
55
55
56
- Apply the binary operator `op` elementwise on the set intersection of `A` and `B`.
56
+ Apply the binary operator `op` elementwise on the set intersection of `A` and `B`.
57
57
When `op = *` this is equivalent to `A .* B`, however any binary operator may be substituted.
58
58
59
59
The pattern of the result is the set intersection of `A` and `B`. For a set
60
60
union equivalent see [`eadd`](@ref).
61
61
62
62
# Arguments
63
63
- `A, B::GBArray`: A GBVector or GBMatrix, possibly transposed.
64
- - `op::Union{Function, AbstractBinaryOp, Monoid} = *`: the binary operation which is
64
+ - `op::Union{Function, AbstractBinaryOp, Monoid} = *`: the binary operation which is
65
65
applied such that `C[i,j] = op(A[i,j], B[i,j])` for all `i,j` present in both `A` and `B`.
66
66
67
67
# Keywords
@@ -107,7 +107,7 @@ For a set intersection equivalent see [`emul!`](@ref).
107
107
# Arguments
108
108
- `C::GBArray`: the output vector or matrix.
109
109
- `A, B::GBArray`: A GBVector or GBMatrix, possibly transposed.
110
- - `op::Union{Function, AbstractBinaryOp, Monoid} = +`: the binary operation which is
110
+ - `op::Union{Function, AbstractBinaryOp, Monoid} = +`: the binary operation which is
111
111
applied such that `C[i,j] = op(A[i,j], B[i,j])` for all `i,j` present in either `A` and `B`.
112
112
113
113
# Keywords
148
148
"""
149
149
eadd(A::GBArray, B::GBArray, op = +; kwargs...)::GBVecOrMat
150
150
151
- Apply the binary operator `op` elementwise on the set union of `A` and `B`.
151
+ Apply the binary operator `op` elementwise on the set union of `A` and `B`.
152
152
When `op = +` this is equivalent to `A .+ B`, however any binary operation may be substituted.
153
153
154
154
Note that the behavior of `A[i,j] op B[i,j]` may be unintuitive when one operand is an implicit
@@ -159,7 +159,7 @@ For a set intersection equivalent see [`emul`](@ref).
159
159
160
160
# Arguments
161
161
- `A, B::GBArray`: A GBVector or GBMatrix, possibly transposed.
162
- - `op::Union{Function, AbstractBinaryOp, Monoid} = +`: the binary operation which is
162
+ - `op::Union{Function, AbstractBinaryOp, Monoid} = +`: the binary operation which is
163
163
applied such that `C[i,j] = op(A[i,j], B[i,j])` for all `i,j` present in either `A` and `B`.
164
164
165
165
# Keywords
@@ -185,6 +185,96 @@ function eadd(
185
185
return eadd! (C, A, B, op; mask, accum, desc)
186
186
end
187
187
188
+
189
+ """
190
+ eunion!(C::GBVecOrMat, A::GBArray{T}, α::T B::GBArray, β::T, op = +; kwargs...)::GBVecOrMat
191
+
192
+ Apply the binary operator `op` elementwise on the set union of `A` and `B`. Store or
193
+ accumulate the result into C. When `op = +` this is equivalent to `A .+ B`,
194
+ however any binary operation may be substituted.
195
+
196
+ Unlike `eadd!` where an argument missing in `A` causes the `B` element to "pass-through",
197
+ `eunion!` utilizes the `α` and `β` arguments for the missing operand elements.
198
+
199
+ # Arguments
200
+ - `C::GBArray`: the output vector or matrix.
201
+ - `A, B::GBArray`: A GBVector or GBMatrix, possibly transposed.
202
+ - `α, β`: The fill-in value for `A` and `B` respectively.
203
+ - `op::Union{Function, AbstractBinaryOp, Monoid} = +`: the binary operation which is
204
+ applied such that `C[i,j] = op(A[i,j], B[i,j])` for all `i,j` present in either `A` and `B`.
205
+
206
+ # Keywords
207
+ - `mask::Union{Nothing, GBVecOrMat} = nothing`: optional mask.
208
+ - `accum::Union{Nothing, Function, AbstractBinaryOp} = nothing`: binary accumulator operation
209
+ such that `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
210
+ - `desc::Union{Nothing, Descriptor} = nothing`
211
+ """
212
+ function eunion! (
213
+ C:: GBVecOrMat ,
214
+ A:: GBArray{T} ,
215
+ α:: T ,
216
+ B:: GBArray{U} ,
217
+ β:: U ,
218
+ op:: MonoidBinaryOrRig = BinaryOps. PLUS;
219
+ mask = nothing ,
220
+ accum = nothing ,
221
+ desc = nothing
222
+ ) where {T, U}
223
+ mask, accum = _handlenothings (mask, accum)
224
+ desc = _handledescriptor (desc; in1= A, in2 = B)
225
+ size (C) == size (A) == size (B) || throw (DimensionMismatch ())
226
+ op = getoperator (op, optype (A, B))
227
+ accum = getaccum (accum, eltype (C))
228
+ if op isa TypedBinaryOperator
229
+ libgb. GxB_Matrix_eWiseUnion (C, mask, accum, op, parent (A), GBScalar (α), parent (B), GBScalar (β), desc)
230
+ return C
231
+ else
232
+ throw (ArgumentError (" $op is not a valid monoid binary op or semiring." ))
233
+ end
234
+ return C
235
+ end
236
+
237
+ """
238
+ eunion(C::GBVecOrMat, A::GBArray{T}, α::T B::GBArray, β::T, op = +; kwargs...)::GBVecOrMat
239
+
240
+ Apply the binary operator `op` elementwise on the set union of `A` and `B`.
241
+ When `op = +` this is equivalent to `A .+ B`, however any binary operation may be substituted.
242
+
243
+ Unlike `eadd!` where an argument missing in `A` causes the `B` element to "pass-through",
244
+ `eunion!` utilizes the `α` and `β` arguments for the missing operand elements.
245
+
246
+ # Arguments
247
+ - `A, B::GBArray`: A GBVector or GBMatrix, possibly transposed.
248
+ - `α, β`: The fill-in value for `A` and `B` respectively.
249
+ - `op::Union{Function, AbstractBinaryOp, Monoid} = +`: the binary operation which is
250
+ applied such that `C[i,j] = op(A[i,j], B[i,j])` for all `i,j` present in either `A` and `B`.
251
+
252
+ # Keywords
253
+ - `mask::Union{Nothing, GBVecOrMat} = nothing`: optional mask.
254
+ - `accum::Union{Nothing, Function, AbstractBinaryOp} = nothing`: binary accumulator operation
255
+ such that `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
256
+ - `desc::Union{Nothing, Descriptor} = nothing`
257
+ """
258
+ function eunion (
259
+ A:: GBArray{T} ,
260
+ α:: T ,
261
+ B:: GBArray{U} ,
262
+ β:: U ,
263
+ op:: MonoidBinaryOrRig = BinaryOps. PLUS;
264
+ mask = nothing ,
265
+ accum = nothing ,
266
+ desc = nothing
267
+ ) where {T, U}
268
+ t = inferoutputtype (A, B, op)
269
+ if A isa GBVector && B isa GBVector
270
+ C = GBVector {t} (size (A))
271
+ else
272
+ C = GBMatrix {t} (size (A))
273
+ end
274
+ return eunion! (C, A, α, B, β, op; mask, accum, desc)
275
+ end
276
+
277
+
188
278
function emul! (C, A, B, op:: Function ; mask = nothing , accum = nothing , desc = nothing )
189
279
emul! (C, A, B, BinaryOp (op); mask, accum, desc)
190
280
end
@@ -201,12 +291,20 @@ function eadd(A, B, op::Function; mask = nothing, accum = nothing, desc = nothin
201
291
eadd (A, B, BinaryOp (op); mask, accum, desc)
202
292
end
203
293
294
+ function eunion! (C, A, α, B, β, op:: Function ; mask = nothing , accum = nothing , desc = nothing )
295
+ eunion! (C, A, α, B, β, BinaryOp (op); mask, accum, desc)
296
+ end
297
+
298
+ function eunion (A, α, B, β, op:: Function ; mask = nothing , accum = nothing , desc = nothing )
299
+ eunion (A, α, B, β, BinaryOp (op); mask, accum, desc)
300
+ end
301
+
204
302
function Base.:+ (A:: GBArray , B:: GBArray )
205
- eadd (A, B, BinaryOps . PLUS )
303
+ eadd (A, B, + )
206
304
end
207
305
208
306
function Base.:- (A:: GBArray , B:: GBArray )
209
- eadd (A, B, BinaryOps . MINUS )
307
+ eadd (A, B, - )
210
308
end
211
309
212
310
⊕ (A, B, op; mask = nothing , accum = nothing , desc = nothing ) =
0 commit comments