-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bug] [refactor] Fix error when ti.init() not called by deprecating E…
…xpr.layout_materialized (#1347) * [bug] [refactor] Fix AttributeError when ti.init() not called by deprecating Expr.layout_materialized * remove accident * add test * [skip ci] enforce code format * [skip ci] Update python/taichi/lang/impl.py Co-authored-by: Yuanming Hu <[email protected]> * try fix test * did fix * [skip ci] Update tests/python/test_runtime.py Co-authored-by: Ye Kuang <[email protected]> Co-authored-by: Taichi Gardener <[email protected]> Co-authored-by: Yuanming Hu <[email protected]> Co-authored-by: Ye Kuang <[email protected]>
- Loading branch information
1 parent
a6ad366
commit 4e37b9a
Showing
7 changed files
with
86 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
*.swp | ||
*.swo | ||
/.vs | ||
/tags | ||
/.*_localrc | ||
/tags | ||
/Debug | ||
*.sdf | ||
/x64 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import taichi as ti | ||
from taichi import make_temp_file | ||
import sys, os | ||
|
||
|
||
def test_without_init(): | ||
# We want to check if Taichi works well without ``ti.init()``. | ||
# But in test ``ti.init()`` will always be called in last ``@ti.all_archs``. | ||
# So we have to create a new Taichi instance, i.e. test in a sandbox. | ||
content = ''' | ||
import taichi as ti | ||
assert ti.cfg.arch == ti.cpu | ||
x = ti.var(ti.i32, (2, 3)) | ||
assert x.shape == (2, 3) | ||
x[1, 2] = 4 | ||
assert x[1, 2] == 4 | ||
''' | ||
filename = make_temp_file() | ||
with open(filename, 'w') as f: | ||
f.write(content) | ||
assert os.system(f'{sys.executable} {filename}') == 0 | ||
|
||
|
||
@ti.all_archs | ||
@ti.must_throw(RuntimeError) | ||
def test_materialization_after_kernel(): | ||
x = ti.var(ti.f32, (3, 4)) | ||
|
||
@ti.kernel | ||
def func(): | ||
print(x[2, 3]) | ||
|
||
func() | ||
|
||
y = ti.var(ti.f32, (2, 3)) | ||
# ERROR: No new variable should be declared after kernel invocation! | ||
|
||
|
||
@ti.all_archs | ||
@ti.must_throw(RuntimeError) | ||
def test_materialization_after_access(): | ||
x = ti.var(ti.f32, (3, 4)) | ||
|
||
print(x[2, 3]) | ||
|
||
y = ti.var(ti.f32, (2, 3)) | ||
# ERROR: No new variable should be declared after Python-scope tensor access! | ||
|
||
|
||
@ti.all_archs | ||
@ti.must_throw(RuntimeError) | ||
def test_materialization_after_get_shape(): | ||
x = ti.var(ti.f32, (3, 4)) | ||
|
||
print(x.shape) | ||
|
||
y = ti.var(ti.f32, (2, 3)) | ||
# ERROR: No new variable should be declared after Python-scope tensor access! |