Dgl.function: Using parameter to define the feature name of udf

def udf_max(nodes):
   return {'h_max' : th.max(nodes.mailbox['m'], 1)[0]}

The above is a user-defined function from documents. How can i use a parameter to defined the feature name h_max, like fn.max(‘m’, ‘h_max’).

You can do something as follows.

def udf_max(msg_name='m', out_name='h_max'):
    def func(nodes):
        return {out_name : th.max(nodes.mailbox[msg_name], 1)[0]}
    return func
1 Like

Thanks a lot, it works. It seems there is a little mistake. The return of udf_max should be func.

You are right. I’ve fixed that.