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

[refactor] Enable the new ast builder by default #3516

Merged
merged 4 commits into from
Nov 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/taichi/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def __init__(self):
self.gdb_trigger = False
self.excepthook = False
self.experimental_real_function = False
self.experimental_ast_refactor = False
self.experimental_ast_refactor = True


def prepare_sandbox():
Expand Down
5 changes: 5 additions & 0 deletions python/taichi/lang/ir_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,11 @@ def build_Continue(ctx, node):
def build_Pass(ctx, node):
return node

@staticmethod
def build_Raise(ctx, node):
node.exc = build_stmt(ctx, node.exc)
raise node.exc.ptr


build_stmt = IRBuilder()

Expand Down
15 changes: 9 additions & 6 deletions python/taichi/lang/linalg_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,13 @@ def svd(A, dt):
Returns:
Decomposed nxn matrices `U`, 'S' and `V`.
"""
if ti.static(A.n == 2):
if ti.static(A.n == 2): # pylint: disable=R1705
ret = svd2d(A, dt)
return ret
if ti.static(A.n == 3):
elif ti.static(A.n == 3):
return svd3d(A, dt)
raise Exception("SVD only supports 2D and 3D matrices.")
else:
raise Exception("SVD only supports 2D and 3D matrices.")


@func
Expand All @@ -251,9 +252,11 @@ def polar_decompose(A, dt):
Returns:
Decomposed nxn matrices `U` and `P`.
"""
if ti.static(A.n == 2):
if ti.static(A.n == 2): # pylint: disable=R1705
ret = polar_decompose2d(A, dt)
return ret
if ti.static(A.n == 3):
elif ti.static(A.n == 3):
return polar_decompose3d(A, dt)
raise Exception("Polar decomposition only supports 2D and 3D matrices.")
else:
raise Exception(
"Polar decomposition only supports 2D and 3D matrices.")
17 changes: 17 additions & 0 deletions tests/python/test_ast_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,3 +967,20 @@ def foo() -> ti.i32:
return bar(1, 2, 3)

foo()


@ti.test(experimental_ast_refactor=True)
def test_raise():
dim = 1
m = ti.Matrix.field(dim, dim, ti.f32)
ti.root.place(m)

with pytest.raises(Exception) as e:

@ti.kernel
def foo():
ti.polar_decompose(m, ti.f32)

foo()
assert e.value.args[
0] == "Polar decomposition only supports 2D and 3D matrices."