Description
We've discussed this before, but I think it deserves an issue. SuiteSparse:GraphBLAS added ewise-union, which allows a left-default and a right-default value to be given for a binary operator. We wrap this; for example, op.minus(A | B, left_default=0, right_default=0)
.
What if we allowed only one of left_default
or right_default
to be given to allow right-join and left-join behavior? For example, we could add recipes such as the following:
# if updater on left has mask
left(mask, ...) << binop(A | B, left_default=a)
->
left(mask, ...) << binop(A | B, left_default=a, right_default=False).new(mask=B.S)
and
# if updater on left *does not* have mask (ignore replace if given)
left(optional_accum) << binop(A | B, left_default=a)
->
left(optional_accum, mask=B.S) << binop(A | B, left_default=a, right_default=False)
and we could even investigate pushing the mask further up in the recipe to be more memory-efficient
# if updater on left has mask, but not replace
left(mask, optional_accum) << binop(A | B, left_default=a)
->
new_mask = unary.one(B).new(mask=mask)
left(new_mask.S, optional_accum) << binop(A | B, left_default=a, right_default=False)
Other recipes for performing these operations exist (and the above recipes may be flawed), and we'll need to handle vector broadcasting such as binop(A | v, left_default=a)
as well.
Note that #215 added a clean way to add recipes like this, so we can make the recipes perform action once they have the updater, and they can also have nice reprs.
Pro's:
- We can!
- Natural syntax
- We get to codify what we believe are the "best" recipes
- Some of these recipes are non-obvious, so it's helpful to not force users to implement their own solutions
dimsum
can use this directly instead of using its own recipes- If we find this is useful, we can argue for it to be added upstream
Con's:
- Added complication
- My recipes above rely on a SuiteSparse-specific
GxB
method, so supporting vanilla GraphBLAS will need other recipes- Unless ewise-union gets added to the spec ;)
- It's unclear how common this will be used in practice
My 🪙🪙 , I'm probably +1 for supporting this, but I also think it's low priority. CC @jim22k