-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Avoid duplicate evaluations in chaining comparison #540
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ff614b9
tmp
xumingkuan f974ad7
Merge branch 'chain_tmp' of github.com:xumingkuan/taichi into chain_tmp
xumingkuan dee4883
Avoid duplicate evaluations in chaining comparison
xumingkuan 6c2f6c2
Merge branch 'chain_tmp' of github.com:xumingkuan/taichi into chain_tmp
xumingkuan 6370968
minor: new line
xumingkuan c3996e7
removed taichi/lang.h and taichi/llvm_jit.h
yuanming-hu 41f3ffa
tmp
xumingkuan da6ef20
Make sure KernelTemplateMapper extractors's size is the same as the n…
k-ye 65a8db1
Update README.md
yuanming-hu bf38434
Avoid duplicate evaluations in chaining comparison
xumingkuan 14240ee
minor: new line
xumingkuan ef1ce4f
Merge branch 'chain_tmp' of github.com:xumingkuan/taichi into chain_tmp
xumingkuan 069f596
improve tests
xumingkuan c06d850
Do not apply the generic visitor if the function called is ti.static
xumingkuan a07e2bb
Disallow Expr.__getitem__ in Taichi-scope
xumingkuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,116 @@ | ||
import taichi as ti | ||
|
||
|
||
@ti.all_archs | ||
def test_compare_basics(): | ||
a = ti.var(ti.i32) | ||
ti.root.dynamic(ti.i, 256).place(a) | ||
b = ti.var(ti.i32, shape=()) | ||
c = ti.var(ti.i32, shape=()) | ||
|
||
@ti.kernel | ||
def func(): | ||
b[None] = 3 | ||
c[None] = 5 | ||
a[0] = b < c | ||
a[1] = b <= c | ||
a[2] = b > c | ||
a[3] = b >= c | ||
a[4] = b == c | ||
a[5] = b != c | ||
a[6] = c < b | ||
a[7] = c <= b | ||
a[8] = c > b | ||
a[9] = c >= b | ||
a[10] = c == b | ||
a[11] = c != b | ||
# a[12] = b is not c # not supported | ||
|
||
func() | ||
assert a[0] | ||
assert a[1] | ||
assert not a[2] | ||
assert not a[3] | ||
assert not a[4] | ||
assert a[5] | ||
assert not a[6] | ||
assert not a[7] | ||
assert a[8] | ||
assert a[9] | ||
assert not a[10] | ||
assert a[11] | ||
|
||
|
||
@ti.all_archs | ||
def test_compare_equality(): | ||
a = ti.var(ti.i32) | ||
ti.root.dynamic(ti.i, 256).place(a) | ||
b = ti.var(ti.i32, shape=()) | ||
c = ti.var(ti.i32, shape=()) | ||
|
||
@ti.kernel | ||
def func(): | ||
b[None] = 3 | ||
c[None] = 3 | ||
a[0] = b < c | ||
a[1] = b <= c | ||
a[2] = b > c | ||
a[3] = b >= c | ||
a[4] = b == c | ||
a[5] = b != c | ||
a[6] = c < b | ||
a[7] = c <= b | ||
a[8] = c > b | ||
a[9] = c >= b | ||
a[10] = c == b | ||
a[11] = c != b | ||
|
||
func() | ||
assert not a[0] | ||
assert a[1] | ||
assert not a[2] | ||
assert a[3] | ||
assert a[4] | ||
assert not a[5] | ||
assert not a[6] | ||
assert a[7] | ||
assert not a[8] | ||
assert a[9] | ||
assert a[10] | ||
assert not a[11] | ||
|
||
|
||
@ti.all_archs | ||
def test_no_duplicate_eval(): | ||
a = ti.var(ti.i32) | ||
ti.root.dynamic(ti.i, 256).place(a) | ||
|
||
@ti.kernel | ||
def func(): | ||
a[2] = 0 <= ti.append(a.parent(), [], 10) < 1 | ||
|
||
func() | ||
assert a[0] == 10 | ||
assert a[1] == 0 # not appended twice | ||
assert a[2] # ti.append returns 0 | ||
|
||
|
||
@ti.all_archs | ||
def test_chain_compare(): | ||
a = ti.var(ti.i32) | ||
ti.root.dynamic(ti.i, 256).place(a) | ||
b = ti.var(ti.i32, shape=()) | ||
c = ti.var(ti.i32, shape=()) | ||
d = ti.var(ti.i32, shape=()) | ||
|
||
@ti.kernel | ||
def func(): | ||
b[None] = 2 | ||
c[None] = 3 | ||
d[None] = 3 | ||
a[0] = c == d != b < d > b >= b <= c | ||
a[1] = b <= c != d > b == b | ||
|
||
func() | ||
assert a[0] | ||
assert not a[1] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would break the test into multiple pieces.
a[2] = 0 <= ti.append(a.parent(), [], 10) < 1
itself can be considered as one test (test_no_duplicate_eval
).a[3] = b < c == d
toc == d != b < d > b >= b <= c
(test_chain_compare
)test_compare_basics
)<
and<=
. (test_compare_equality
)