-
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
Struct member function can not be called #7370
Comments
I meet this problem too T_T. |
I guess currently only way is to use procedural programming with first argument being the struct... |
May i ask if this is data oriented programming? The struct is considered as a group of data without function. |
It's been a long time. By the way I bypassed this issue by opting for newer python version. So... what's the cause of this problem? As far as I can recall, it's caused by struct name aliasing? But I don't see anything related to this in my minimal reproduction code. Judging from the discussion you have above, it seems that it is caused by struct nesting, and the member functions of the inner struct are stripped? |
Could you please explain how you can bypass this issue by newer python version? Because I think maybe taichi is not related to the version of python? |
Since I have two systems (one windows and one ubuntu) on my laptop, I found that the behavior of my code was different, even if I have the same version of Taichi. I did some experiments back then, and found that 3.8- (not all of them, 3.7.8 seemed fine, if I recall it correctly) would run into this issue. I tried again this code just now:
And..., is struct nesting such a big problem? I used a lot in my project, like: BSDF.py. The outtermost struct is BSDF, containing a struct Medium, which contains, further, a dataclass struct called PhaseFunction. The code works fine. |
thanks a lot!! |
Mine is 3.9.13, but my ubuntu is 3.8+. This is weird... |
Calling nested struct member function
Calling the function of a struct from the parent struct will fail and lead to "AttributeError: 'Structxx' object has no attribute 'xxx'"
To Reproduce
First, I know this issue looks like #6917 or #6737 but it's different. I saw there was a pr in #6917. I ran through the code, and also found the updated version of struct initialization. Yet I got a exception.
I create a small example snippet to reproduce:
The code is run by (say we create a file called
test.py
):python3 test.py
Log/Screenshots
The exception thrown:
I have tested this behavior on Win11 / Ubuntu 20.04, with python 3.7.1 and 3.7.5, taichi 1.3.0 (after that fixing PR) and 1.4.1. It looks like on win11, llvm version is 15.0.1 while on linux it is 15.0.4. They all throw the same exception. I tried to print the
__struct_method
field when initializing the struct, everything seems fine to me. I just got no clue why this would happen.Additional comments
The text was updated successfully, but these errors were encountered: