Skip to content

Commit 32d75cd

Browse files
committed
compiler: Add more checks prior to specialization
1 parent b071524 commit 32d75cd

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

devito/ir/iet/visitors.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,11 +1525,14 @@ def __init__(self, mapper, nested=False):
15251525
f"specialization. Value {v} was supplied for symbol "
15261526
f"{k}, but is of type {type(v)}.")
15271527

1528+
try:
1529+
_ = k.dtype(v)
1530+
except ValueError as e:
1531+
raise ValueError(f"Value {v} is incompatible with {k.dtype} dtype "
1532+
"of {k}") from e
1533+
15281534
def _visit(self, o, *args, **kwargs):
15291535
retval = super()._visit(o, *args, **kwargs)
1530-
# print(f"Visiting {o.__class__}")
1531-
# print(retval)
1532-
# print("--------------------------------------------")
15331536
return retval
15341537

15351538
# TODO: Should probably be moved to Uxreplace at least (as should some of these
@@ -1580,10 +1583,6 @@ def visit_Operator(self, o, **kwargs):
15801583
raise ValueError(f"Attempted to specialize symbols {not_params} which are not"
15811584
" found in the Operator parameters")
15821585

1583-
# FIXME: Should also type-check the values supplied against the symbols they are
1584-
# replacing (and cast them if needed?) -> use a try-except on the cast in
1585-
# python-land
1586-
15871586
parameters = tuple(i for i in o.parameters if i not in self.mapper)
15881587

15891588
# Note: the following is not dissimilar to unpickling an Operator

tests/test_specialization.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ def test_apply_basic(self):
192192

193193
# TODO: Need a test to check that block sizes can be specialized
194194
# TODO: Need to test that tile sizes can be specialized
195+
# TODO: Test pickling followed by specialization
196+
# TODO: Test specialized operators can be pickled
195197

196198

197199
class TestApply:

0 commit comments

Comments
 (0)