-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[Lang] Support template arguments for ti.func #1043
Conversation
No problem! But cant we already pass snodes into funcs without ti.template(), like we did in #824 with |
Yes, we already can, but requires a dirty hack (is it?), see 0139195#r39384288. |
Actually, I just tried commenting out |
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.
Thank you! LGTM. I suggest adding a couple of lines of comments in case we forget what's happening here in the future.
The test I added doesn't work atm. For some reason it runs into a python sytnax error. This syntax error does not occur when the test is run as stand alone script. So I think its related some weird nested function syntax. If you have another idea for the test to get around that please let me know!
Is this still an issue? It seems to me that CI tests are passing.
if isinstance(self.func.arguments[i], ti.template): | ||
continue |
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.
if isinstance(self.func.arguments[i], ti.template): | |
continue | |
# Directly pass in template arguments, | |
# such as class instances ("self"), tensors, SNodes, etc. | |
if isinstance(self.func.arguments[i], ti.template): | |
continue | |
# Create a copy for non-template arguments, | |
# so that they are passed by value. |
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.
Aliright thanks! Yes, both tests are passing. Although the second one passes even without making x a template. I assume its related to the hack 0139195#r39384288 @archibate was talking about, which I think we can get rid of at some point.
This PR implements support for template arguments in
ti.func
s. This just required skipping python AST transform for arguments type-hinted withti.template()
. I also slightly refactored ASTTransformer by removing theis_classfunc
argument.The test I added doesn't work atm. For some reason it runs into a python sytnax error. This syntax error does not occur when the test is run as stand alone script. So I think its related some weird nested function syntax. If you have another idea for the test to get around that please let me know!
Related issue = #1042
[Click here for the format server]