Skip to content

Add torch.promote_types function#26655

Closed
nairbv wants to merge 7 commits intogh/nairbv/3/basefrom
gh/nairbv/3/head
Closed

Add torch.promote_types function#26655
nairbv wants to merge 7 commits intogh/nairbv/3/basefrom
gh/nairbv/3/head

Conversation

@nairbv
Copy link
Copy Markdown
Collaborator

@nairbv nairbv commented Sep 23, 2019

Stack from ghstack:

Differential Revision: D17556196

@pytorchbot pytorchbot added module: docs Related to our documentation, both in docs/ and docblocks module: internals Related to internal abstractions in c10 and ATen module: operators module: pybind Related to our Python bindings / interactions with other Python libraries labels Sep 23, 2019
nairbv added a commit that referenced this pull request Sep 23, 2019
ghstack-source-id: 7fc9e80
Pull Request resolved: #26655
nairbv added a commit that referenced this pull request Sep 23, 2019
ghstack-source-id: 18e1d58
Pull Request resolved: #26655
@nairbv nairbv requested a review from gchanan September 23, 2019 22:21
Comment thread torch/_torch_docs.py Outdated
promote_types(type1, type2) -> dtype

Returns the :class:`torch.dtype` with the smallest size and scalar kind to which
`type1` and `type2` may be safely cast. See type promotion :ref:`documentation <type-promotion-doc>`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"safely cast" isn't really defined here and I would argue are casting rules aren't really safe (i.e. int32 + float32) -> float32 can lose precision. Can you reword this somehow?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to a more specific explanation.

nairbv added a commit that referenced this pull request Sep 24, 2019
ghstack-source-id: 60c0fba
Pull Request resolved: #26655
@nairbv nairbv added this to the 1.3 milestone Sep 24, 2019
Comment thread torch/_torch_docs.py Outdated
nairbv added a commit that referenced this pull request Sep 25, 2019
ghstack-source-id: 8f0505c
Pull Request resolved: #26655
nairbv added a commit that referenced this pull request Sep 26, 2019
ghstack-source-id: de9e39d
Pull Request resolved: #26655
zdevito pushed a commit to zdevito/ATen that referenced this pull request Sep 28, 2019
Summary: Pull Request resolved: pytorch/pytorch#26655

Test Plan: Imported from OSS

Differential Revision: D17556196

Pulled By: nairbv

fbshipit-source-id: eeebce8968bfb2ffd25c066595bc19e5dee6ea6f
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@nairbv merged this pull request in 0c6a18d.

@xuhdev xuhdev deleted the gh/nairbv/3/head branch October 14, 2019 20:03
@gchanan
Copy link
Copy Markdown
Contributor

gchanan commented Oct 15, 2019

does this work with JIT?

@nairbv
Copy link
Copy Markdown
Collaborator Author

nairbv commented Oct 16, 2019

does this work with JIT?

Seems like it works as much as scalar types in general work (they're treated as ints):

>>> code='''
... def foo():
...     return torch.promote_types(torch.int, torch.double)
... def bar():
...     return torch.double
... '''
>>> cu=torch.jit.CompilationUnit(code)
>>> cu.foo()
7
>>> cu.bar()
7

pdlive215 pushed a commit to pdlive215/pytorch that referenced this pull request Nov 27, 2019
Summary: Pull Request resolved: pytorch#26655

Test Plan: Imported from OSS

Differential Revision: D17556196

Pulled By: nairbv

fbshipit-source-id: eeebce8968bfb2ffd25c066595bc19e5dee6ea6f
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary: Pull Request resolved: pytorch#26655

Test Plan: Imported from OSS

Differential Revision: D17556196

Pulled By: nairbv

fbshipit-source-id: eeebce8968bfb2ffd25c066595bc19e5dee6ea6f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: docs Related to our documentation, both in docs/ and docblocks module: internals Related to internal abstractions in c10 and ATen module: pybind Related to our Python bindings / interactions with other Python libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants