mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[math] Trace float.fromhex
(#156976)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/156976 Approved by: https://github.com/zou3519 ghstack dependencies: #156975, #156977
This commit is contained in:
committed by
PyTorch MergeBot
parent
f5314f89c8
commit
576253c476
@ -1271,6 +1271,19 @@ class BuiltinVariable(VariableTracker):
|
||||
args[1:],
|
||||
)
|
||||
|
||||
if self.fn is float and len(args) == 1 and name in ("fromhex", "hex"):
|
||||
if isinstance(args[0], ConstantVariable):
|
||||
try:
|
||||
fn = getattr(float, name)
|
||||
res = fn(args[0].as_python_constant())
|
||||
return variables.ConstantVariable.create(res)
|
||||
except (OverflowError, ValueError) as e:
|
||||
raise_observed_exception(
|
||||
type(e),
|
||||
tx,
|
||||
args=list(map(ConstantVariable.create, e.args)),
|
||||
)
|
||||
|
||||
if self.fn is object and name == "__init__":
|
||||
# object.__init__ is a no-op
|
||||
return variables.ConstantVariable(None)
|
||||
|
Reference in New Issue
Block a user