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 all commits
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ __pycache__
*.jpg
*.egg-info
.tlang_cache
.tidle_*
/taichi/common/version.h
/taichi/common/commit_hash.h
/python/test_env
Expand Down
12 changes: 6 additions & 6 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 @@ -534,12 +535,11 @@ def static(x, *xs):
return [static(x)] + [static(x) for x in 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():
if isinstance(x,
(bool, int, float, range, list, tuple, enumerate, ti.ndrange,
ti.GroupedNDRange, zip, filter, map)) or x is None:
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