Skip to content

Implement torch.xlogy #22656

@colesbury

Description

@colesbury

🚀 Feature

Implement torch.xlogy which computes x * log(y) if x != 0 and 0 if x == 0.

Motivation

Often one wants to compute x * log(x) or x * 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    function requestA 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 module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions