Output 0 instead of nan when dividing by 0

Hi all,

tl;dr Is there a way to get 0 when dividing by 0 in Gluon F.broadcast_div() instead of nan or inf?

I’m attempting to rewrite the Tensorflow seq2seq sequence_loss function for Gluon. The source is at addons/loss.py at v0.13.0 · tensorflow/addons · GitHub. Line 160 has the following:

crossent = tf.math.divide_no_nan(crossent, total_size)

which outputs 0 when dividing by 0. On the other hand, Gluon’s F.broadcast_div() will output something like nan or inf. Does anyone have any suggestions for mimicking this behavior in Gluon?

Thanks!