Skip to content

Commit

Permalink
Fix convit_base (#95174)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezyang authored and cyyever committed Mar 5, 2023
1 parent f572c99 commit f347244
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions test/test_sympy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def test_unary_ref(self, fn):
self.assertEqual(r.lower, r.upper)
self.assertEqual(ref_r, r.lower)

def test_pow_half(self):
ValueRangeAnalysis.pow(ValueRanges.unknown(), ValueRanges.wrap(0.5))

@parametrize("fn", BINARY_OPS)
def test_binary_ref(self, fn):
for a, b in itertools.product(CONSTANTS, repeat=2):
Expand Down
7 changes: 6 additions & 1 deletion torch/utils/_sympy/value_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,19 @@ def sqrt(x):

@classmethod
def pow(cls, a, b):
def is_integer(val):
return isinstance(val, int) or (
hasattr(val, "is_integer") and val.is_integer
)

a = ValueRanges.wrap(a)
b = ValueRanges.wrap(b)
if a.is_singleton() and b.is_singleton():
r = a.lower**b.lower
if r == sympy.zoo:
return ValueRanges.unknown()
return ValueRanges.wrap(r)
elif b.is_singleton() and b.lower >= 0 and isinstance(b.lower, int):
elif b.is_singleton() and is_integer(b.lower) and b.lower >= 0:
i = ValueRanges.wrap(1)
for _ in range(b.lower):
i = cls.mul(i, a)
Expand Down

0 comments on commit f347244

Please sign in to comment.