[JIT] Allow type cast between int and float in Script#10168
[JIT] Allow type cast between int and float in Script#10168wanchaol wants to merge 2 commits intopytorch:masterfrom
Conversation
setup.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
0705aea to
8cc10e9
Compare
zdevito
left a comment
There was a problem hiding this comment.
Looks good -- Just some small changes.
setup.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/ir.h
Outdated
| result->output()->setType(type); | ||
| return result; | ||
| } | ||
| Node* createIntToFloat(const TypePtr& type, Value* value) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/ir.h
Outdated
| result->output()->setType(type); | ||
| return result; | ||
| } | ||
| Node* createFloatToInt(const TypePtr& type, Value* value) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/register_prim_ops.cpp
Outdated
| prim::IntToFloat, | ||
| [](Node* node) -> Operation { | ||
| return [](Stack& stack) { | ||
| at::Scalar s; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/register_prim_ops.cpp
Outdated
| prim::FloatToInt, | ||
| [](Node* node) -> Operation { | ||
| return [](Stack& stack) { | ||
| at::Scalar s; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/register_prim_ops.cpp
Outdated
| return [](Stack& stack) { | ||
| at::Scalar s; | ||
| pop(stack, s); | ||
| push(stack, s.toFloat()); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/register_prim_ops.cpp
Outdated
| return [](Stack& stack) { | ||
| at::Scalar s; | ||
| pop(stack, s); | ||
| push(stack, s.toInt()); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/script/compiler.cpp
Outdated
| n = graph.createIntToFloat(dst, value); | ||
| } else { | ||
| throw ErrorReport(loc) << "Cannot cast type '" << orig->str() << "' to type '" | ||
| << dst->str() << "', no available type casting."; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
facebook-github-bot
left a comment
There was a problem hiding this comment.
wanchaol has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
d0663f4 to
46b54e1
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
wanchaol has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@pytorchbot retest this please |
Summary: The PR allows int→float and float→int casts. Current we only allow `tensor→int` and `tensor→float` casts. Pull Request resolved: pytorch#10168 Differential Revision: D9141163 Pulled By: wanchaol fbshipit-source-id: 5e5591a98b4985a675641dfc9a385b2a0bf8e208
The PR allows int→float and float→int casts. Current we only allow
tensor→intandtensor→floatcasts.