Skip to content

Commit

Permalink
Fixed ast.Num and n attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexnick83 committed Oct 9, 2023
1 parent 5ae0b47 commit fead1d6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dace/codegen/tools/type_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,15 @@ def _BinOp(t, symbols, inferred_symbols):
return dtypes.result_type_of(type_left, type_right)
# Special case for integer power
elif t.op.__class__.__name__ == 'Pow':
if (isinstance(t.right, (ast.Num, ast.Constant)) and int(t.right.n) == t.right.n and t.right.n >= 0):
if (sys.version_info >= (3, 8) and isinstance(t.right, ast.Constant) and
int(t.right.value) == t.right.value and t.right.value >= 0):
if t.right.value != 0:
type_left = _dispatch(t.left, symbols, inferred_symbols)
for i in range(int(t.right.n) - 1):
_dispatch(t.left, symbols, inferred_symbols)
return dtypes.result_type_of(type_left, dtypes.typeclass(np.uint32))
elif (sys.version_info < (3, 8) and isinstance(t.right, ast.Num) and
int(t.right.n) == t.right.n and t.right.n >= 0):
if t.right.n != 0:
type_left = _dispatch(t.left, symbols, inferred_symbols)
for i in range(int(t.right.n) - 1):
Expand Down

0 comments on commit fead1d6

Please sign in to comment.