Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Accepting python scalar inputs for torch.minimum/torch.maximum and friends #69524

Open
vadimkantorov opened this issue Dec 7, 2021 · 2 comments
Labels
module: distance functions triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@vadimkantorov
Copy link
Contributor

vadimkantorov commented Dec 7, 2021

It will simplify the user code and will allow to use some placeholder default values like float('inf') (btw torch.minimum could be nop in this case).

>>> torch.rand(3, 4).mul(5.0)
# works

>>> torch.rand(3, 4).minimum(5.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: minimum(): argument 'other' (position 1) must be Tensor, not float

>>> torch.rand(3, 4).minimum(torch.tensor(5.0))
# works
@vadimkantorov vadimkantorov changed the title [feature request] Accepting scalar inputs for torch.minimum and friends [feature request] Accepting python scalar inputs for torch.minimum and friends Dec 7, 2021
@zou3519 zou3519 added module: distance functions triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Dec 7, 2021
@zou3519
Copy link
Contributor

zou3519 commented Dec 7, 2021

Seems reasonable to have

@vadimkantorov vadimkantorov changed the title [feature request] Accepting python scalar inputs for torch.minimum and friends [feature request] Accepting python scalar inputs for torch.minimum/torch.maximum and friends Dec 10, 2021
@vadimkantorov
Copy link
Contributor Author

It seems that torch.clamp now supports both scalar and vector min/max arguments and supports broadcasting. I'm not sure if it supports differentiating through min/max arguments.

Could torch.maximum / torch.minimum just redirect to torch.clamp? (and maybe all of them should support differentiation through min/max although that could be forward compat breaking)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: distance functions triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants