-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes replacement of dict keys (spcl#1845)
If the internal method `SDFG._replace_dict_keys` is called with the same `old` and `new` keys, then the method erroneously removes the entry for the specific key completely. Such a case occurs when calling `SDFG.replace_dict` with a dictionary that contains identity replacement matches. This PR addresses the issue by: - [x] Adding a check inside `SDFG._replace_dict_keys` and skipping if `old == new`. A warning is also thrown for debugging purposes. - [x] Removing identity replacement matches from `repldict` and `symrepl` in `SDFG.replace_dict`.
- Loading branch information
1 parent
43883ea
commit 6254c0f
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2019-2025 ETH Zurich and the DaCe authors. All rights reserved. | ||
|
||
import dace | ||
import numpy as np | ||
|
||
|
||
def test_key_replacement_same_name(): | ||
|
||
sdfg = dace.SDFG('key_replacement_same_name') | ||
sdfg.add_array('inp', [1], dace.int32) | ||
sdfg.add_array('out', [1], dace.int32) | ||
|
||
first = sdfg.add_state('first_state') | ||
second = sdfg.add_state('second_state') | ||
edge = sdfg.add_edge(first, second, dace.InterstateEdge(assignments={'s': 'inp[0]'})) | ||
|
||
task = second.add_tasklet('t', {}, {'__out'}, '__out = s') | ||
access = second.add_access('out') | ||
second.add_edge(task, '__out', access, None, dace.Memlet('out[0]')) | ||
|
||
sdfg.replace('s', 's') | ||
assert 's' in edge.data.assignments | ||
sdfg.replace_dict({'s': 's'}) | ||
assert 's' in edge.data.assignments | ||
|
||
rng = np.random.default_rng() | ||
inp = rng.integers(1, 100, 1) | ||
inp = np.array(inp, dtype=np.int32) | ||
out = np.zeros([1], dtype=np.int32) | ||
|
||
sdfg(inp=inp, out=out) | ||
assert out[0] == inp[0] | ||
|
||
|
||
if __name__ == '__main__': | ||
test_key_replacement_same_name() |