-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[TIR][Arith] Support negative coeff in ModularSet #13081
Conversation
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
This was originally discovered in a failing unit test for #13024. An unrolled loop produced a |
Prior to this commit, any use of negative coefficients in `ModularSet` would result in an error. This included cases where a constraint is being entered, such as `floormod(i, -2)==0` appearing as the condition of an if/else block. These negative indices can also arise as intermediate simplification steps produced by `CanonicalSimplifier`, such as `floormod(-i,2)` being canonicalized to `floormod(i,-2)`. This commit adds support for negative coefficients in `ModularSet`, using the same sign convention as is used by `CanonicalSimplifier` for negative denominators, and adds unit tests to verify that sign convention.
b76c70a
to
297b3af
Compare
Rebasing onto main to get the bug fix from #13067 |
@@ -97,6 +97,8 @@ def test_split_index_simplify(): | |||
# cannot simplify mixed case, unless we canonicalize into one mode. | |||
ck.verify(tdiv(x, 6) * 2 + tmod(fld(x, 3), 2), tdiv(x, 6) * 2 + tmod(fld(x, 3), 2)) | |||
|
|||
ck.verify(tmod(-x, 2), tmod(x, -2) * -1) |
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.
does this cover modular set analysis?
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.
This test only covers the CanonicalSimplify behavior of negative indices, but the ModularSet's behavior should be consistent with the sign convention in CanonicalSimplify. Since CanonicalSimplify's sign convention for negative indices wasn't checked by any test I could find, I wanted to add a test for its behavior.
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.
Nice fix, Thanks @Lunderberg!
Prior to this commit, any use of negative coefficients in `ModularSet` would result in an error. This included cases where a constraint is being entered, such as `floormod(i, -2)==0` appearing as the condition of an if/else block. These negative indices can also arise as intermediate simplification steps produced by `CanonicalSimplifier`, such as `floormod(-i,2)` being canonicalized to `floormod(i,-2)`. This commit adds support for negative coefficients in `ModularSet`, using the same sign convention as is used by `CanonicalSimplifier` for negative denominators, and adds unit tests to verify that sign convention.
Prior to this commit, any use of negative coefficients in `ModularSet` would result in an error. This included cases where a constraint is being entered, such as `floormod(i, -2)==0` appearing as the condition of an if/else block. These negative indices can also arise as intermediate simplification steps produced by `CanonicalSimplifier`, such as `floormod(-i,2)` being canonicalized to `floormod(i,-2)`. This commit adds support for negative coefficients in `ModularSet`, using the same sign convention as is used by `CanonicalSimplifier` for negative denominators, and adds unit tests to verify that sign convention.
Prior to this commit, any use of negative coefficients in
ModularSet
would result in an error. This included cases where a constraint is being entered, such asfloormod(i, -2)==0
appearing as the condition of an if/else block. These negative indices can also arise as intermediate simplification steps produced byCanonicalSimplifier
, such asfloormod(-i,2)
being canonicalized tofloormod(i,-2)
.This commit adds support for negative coefficients in
ModularSet
, using the same sign convention as is used byCanonicalSimplifier
for negative denominators, and adds unit tests to verify that sign convention.