-
Notifications
You must be signed in to change notification settings - Fork 10
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
About ts.TaichiClass #9
Comments
E.g., you have a @ti.data_oriented
class TestClass:
def __init__(self):
self.a = ti.field(float, shape=())
self.b = ti.field(float, shape=())
test = Test()
test.a[None]
test.b[None] But this way your @ti.data_oriented
class TestClass:
def __init__(self, shape):
self.a = ti.field(float, shape=shape)
self.b = ti.field(float, shape=shape)
test = Test()
test.a[i]
test.b[i] But this way you can only initialize it as global field, you can't use it as local variables: tmp = test[i] # ERROR!
tmp.a
tmp.b You can't construct it as local variable: tmp2 = TestClass(a, b) You can't use a struct-for loop, or accessing its shape: for i in test:
...
test.shape[0] That's why I invent class TestClass(ts.TaichiClass):
def _init(self, shape=None):
return ti.field(float, shape), ti.field(float, shape)
@property
def a(self): return self.entries[0]
@property
def b(self): return self.entries[1]
test = TestClass.field(shape=233) as an walkaround. In fact, |
For your application case (the collider), if you have a lot of colliders, then using the method I mentioned in that post will be very low-efficient. You should use a
Not really, they're very different things. |
Ahh thanks for the detailed reply ! The truth is, after I saw your explanation, it seems I misunderstood the Emmmm sry but let me have a second to reconsider this issue😂 |
Hi, I'm the guy who posted this.
I'm currently considering to refactor my project to make it easier to extend. So I remembered in that post you mentioned the ts.TaichiClass, which is an enhanced version for ti.data_oriented.
Could you explain more about what's the difference between these two class because I did not find a concrete example(except the complex class from glsl) or documentation?
For example, for the question I raised in that post, how exactly the ts.TaichiClass could make a difference?
Could I directly replace every @ti.data_oriented decorator in a typical taichi class to ts.TaichiClass ?
Sorry my python skill could not support me to master the exact difference from source code
Thanks in advance !
The text was updated successfully, but these errors were encountered: