-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Support operator overloading for UDT #20033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fdd14a7 to
aa2dcb6
Compare
aa2dcb6 to
721931c
Compare
| output = m_loaded(input) | ||
| self.assertEqual(3 * input, output) | ||
|
|
||
| def test_overloaded_fn(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll get long but I think it should have a test every magic method to make sure the switch in compiler.cpp is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure 🌵
| at::ArrayRef<NamedValue> attributes, | ||
| size_t n_binders) override { | ||
| if (inputs.size() > 0 && attributes.size() == 0) { | ||
| auto class_ptr = inputs[0].value(*m.graph())->type()->cast<ClassType>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens in Python if you have two separate classes with different __add__ methods and you do something like Foo() + Bar()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is out of scope for this PR. Probably an error should be raised when compiling the Class. All of the api's for ClassTypes assume a single function per name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh i misread the question, but if it's a binary op this will call into the first value's function, as with python
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Support operator overloading for User Defined Types, which includes desugaring
a + band python builtin functions which call into a method if it is defined likelen(x).See https://rszalski.github.io/magicmethods/ for list of magic methods.