|
5 | 5 |
|
6 | 6 | import numpy as np |
7 | 7 | import sympy |
8 | | -from sympy import Expr, Function, Number, Tuple, sympify |
| 8 | +from sympy import Expr, Function, Number, Tuple, cacheit, sympify |
9 | 9 | from sympy.core.decorators import call_highest_priority |
10 | 10 |
|
11 | 11 | from devito.finite_differences.elementary import Min, Max |
|
21 | 21 | 'ListInitializer', 'Byref', 'IndexedPointer', 'Cast', 'DefFunction', |
22 | 22 | 'MathFunction', 'InlineIf', 'ReservedWord', 'Keyword', 'String', |
23 | 23 | 'Macro', 'Class', 'MacroArgument', 'Deref', 'Namespace', |
24 | | - 'Rvalue', 'Null', 'SizeOf', 'rfunc', 'BasicWrapperMixin', 'ValueLimit'] |
| 24 | + 'Rvalue', 'Null', 'SizeOf', 'rfunc', 'BasicWrapperMixin', 'ValueLimit', |
| 25 | + 'VectorAccess'] |
25 | 26 |
|
26 | 27 |
|
27 | 28 | class CondEq(sympy.Eq): |
@@ -453,10 +454,7 @@ def _C_ctype(self): |
453 | 454 |
|
454 | 455 | @property |
455 | 456 | def _op(self): |
456 | | - cstr = ctypes_to_cstr(self._C_ctype) |
457 | | - if self.stars: |
458 | | - cstr = f"{cstr}{self.stars}" |
459 | | - return f'({cstr})' |
| 457 | + return f'({ctypes_to_cstr(self._C_ctype)}{self.stars})' |
460 | 458 |
|
461 | 459 | def __str__(self): |
462 | 460 | return f"{self._op}{self.base}" |
@@ -796,6 +794,36 @@ def __str__(self): |
796 | 794 | __repr__ = __str__ |
797 | 795 |
|
798 | 796 |
|
| 797 | +class VectorAccess(Expr, Pickable, BasicWrapperMixin): |
| 798 | + |
| 799 | + """ |
| 800 | + Represent a vector access operation at high-level. |
| 801 | + """ |
| 802 | + |
| 803 | + def __new__(cls, *args, **kwargs): |
| 804 | + return Expr.__new__(cls, *args) |
| 805 | + |
| 806 | + def __str__(self): |
| 807 | + return f"VL<{self.base}>" |
| 808 | + |
| 809 | + __repr__ = __str__ |
| 810 | + |
| 811 | + func = Pickable._rebuild |
| 812 | + |
| 813 | + @property |
| 814 | + def base(self): |
| 815 | + return self.args[0] |
| 816 | + |
| 817 | + @property |
| 818 | + def indices(self): |
| 819 | + return self.base.indices |
| 820 | + |
| 821 | + @cacheit |
| 822 | + def sort_key(self, order=None): |
| 823 | + # Ensure that the VectorAccess is sorted as the base |
| 824 | + return self.base.sort_key(order=order) |
| 825 | + |
| 826 | + |
799 | 827 | # Some other utility objects |
800 | 828 | Null = Macro('NULL') |
801 | 829 |
|
|
0 commit comments