Add type annotation logic for complex numbers#50884
Add type annotation logic for complex numbers#50884anjali411 wants to merge 8 commits intogh/anjali411/88/basefrom
Conversation
[ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 33e9e2a (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Differential Revision: [](https://our.internmc.facebook.com/intern/diff/) [ghstack-poisoned]
Differential Revision: [](https://our.internmc.facebook.com/intern/diff/) [ghstack-poisoned]
Differential Revision: [](https://our.internmc.facebook.com/intern/diff/) [ghstack-poisoned]
SplitInfinity
left a comment
There was a problem hiding this comment.
Nice! Do you plan to support constant literals in TorchScript code in this diff? If not, I think it is ready to land. If so, I think some more changes are required.
| return py::cast<int64_t>(obj); | ||
| } else if (py::isinstance<py::float_>(obj)) { | ||
| return py::cast<double>(obj); | ||
| } else if (PyComplex_CheckExact(obj.ptr())) { |
There was a problem hiding this comment.
Dumb question but why does this line not say something like py::isinstance<py::complex_>(...) like all the others?
There was a problem hiding this comment.
Complex type is not available in pybind (see doc here: https://pybind11.readthedocs.io/en/stable/advanced/pycpp/object.html#accessing-python-libraries-from-c) so I just pass the underlying PyObject* to PyComplex_CheckExact to check whether it's complex
| if inspect.isclass(ann) and issubclass(ann, builtins.complex): | ||
| return ComplexDoubleType.get() |
There was a problem hiding this comment.
Another dumb question, why is this not ann is complex?
There was a problem hiding this comment.
Also, is there a usecase for creating subclasses of complex?
There was a problem hiding this comment.
complex is a python class hence the isclass call. umm no there's no use specific case of creating subclasses of complex
There was a problem hiding this comment.
But aren't int and float classes too?
There was a problem hiding this comment.
ok wait you are right ann is complex works!
| case TypeKind::ComplexDoubleType: | ||
| return parseSingleConstant(arg_type->kind()); |
There was a problem hiding this comment.
parseSingleConstant needs to be updated to handle complex numbers. I would either get rid of it and do it in a follow-up PR or add a test for it (and update parseSingleConstant and other code as needed).
There was a problem hiding this comment.
I'll just remove this change for the current PR and add it separately
Differential Revision: [](https://our.internmc.facebook.com/intern/diff/) [ghstack-poisoned]
no I'll just make a separate PR for that! also, addressed all the comments and updated the PR |
|
This pull request has been merged in b6eaca9. |
Summary: Pull Request resolved: pytorch#50884 Test Plan: Imported from OSS Reviewed By: heitorschueroff Differential Revision: D26086963 fbshipit-source-id: f103f7f529d63d701c4f17862e30eafbab7d0c68
Stack from ghstack:
Differential Revision:
Differential Revision: D26086963