mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
[dynamo] Support method calls on complex ConstantVariables (#161122)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161122 Approved by: https://github.com/mlazos, https://github.com/guilhermeleobas
This commit is contained in:
committed by
PyTorch MergeBot
parent
9d882fd9ff
commit
4c36c8a994
@ -308,6 +308,7 @@ class BuiltinVariable(VariableTracker):
|
||||
bool,
|
||||
callable,
|
||||
chr,
|
||||
complex,
|
||||
divmod,
|
||||
float,
|
||||
getattr,
|
||||
@ -1478,21 +1479,6 @@ class BuiltinVariable(VariableTracker):
|
||||
call_int = _call_int_float
|
||||
call_float = _call_int_float
|
||||
|
||||
def call_complex(self, tx: "InstructionTranslator", *args, **kwargs):
|
||||
if self.constant_args(*args, **kwargs):
|
||||
try:
|
||||
c = complex(
|
||||
*(arg.as_python_constant() for arg in args),
|
||||
**{k: kwargs[k].as_python_constant() for k in kwargs},
|
||||
)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise_observed_exception(
|
||||
type(exc),
|
||||
tx,
|
||||
args=list(map(ConstantVariable.create, exc.args)),
|
||||
)
|
||||
return ConstantVariable(c)
|
||||
|
||||
def call_bool(self, tx: "InstructionTranslator", arg):
|
||||
# Emulate `PyBool_Type.tp_vectorcall` which boils down to `PyObject_IsTrue`.
|
||||
# https://github.com/python/cpython/blob/3.12/Objects/object.c#L1674-L1697
|
||||
|
Reference in New Issue
Block a user