Skip to content
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

TypeError: 'Scene' object is not iterable #7955

Closed
Ginko2501 opened this issue May 9, 2023 · 1 comment
Closed

TypeError: 'Scene' object is not iterable #7955

Ginko2501 opened this issue May 9, 2023 · 1 comment
Assignees

Comments

@Ginko2501
Copy link

Hi,

I was defining custom @ti.data_oriented and encountered this problem. Here is my code

@ti.data_oriented
class Scene:

def __init__(self, dt):
    # spheres
    self.num_sphere = ti.field(dtype=ti.i32, shape=())
    self.spheres = Sphere.field(shape=(100,))
    
    # particles in local coordinates
    self.num_pt = ti.field(dtype=ti.i32, shape=())
    self.particles = ti.Vector.field(2, shape=(10000), dtype=ti.f32) 
    self.indecies = ti.field(dtype=ti.i32, shape=(10000))
    
     self.init_sphere(self, vec2(0,0), 0.5)

def init_sphere(self, o, r, R=vec2(1,0), v=vec2(0,0), ω=0, m=1, I=None, size=None):
    """Initialize a sphere"""
    self.spheres[self.num_sphere[None]].init(o, r, R, v, ω, m, I, size)
    self.num_sphere[None] += 1

This is what I got

File "c:\Zichen\Cornell\spring2023\CS5643\SimSDF\scene.py", line 24, in f
self.init_sphere(self, vec2(0,0), 0.5)
File "c:\Zichen\Cornell\spring2023\CS5643\SimSDF\scene.py", line 30, in init_sphere
self.spheres.o[0] = o
File "C:\Users\ziche\anaconda3\envs\sim-sdf\lib\site-packages\taichi\lang\util.py", line 311, in wrapped
return func(*args, **kwargs)
File "C:\Users\ziche\anaconda3\envs\sim-sdf\lib\site-packages\taichi\lang\matrix.py", line 1404, in setitem
self[key]._set_entries(value)
File "C:\Users\ziche\anaconda3\envs\sim-sdf\lib\site-packages\taichi\lang\util.py", line 311, in wrapped
return func(*args, **kwargs)
File "C:\Users\ziche\anaconda3\envs\sim-sdf\lib\site-packages\taichi\lang\matrix.py", line 453, in _set_entries
value = list(value)
TypeError: 'Scene' object is not iterable

However, I can self.spheres[self.num_sphere[None]].init(o, r, R, v, ω, m, I, size) with no problem directly in init or in my main.py. So I am not sure why this is happening.

@github-project-automation github-project-automation bot moved this to Untriaged in Taichi Lang May 9, 2023
@neozhaoliang neozhaoliang self-assigned this May 19, 2023
@neozhaoliang neozhaoliang moved this from Untriaged to Todo in Taichi Lang May 19, 2023
@neozhaoliang
Copy link
Contributor

neozhaoliang commented May 19, 2023

Hi @Ginko2501 in the code

self.init_sphere(self, vec2(0,0), 0.5)

You don't need to pass self as the first argument here, you should use

self.init_sphere(vec2(0,0), 0.5)

Maybe you need to understand how self works in Python's class, for example: https://www.pythonmorsels.com/what-is-self/

@github-project-automation github-project-automation bot moved this from Todo to Done in Taichi Lang May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants