From f2cd3d7da094f57f9f7e285e4f9e177b86b63f0c Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Mon, 16 May 2016 17:32:29 -0500 Subject: [PATCH] Add affs_from_space --- doc/misc.rst | 3 +++ doc/reference.rst | 10 ++++++++-- islpy/__init__.py | 30 ++++++++++++++++++++++++++++++ test/test_isl.py | 18 +++++++++++++++++- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/doc/misc.rst b/doc/misc.rst index db3d1d9..be06a5b 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 ff24938..cfe351f 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 8765acd..b96eebc 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 a414b99..991031b 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: -- GitLab