-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Implement torch.xlogy #22656
Copy link
Copy link
Closed
Labels
function requestA request for a new function or the addition of new arguments/modes to an existing function.A request for a new function or the addition of new arguments/modes to an existing function.triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
Metadata
Metadata
Assignees
Labels
function requestA request for a new function or the addition of new arguments/modes to an existing function.A request for a new function or the addition of new arguments/modes to an existing function.triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
🚀 Feature
Implement
torch.xlogywhich computesx * log(y)ifx != 0and 0 ifx == 0.Motivation
Often one wants to compute
x * log(x)orx * log(y)but define the result to be zero if x is 0 (instead of NaN). The current alternatives is to use torch.where to mask out NaN values or to add a small epsilon to x, like we do in binary cross entropy loss.Additional context
This is implemented in both SciPy and TensorFlow:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.xlogy.html
https://www.tensorflow.org/api_docs/python/tf/math/xlogy
cc @IssamLaradji