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

[Bug] [lang] Fix error when subscripting a dict #1950

Merged
merged 3 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions python/taichi/lang/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def subscript(value, *indices):
if isinstance(value, np.ndarray):
return value.__getitem__(*indices)

if isinstance(value, tuple) or isinstance(value, list):
if isinstance(value, (tuple, list, dict)):
assert len(indices) == 1
return value[indices[0]]

Expand Down Expand Up @@ -243,6 +243,7 @@ def layout():

for func in self.materialize_callbacks:
func()
self.materialize_callbacks = []
yuanming-hu marked this conversation as resolved.
Show resolved Hide resolved

def clear(self):
if self.prog:
Expand Down Expand Up @@ -535,11 +536,9 @@ def static(x, *xs):
import types
import taichi as ti
if isinstance(x, (bool, int, float, range, list, tuple, enumerate,
ti.ndrange, ti.GroupedNDRange)) or x is None:
return x
elif isinstance(x, ti.lang.expr.Expr) and x.ptr.is_global_var():
ti.ndrange, ti.GroupedNDRange, zip, filter, map)) or x is None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OFT further extend static-for possibilities.

return x
elif isinstance(x, ti.Matrix) and x.is_global():
elif isinstance(x, (ti.Expr, ti.Matrix)) and x.is_global():
yuanming-hu marked this conversation as resolved.
Show resolved Hide resolved
return x
elif isinstance(x, (types.FunctionType, types.MethodType)):
return x
Expand Down
2 changes: 1 addition & 1 deletion python/taichi/lang/ndrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def __init__(self, *args):
args = list(args)
for i in range(len(args)):
if isinstance(args[i], list):
args[i] = list(args[i])
args[i] = tuple(args[i])
yuanming-hu marked this conversation as resolved.
Show resolved Hide resolved
if not isinstance(args[i], tuple):
args[i] = (0, args[i])
assert len(args[i]) == 2
Expand Down