def test_collect_aliases(fa, fb, fc, fd, t0, t1, t2, t3, exprs, expected): scope = [fa, fb, fc, fd, t0, t1, t2, t3] mapper = dict([(EVAL(k, *scope), v) for k, v in expected.items()]) _, aliases = collect(EVAL(exprs, *scope)) for k, v in aliases.items(): assert k in mapper assert (len(v.aliased) == 1 and mapper[k] is None) or v.anti_stencil == mapper[k]
def test_collect_aliases(fc, fd, exprs, expected): grid = Grid(shape=(4, 4)) x, y = grid.dimensions # noqa xi, yi = grid.interior.dimensions # noqa t0 = Scalar(name='t0') # noqa t1 = Scalar(name='t1') # noqa t2 = Scalar(name='t2') # noqa t3 = Scalar(name='t3') # noqa fa = Function(name='fa', grid=grid, shape=(4, ), dimensions=(x, )) # noqa fb = Function(name='fb', grid=grid, shape=(4, ), dimensions=(x, )) # noqa fc = Function(name='fc', grid=grid) # noqa fd = Function(name='fd', grid=grid) # noqa # List/dict comprehension would need explicit locals/globals mappings to eval for i, e in enumerate(list(exprs)): exprs[i] = eval(e) for k, v in list(expected.items()): expected[eval(k)] = eval(v) aliases = collect(exprs) assert len(aliases) > 0 for k, v in aliases.items(): assert ((len(v.aliased) == 1 and expected[k] is None) or v.anti_stencil == expected[k])