Hi,
I’ve been using DGL for a while and I am developing some models that require custom message/reduce functions.
While the current set of supported built-in base message functions https://docs.dgl.ai/api/python/function.html can be used to compose a wide range of functions, it is missing some common comparison ops such as eq (equal),gt (greater than).
Is there any plan for supporting comparison operations?
Thanks for your suggestions.
I think what do you mean is something like u_leq_v
, u_eq_e
, … right?
Yes, exactly. It would be an elementwise comparison and the result would be a Boolean tensor.
Interesting, of course we can support such operators. However, the performance of these builtin operations would be similar to user defined functions. For example, for u_eq_v
we can only provide a builtin function with similar performance to the following function:
def u_eq_v(src_field, dst_field, out_field):
def func(edges):
return {out_field: edges.src[src_field] == edges.dst[dst_field]}
return func
That’s because we can not fuse the operator with a reduce function such as sum
/mean
/etc (they are meaning less in the context of boolean algebra).
If you think the performance is not an issue, we would provide these operators. Besides, may I ask you about the potential use cases of these ops?
BTW, @minjie has a good suggestion:
for g.apply_edges(fn.u_geq_v('x', 'y', 'm'))
, you can implement this by:
g.apply_edges(fn.u_sub_v('x', 'y', 'x-y'))
g.edata['m'] = g.edata.pop('x-y') >= 0
Thanks for the suggestion. I’ve been implementing this with a custom apply function. The purpose is to implement conditional propagation in GNN, for example, only propagate between nodes that belong to the same partition.