Skip to content

Commit dcc0d78

Browse files
committed
compiler: Relax ComponentAccess
1 parent d12129f commit dcc0d78

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

devito/passes/iet/languages/CIR.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ class CIRPrinter(CPrinter):
88
"""
99

1010
def _print_ComponentAccess(self, expr):
11-
return f"{self._print(expr.base)}.<{expr.sindex},{expr.function.ncomp}>"
11+
try:
12+
ncomp = expr.function.ncomp
13+
except AttributeError:
14+
# E.g., the argument is a plain Symbol
15+
ncomp = 'N'
16+
return f"{self._print(expr.base)}.<{expr.sindex},{ncomp}>"

devito/types/array.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,9 @@ class ComponentAccess(Expr, Pickable):
588588
__rkwargs__ = ('index',)
589589

590590
def __new__(cls, arg, index=0, **kwargs):
591-
if not arg.is_Indexed:
592-
raise ValueError("Expected Indexed, got `%s` instead" % type(arg))
591+
if not (arg.is_Symbol or arg.is_Indexed):
592+
raise ValueError(f"Expected Symbol or Indexed, got `{type(arg)}` "
593+
"instead")
593594
if not is_integer(index) or index > 3:
594595
raise ValueError("Expected 0 <= index < 4")
595596

0 commit comments

Comments
 (0)