|
19 | 19 | from .builtins import (builtin_functions_dict,
|
20 | 20 | PythonRange, PythonList, PythonTuple, PythonSet)
|
21 | 21 | from .cmathext import cmath_mod
|
22 |
| -from .datatypes import HomogeneousTupleType, PythonNativeInt |
| 22 | +from .datatypes import HomogeneousTupleType, InhomogeneousTupleType, PythonNativeInt |
23 | 23 | from .internals import PyccelFunction, Slice
|
24 | 24 | from .itertoolsext import itertools_mod
|
25 | 25 | from .literals import LiteralInteger, LiteralEllipsis, Nil
|
|
29 | 29 | from .numpyext import (NumpyEmpty, NumpyArray, numpy_mod,
|
30 | 30 | NumpyTranspose, NumpyLinspace)
|
31 | 31 | from .operators import PyccelAdd, PyccelMul, PyccelIs, PyccelArithmeticOperator
|
| 32 | +from .operators import PyccelUnarySub |
32 | 33 | from .scipyext import scipy_mod
|
33 | 34 | from .typingext import typing_mod
|
34 |
| -from .variable import (Variable, IndexedElement, InhomogeneousTupleVariable ) |
| 35 | +from .variable import Variable, IndexedElement |
35 | 36 |
|
36 | 37 | from .c_concepts import ObjectAddress
|
37 | 38 |
|
@@ -732,8 +733,8 @@ def expand_inhomog_tuple_assignments(block, language_has_vectors = False):
|
732 | 733 | block.substitute(allocs_to_unravel, new_allocs)
|
733 | 734 |
|
734 | 735 | assigns = [a for a in block.get_attribute_nodes(Assign) \
|
735 |
| - if isinstance(a.lhs, InhomogeneousTupleVariable) \ |
736 |
| - and isinstance(a.rhs, (PythonTuple, InhomogeneousTupleVariable))] |
| 736 | + if isinstance(a.lhs.class_type, InhomogeneousTupleType) \ |
| 737 | + and isinstance(a.rhs, (PythonTuple, Variable))] |
737 | 738 | if len(assigns) != 0:
|
738 | 739 | new_assigns = [[Assign(l,r) for l,r in zip(a.lhs, a.rhs)] for a in assigns]
|
739 | 740 | block.substitute(assigns, new_assigns)
|
@@ -796,3 +797,25 @@ def expand_to_loops(block, new_index, scope, language_has_vectors = False):
|
796 | 797 | body = [bi for b in body for bi in b]
|
797 | 798 |
|
798 | 799 | return body
|
| 800 | + |
| 801 | +#============================================================================== |
| 802 | +def is_literal_integer(expr): |
| 803 | + """ |
| 804 | + Determine whether the expression is a literal integer. |
| 805 | +
|
| 806 | + Determine whether the expression is a literal integer. A literal integer |
| 807 | + can be described by a LiteralInteger, a PyccelUnarySub(LiteralInteger) or |
| 808 | + a Constant. |
| 809 | +
|
| 810 | + Parameters |
| 811 | + ---------- |
| 812 | + expr : object |
| 813 | + Any Python object which should be analysed to determine whether it is an integer. |
| 814 | +
|
| 815 | + Returns |
| 816 | + ------- |
| 817 | + bool |
| 818 | + True if the object represents a literal integer, false otherwise. |
| 819 | + """ |
| 820 | + return isinstance(expr, (int, LiteralInteger)) or \ |
| 821 | + isinstance(expr, PyccelUnarySub) and isinstance(expr.args[0], (int, LiteralInteger)) |
0 commit comments