diff --git a/doc/misc.rst b/doc/misc.rst index db3d1d9aaa87dc179fbe9682c6252587679a8250..be06a5bb7ed2d58c8750fa69bb376a34b7e7eeb3 100644 --- a/doc/misc.rst +++ b/doc/misc.rst @@ -93,6 +93,9 @@ Version 2016.2 This version is currently in development and can be obtained from islpy's version control. +* Update for isl 0.17 +* Add :func:`make_zero_and_vars` + Version 2016.1.1 ---------------- diff --git a/doc/reference.rst b/doc/reference.rst index ff249388b978d70b2aacc870fd308665e2396e84..cfe351f3b0f5205d457d4c953095199bd5113a5b 100644 --- a/doc/reference.rst +++ b/doc/reference.rst @@ -82,6 +82,14 @@ Error Reporting .. exception:: Error +Convenience +^^^^^^^^^^^ + +.. autofunction:: make_zero_and_vars + +.. autofunction:: affs_from_space + + Lifetime Helpers ^^^^^^^^^^^^^^^^ @@ -279,8 +287,6 @@ Piecewise Quasi-Affine Expression .. autoclass:: PwAff :members: -.. autofunction:: make_zero_and_vars - Union of Piecewise Quasi-Affine Expressions ------------------------------------------- diff --git a/islpy/__init__.py b/islpy/__init__.py index 8765acd8d360def78a5981f155ca979290f1963f..b96eebc422804f92977253432e3af169f14efe5c 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -1226,6 +1226,36 @@ def make_zero_and_vars(set_vars, params=[], ctx=None): params = [s.strip() for s in params.split(",")] space = Space.create_from_names(ctx, set=set_vars, params=params) + return affs_from_space(space) + + +def affs_from_space(space): + """ + :return: a dictionary from variable names (in *set_vars* and *params*) + to :class:`PwAff` instances that represent each of the + variables *in*space*. They key '0' is also include and represents + a :class:`PwAff` zero constant. + + .. versionadded:: 2016.2 + + This function is intended to make it relatively easy to construct sets + programmatically without resorting to string manipulation. + + Usage example:: + + s = isl.Set("[n] -> {[i,j,k]: 0<=i,j,k<n}") + v = isl.affs_from_space(s.space) + + myset = ( + v[0].le_set(v["i"] + v["j"]) + & + (v["i"] + v["j"]).lt_set(v["n"]) + & + (v[0].le_set(v["i"])) + & + (v["i"].le_set(13 + v["n"])) + ) + """ result = {} diff --git a/test/test_isl.py b/test/test_isl.py index a414b994ec6be43fa129da3ce58f1c86fafdf6bc..991031b106247b177018dd56e32bd313150f6f62 100644 --- a/test/test_isl.py +++ b/test/test_isl.py @@ -254,7 +254,7 @@ def test_codegen(): print(isl_ast_codegen(s)) -def test_set_building(): +def test_make_zero_and_vars(): v = isl.make_zero_and_vars("i,j,k", "n") myset = ( @@ -270,6 +270,22 @@ def test_set_building(): print(myset) +def test_affs_from_space(): + s = isl.Set("[n] -> {[i,j,k]: 0<=i,j,k<n}") + v = isl.affs_from_space(s.space) + + myset = ( + v[0].le_set(v["i"] + v["j"]) + & + (v["i"] + v["j"]).lt_set(v["n"]) + & + (v[0].le_set(v["i"])) + & + (v["i"].le_set(13 + v["n"])) + ) + + print(myset) + if __name__ == "__main__": import sys if len(sys.argv) > 1: