From e6f4023ab68a97ba8653aaf3d99c1e199abd5e85 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Feb 2019 14:06:11 -0600 Subject: [PATCH 1/4] make_sym_vector: Accept integral values for components. --- pymbolic/primitives.py | 17 +++++++++++++---- test/test_pymbolic.py | 9 +++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py index 018cbaa..5855f5d 100644 --- a/pymbolic/primitives.py +++ b/pymbolic/primitives.py @@ -1700,14 +1700,23 @@ def make_sym_vector(name, components, var_factory=None): """Return an object array of *components* subscripted :class:`Variable` (or subclass) instances. - :arg components: The number of components in the vector. - :arg var_factory: The :class:`Variable` subclass to use for instantiating - the scalar variables. + :arg components: Either a list of indices, or an integer representing the + number of indices. + :arg var_factory: The :class:`Variable` subclass to + use for instantiating the scalar variables. + + For example, this creates a vector with three components:: + + >>> make_sym_vector("vec", 3) + array([Subscript(Variable('vec'), 0), Subscript(Variable('vec'), 1), + Subscript(Variable('vec'), 2)], dtype=object) + """ if var_factory is None: var_factory = Variable - if isinstance(components, int): + from numbers import Integral + if isinstance(components, Integral): components = list(range(components)) from pytools.obj_array import join_fields diff --git a/test/test_pymbolic.py b/test/test_pymbolic.py index 2cc3c82..4b358ab 100644 --- a/test/test_pymbolic.py +++ b/test/test_pymbolic.py @@ -574,6 +574,15 @@ def test_flop_counter(): assert CSEAwareFlopCounter()(expr) == 4 + 2 +def test_make_sym_vector(): + numpy = pytest.importorskip("numpy") + from pymbolic.primitives import make_sym_vector + + assert len(make_sym_vector("vec", 2)) == 2 + assert len(make_sym_vector("vec", numpy.int32(2))) == 2 + assert len(make_sym_vector("vec", [1, 2, 3])) == 3 + + if __name__ == "__main__": import sys if len(sys.argv) > 1: -- GitLab From f15e62a1465d2a4cb8666389eb39f15b5d059c40 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Feb 2019 14:10:21 -0600 Subject: [PATCH 2/4] Don't reference specific Python 3 versions in CI. --- .gitlab-ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9213375..dbfd8e9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,14 +26,14 @@ Python 2.7 Conda: reports: junit: test/pytest.xml -Python 3.7: +Python 3: script: - - py_version=3.7 + - PY_EXE=python3 - EXTRA_INSTALL="numpy sympy pexpect" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" tags: - - python3.7 + - python3 - maxima except: - tags @@ -41,7 +41,7 @@ Python 3.7: reports: junit: test/pytest.xml -Python 3.6 Conda: +Python 3 Conda: script: - CONDA_ENVIRONMENT=.test-py3.yml - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh @@ -54,7 +54,7 @@ Python 3.6 Conda: reports: junit: test/pytest.xml -Python 3.6 Apple: +Python 3 Conda Apple: script: - CONDA_ENVIRONMENT=.test-py3.yml - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh @@ -70,11 +70,11 @@ Python 3.6 Apple: Pylint: script: - EXTRA_INSTALL="numpy sympy symengine scipy pexpect" - - py_version=3.7 + - PY_EXE=python3 - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-pylint.sh - ". ./prepare-and-run-pylint.sh pymbolic test/test_*.py" tags: - - python3.7 + - python3 except: - tags @@ -93,6 +93,6 @@ Flake8: - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-flake8.sh - ". ./prepare-and-run-flake8.sh pymbolic test" tags: - - python3.5 + - python3 except: - tags -- GitLab From f860f9df7c5692d8e24b86cbfceeef0889888039 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Feb 2019 14:17:20 -0600 Subject: [PATCH 3/4] Can default to Variable instead of None. --- pymbolic/primitives.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py index 5855f5d..9633625 100644 --- a/pymbolic/primitives.py +++ b/pymbolic/primitives.py @@ -1696,7 +1696,7 @@ def make_common_subexpression(field, prefix=None, scope=None): return CommonSubexpression(field, prefix, scope) -def make_sym_vector(name, components, var_factory=None): +def make_sym_vector(name, components, var_factory=Variable): """Return an object array of *components* subscripted :class:`Variable` (or subclass) instances. @@ -1712,9 +1712,6 @@ def make_sym_vector(name, components, var_factory=None): Subscript(Variable('vec'), 2)], dtype=object) """ - if var_factory is None: - var_factory = Variable - from numbers import Integral if isinstance(components, Integral): components = list(range(components)) -- GitLab From d8743391c655303a15b76c5e526555f58dd7b0f5 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Feb 2019 14:25:27 -0600 Subject: [PATCH 4/4] Another spot where Variable can be defaulted. --- pymbolic/primitives.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py index 9633625..8bc8042 100644 --- a/pymbolic/primitives.py +++ b/pymbolic/primitives.py @@ -1721,10 +1721,7 @@ def make_sym_vector(name, components, var_factory=Variable): return join_fields(*[vfld.index(i) for i in components]) -def make_sym_array(name, shape, var_factory=None): - if var_factory is None: - var_factory = Variable - +def make_sym_array(name, shape, var_factory=Variable): vfld = var_factory(name) if shape == (): return vfld -- GitLab