@@ -19,7 +19,7 @@ union equivalent see [`eadd!`](@ref).
19
19
- `mask::Union{Ptr{Nothing}, GBMatrix} = C_NULL`: optional mask.
20
20
- `accum::Union{Ptr{Nothing}, AbstractBinaryOp} = C_NULL`: binary accumulator operation
21
21
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
22
- - `desc::Descriptor = Descriptors.NULL `
22
+ - `desc = nothing `
23
23
"""
24
24
function emul! end
25
25
@@ -43,7 +43,7 @@ union equivalent see [`eadd`](@ref).
43
43
- `mask::Union{Ptr{Nothing}, GBMatrix} = C_NULL`: optional mask.
44
44
- `accum::Union{Ptr{Nothing}, AbstractBinaryOp} = C_NULL`: binary accumulator operation
45
45
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
46
- - `desc::Descriptor = Descriptors.NULL `
46
+ - `desc = nothing `
47
47
48
48
# Returns
49
49
- `GBArray`: Output `GBVector` or `GBMatrix` whose eltype is determined by the `eltype` of
@@ -55,11 +55,13 @@ function emul!(
55
55
w:: GBVector ,
56
56
u:: GBVector ,
57
57
v:: GBVector ,
58
- op:: MonoidBinaryOrRig = BinaryOps . TIMES ;
59
- mask = C_NULL ,
60
- accum = C_NULL ,
61
- desc:: Descriptor = Descriptors . NULL
58
+ op = nothing ;
59
+ mask = nothing ,
60
+ accum = nothing ,
61
+ desc = nothing
62
62
)
63
+ op, mask, accum, desc = _handlectx (op, mask, accum, desc, BinaryOps. TIMES)
64
+
63
65
size (w) == size (u) == size (v) || throw (DimensionMismatch ())
64
66
op = getoperator (op, optype (u, v))
65
67
accum = getoperator (accum, eltype (w))
@@ -72,17 +74,20 @@ function emul!(
72
74
elseif op isa libgb. GrB_BinaryOp
73
75
libgb. GrB_Vector_eWiseMult_BinaryOp (w, mask, accum, op, u, v, desc)
74
76
return w
77
+ else
78
+ throw (ArgumentError (" $op is not a valid monoid binary op or semiring." ))
75
79
end
76
80
end
77
81
78
82
function emul (
79
83
u:: GBVector ,
80
84
v:: GBVector ,
81
- op:: MonoidBinaryOrRig = BinaryOps . TIMES ;
82
- mask = C_NULL ,
83
- accum = C_NULL ,
84
- desc:: Descriptor = Descriptors . NULL
85
+ op = nothing ;
86
+ mask = nothing ,
87
+ accum = nothing ,
88
+ desc = nothing
85
89
)
90
+ op = _handlectx (op, ctxop, BinaryOps. TIMES)
86
91
if op isa GrBOp
87
92
t = ztype (op)
88
93
else
@@ -96,11 +101,12 @@ function emul!(
96
101
C:: GBMatrix ,
97
102
A:: GBMatOrTranspose ,
98
103
B:: GBMatOrTranspose ,
99
- op:: MonoidBinaryOrRig = BinaryOps . TIMES ;
100
- mask = C_NULL ,
101
- accum = C_NULL ,
102
- desc:: Descriptor = Descriptors . NULL
104
+ op = nothing ;
105
+ mask = nothing ,
106
+ accum = nothing ,
107
+ desc = nothing
103
108
)
109
+ op, mask, accum, desc = _handlectx (op, mask, accum, desc, BinaryOps. TIMES)
104
110
size (C) == size (A) == size (B) || throw (DimensionMismatch ())
105
111
A, desc, B = _handletranspose (A, desc, B)
106
112
op = getoperator (op, optype (A, B))
@@ -114,17 +120,20 @@ function emul!(
114
120
elseif op isa libgb. GrB_BinaryOp
115
121
libgb. GrB_Matrix_eWiseMult_BinaryOp (C, mask, accum, op, A, B, desc)
116
122
return C
123
+ else
124
+ throw (ArgumentError (" $op is not a valid monoid binary op or semiring." ))
117
125
end
118
126
end
119
127
120
128
function emul (
121
129
A:: GBMatOrTranspose ,
122
130
B:: GBMatOrTranspose ,
123
- op:: MonoidBinaryOrRig = BinaryOps . TIMES ;
124
- mask = C_NULL ,
125
- accum = C_NULL ,
126
- desc:: Descriptor = Descriptors . NULL
131
+ op = nothing ;
132
+ mask = nothing ,
133
+ accum = nothing ,
134
+ desc = nothing
127
135
)
136
+ op = _handlectx (op, ctxop, BinaryOps. TIMES)
128
137
if op isa GrBOp
129
138
t = ztype (op)
130
139
else
@@ -155,7 +164,7 @@ intersection equivalent see [`eadd!`](@ref).
155
164
- `mask::Union{Ptr{Nothing}, GBMatrix} = C_NULL`: optional mask.
156
165
- `accum::Union{Ptr{Nothing}, AbstractBinaryOp} = C_NULL`: binary accumulator operation
157
166
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
158
- - `desc::Descriptor = Descriptors.NULL `
167
+ - `desc = nothing `
159
168
"""
160
169
function eadd! end
161
170
@@ -179,7 +188,7 @@ intersection equivalent see [`emul`](@ref).
179
188
- `mask::Union{Ptr{Nothing}, GBMatrix} = C_NULL`: optional mask.
180
189
- `accum::Union{Ptr{Nothing}, AbstractBinaryOp} = C_NULL`: binary accumulator operation
181
190
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
182
- - `desc::Descriptor = Descriptors.NULL `
191
+ - `desc = nothing `
183
192
184
193
# Returns
185
194
- `GBArray`: Output `GBVector` or `GBMatrix` whose eltype is determined by the `eltype` of
@@ -191,11 +200,12 @@ function eadd!(
191
200
w:: GBVector ,
192
201
u:: GBVector ,
193
202
v:: GBVector ,
194
- op:: MonoidBinaryOrRig = BinaryOps . PLUS ;
195
- mask = C_NULL ,
196
- accum = C_NULL ,
197
- desc:: Descriptor = Descriptors . NULL
203
+ op = nothing ;
204
+ mask = nothing ,
205
+ accum = nothing ,
206
+ desc = nothing
198
207
)
208
+ op, mask, accum, desc = _handlectx (op, mask, accum, desc, BinaryOps. PLUS)
199
209
size (w) == size (u) == size (v) || throw (DimensionMismatch ())
200
210
op = getoperator (op, optype (u, v))
201
211
accum = getoperator (accum, eltype (w))
@@ -208,17 +218,20 @@ function eadd!(
208
218
elseif op isa libgb. GrB_BinaryOp
209
219
libgb. GrB_Vector_eWiseAdd_BinaryOp (w, mask, accum, op, u, v, desc)
210
220
return w
221
+ else
222
+ throw (ArgumentError (" $op is not a valid monoid binary op or semiring." ))
211
223
end
212
224
end
213
225
214
226
function eadd (
215
227
u:: GBVector ,
216
228
v:: GBVector ,
217
- op:: MonoidBinaryOrRig = BinaryOps . PLUS ;
218
- mask = C_NULL ,
219
- accum = C_NULL ,
220
- desc:: Descriptor = Descriptors . NULL
229
+ op = nothing ;
230
+ mask = nothing ,
231
+ accum = nothing ,
232
+ desc = nothing
221
233
)
234
+ op, mask, accum, desc = _handlectx (op, mask, accum, desc, BinaryOps. PLUS)
222
235
if op isa GrBOp
223
236
t = ztype (op)
224
237
else
@@ -232,11 +245,12 @@ function eadd!(
232
245
C:: GBMatrix ,
233
246
A:: GBMatOrTranspose ,
234
247
B:: GBMatOrTranspose ,
235
- op:: MonoidBinaryOrRig = BinaryOps . PLUS ;
236
- mask = C_NULL ,
237
- accum = C_NULL ,
238
- desc:: Descriptor = Descriptors . NULL
248
+ op = nothing ;
249
+ mask = nothing ,
250
+ accum = nothing ,
251
+ desc = nothing
239
252
)
253
+ op, mask, accum, desc = _handlectx (op, mask, accum, desc, BinaryOps. PLUS)
240
254
size (C) == size (A) == size (B) || throw (DimensionMismatch ())
241
255
A, desc, B = _handletranspose (A, desc, B)
242
256
op = getoperator (op, optype (A, B))
@@ -251,18 +265,19 @@ function eadd!(
251
265
libgb. GrB_Matrix_eWiseAdd_BinaryOp (C, mask, accum, op, A, B, desc)
252
266
return C
253
267
else
254
- error ( " Unreachable " )
268
+ throw ( ArgumentError ( " $op is not a valid monoid binary op or semiring. " ) )
255
269
end
256
270
end
257
271
258
272
function eadd (
259
273
A:: GBMatOrTranspose ,
260
274
B:: GBMatOrTranspose ,
261
- op:: MonoidBinaryOrRig = BinaryOps . PLUS ;
262
- mask = C_NULL ,
263
- accum = C_NULL ,
264
- desc:: Descriptor = Descriptors . NULL
275
+ op = nothing ;
276
+ mask = nothing ,
277
+ accum = nothing ,
278
+ desc = nothing
265
279
)
280
+ op, mask, accum, desc = _handlectx (op, mask, accum, desc, BinaryOps. PLUS)
266
281
if op isa GrBOp
267
282
t = ztype (op)
268
283
else
@@ -271,57 +286,3 @@ function eadd(
271
286
C = GBMatrix {t} (size (A))
272
287
return eadd! (C, A, B, op; mask, accum, desc)
273
288
end
274
-
275
- # Note well: `.*` and `.+` have clear counterparts in the language of GraphBLAS:
276
- # edgewiseAdd and edgewiseMul. These do not necessarily have the same semantics though.
277
- # edgewiseAdd and edgewiseMul might better be described as edgewiseUnion and
278
- # edgewiseIntersection respectively, and then `op` is applied at materialized indices.
279
- #
280
- # So the plan is thus: `.*` and `.+` will have the Union and Intersection semantics *with*
281
- # the default ops of `*` and `+` respectively. *However*, they have `op` kwargs, which
282
- # may be used with a macro later on down the line to override the default ops.
283
- function Base. broadcasted (
284
- :: typeof (+ ),
285
- u:: GBVector ,
286
- v:: GBVector ,
287
- op:: MonoidBinaryOrRig = BinaryOps. PLUS;
288
- mask = C_NULL ,
289
- accum = C_NULL ,
290
- desc:: Descriptor = Descriptors. NULL
291
- )
292
- return eadd (u, v, op; mask, accum, desc)
293
- end
294
- function Base. broadcasted (
295
- :: typeof (* ),
296
- u:: GBVector ,
297
- v:: GBVector ,
298
- op:: MonoidBinaryOrRig = BinaryOps. TIMES;
299
- mask = C_NULL ,
300
- accum = C_NULL ,
301
- desc:: Descriptor = Descriptors. NULL
302
- )
303
- return emul (u, v, op; mask, accum, desc)
304
- end
305
-
306
- function Base. broadcasted (
307
- :: typeof (+ ),
308
- A:: GBMatOrTranspose ,
309
- B:: GBMatOrTranspose ,
310
- op:: MonoidBinaryOrRig = BinaryOps. PLUS;
311
- mask = C_NULL ,
312
- accum = C_NULL ,
313
- desc:: Descriptor = Descriptors. NULL
314
- )
315
- return eadd (A, B, op; mask, accum, desc)
316
- end
317
- function Base. broadcasted (
318
- :: typeof (* ),
319
- A:: GBMatOrTranspose ,
320
- B:: GBMatOrTranspose ,
321
- op:: MonoidBinaryOrRig = BinaryOps. PLUS;
322
- mask = C_NULL ,
323
- accum = C_NULL ,
324
- desc:: Descriptor = Descriptors. NULL
325
- )
326
- return emul (A, B, op; mask, accum, desc)
327
- end
0 commit comments