Skip to content

Commit e5f8699

Browse files
isurufpytorchmergebot
authored andcommitted
[inductor] Fix ModularIndexing assumptions (pytorch#152993)
Fixes pytorch#151198. Since the result of ModularIndexing can be zero due to the modulo operation, we should not make any assumption about ModularIndexing being positive Pull Request resolved: pytorch#152993 Approved by: https://github.com/yf225
1 parent d900c68 commit e5f8699

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

test/inductor/test_indexing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ def test_modular_indexing_pairs_not_merged(self):
205205
self.assertEqual(expr2, actual)
206206
self.assertNotEqual(ModularIndexing(x, 1, b), actual)
207207

208+
def test_modular_indexing_positive(self):
209+
x = sympy.Symbol("x", integer=True, positive=True)
210+
expr = ModularIndexing(x, 1, 1024) - 1
211+
expr2 = abs(expr)
212+
213+
self.assertNotEqual(expr2, expr)
214+
208215
def test_expand_floor_div_skipped(self):
209216
sizevars = SizeVarAllocator()
210217
x = sympy.Symbol("x", integer=True, positive=True)

torch/utils/_sympy/functions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,6 @@ def _eval_is_nonnegative(self) -> Optional[bool]:
363363
p, q = self.args[:2]
364364
return fuzzy_eq(p.is_nonnegative, q.is_nonnegative) # type: ignore[attr-defined]
365365

366-
def _eval_is_positive(self) -> Optional[bool]:
367-
p, q = self.args[:2]
368-
return fuzzy_eq(p.is_positive, q.is_positive) # type: ignore[attr-defined]
369-
370366

371367
class Where(sympy.Function):
372368
"""

0 commit comments

Comments
 (0)