From 3ac1ae407df7e3e1fe01212857a26b29e88d7636 Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Mon, 5 Oct 2020 21:49:39 +0200 Subject: [PATCH 01/11] Remove Tags related classes moved to pytools. Instead import them from pytools. --- pytato/array.py | 91 ++----------------------------------------------- 1 file changed, 2 insertions(+), 89 deletions(-) diff --git a/pytato/array.py b/pytato/array.py index 1b5406f..6e29a43 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -162,7 +162,8 @@ from typing import ( import numpy as np import pymbolic.primitives as prim from pymbolic import var -from pytools import is_single_valued, memoize_method, UniqueNameGenerator +from pytools import (is_single_valued, memoize_method, UniqueNameGenerator, + DottedName, Tag, UniqueTag, TagsType) import pytato.scalar_expr as scalar_expr from pytato.scalar_expr import ScalarExpression @@ -181,47 +182,6 @@ else: EllipsisType = type(Ellipsis) -# {{{ dotted name - -class DottedName: - """ - .. attribute:: name_parts - - A tuple of strings, each of which is a valid - Python identifier. No name part may start with - a double underscore. - - The name (at least morally) exists in the - name space defined by the Python module system. - It need not necessarily identify an importable - object. - - .. automethod:: from_class - """ - - def __init__(self, name_parts: Tuple[str, ...]): - if len(name_parts) == 0: - raise ValueError("empty name parts") - - for p in name_parts: - if not p.isidentifier(): - raise ValueError(f"{p} is not a Python identifier") - - self.name_parts = name_parts - - @classmethod - def from_class(cls, argcls: Any) -> DottedName: - name_parts = tuple( - [str(part) for part in argcls.__module__.split(".")] - + [str(argcls.__name__)]) - if not all(not npart.startswith("__") for npart in name_parts): - raise ValueError(f"some name parts of {'.'.join(name_parts)} " - "start with double underscores") - return cls(name_parts) - -# }}} - - # {{{ namespace class Namespace(Mapping[str, "Array"]): @@ -298,53 +258,6 @@ class Namespace(Mapping[str, "Array"]): # }}} -# {{{ tag - -tag_dataclass = dataclass(init=True, eq=True, frozen=True, repr=True) - - -@tag_dataclass -class Tag: - """ - Generic metadata, applied to, among other things, - instances of :class:`Array`. - - .. attribute:: tag_name - - A fully qualified :class:`DottedName` that reflects - the class name of the tag. - - Instances of this type must be immutable, hashable, - picklable, and have a reasonably concise :meth:`__repr__` - of the form ``dotted.name(attr1=value1, attr2=value2)``. - Positional arguments are not allowed. - - .. automethod:: __repr__ - - .. note:: - - This mirrors the tagging scheme that :mod:`loopy` - is headed towards. - """ - - @property - def tag_name(self) -> DottedName: - return DottedName.from_class(type(self)) - - -class UniqueTag(Tag): - """ - Only one instance of this type of tag may be assigned - to a single tagged object. - """ - pass - - -TagsType = FrozenSet[Tag] - -# }}} - - # {{{ shape ShapeType = Tuple[ScalarExpression, ...] -- GitLab From 404739d9b635d953699a8c366a5770c6e1915e24 Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Mon, 5 Oct 2020 21:57:46 +0200 Subject: [PATCH 02/11] Remove unused classes, import tag_dataclass --- pytato/array.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pytato/array.py b/pytato/array.py index 6e29a43..b09993e 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -154,16 +154,15 @@ canonicalize type references. Once Sphinx 4.0 is released, we should use the from functools import partialmethod from numbers import Number import operator -from dataclasses import dataclass from typing import ( Optional, Callable, ClassVar, Dict, Any, Mapping, Iterator, Tuple, Union, - FrozenSet, Protocol, Sequence, cast, TYPE_CHECKING) + Protocol, Sequence, cast, TYPE_CHECKING) import numpy as np import pymbolic.primitives as prim from pymbolic import var -from pytools import (is_single_valued, memoize_method, UniqueNameGenerator, - DottedName, Tag, UniqueTag, TagsType) +from pytools import (is_single_valued, memoize_method, UniqueNameGenerator, + Tag, UniqueTag, TagsType, tag_dataclass) import pytato.scalar_expr as scalar_expr from pytato.scalar_expr import ScalarExpression -- GitLab From bc1dac2c3e8f9b4a2a79cf09017ef669523afa13 Mon Sep 17 00:00:00 2001 From: Christensen Date: Mon, 5 Oct 2020 15:30:56 -0500 Subject: [PATCH 03/11] Remove references to DottedName or Tag --- pytato/__init__.py | 5 ++--- pytato/array.py | 18 ++---------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/pytato/__init__.py b/pytato/__init__.py index d65fefc..0510394 100644 --- a/pytato/__init__.py +++ b/pytato/__init__.py @@ -25,8 +25,7 @@ THE SOFTWARE. """ from pytato.array import ( - Namespace, Array, DictOfNamedArrays, Tag, UniqueTag, - DottedName, Placeholder, IndexLambda, + Namespace, Array, DictOfNamedArrays, Placeholder, IndexLambda, make_dict_of_named_arrays, make_placeholder, make_size_param, make_data_wrapper, @@ -40,7 +39,7 @@ from pytato.visualization import get_dot_graph, show_dot_graph __all__ = ( "DottedName", "Namespace", "Array", "DictOfNamedArrays", - "Tag", "UniqueTag", "Placeholder", "IndexLambda", + "Placeholder", "IndexLambda", "make_dict_of_named_arrays", "make_placeholder", "make_size_param", "make_data_wrapper", diff --git a/pytato/array.py b/pytato/array.py index b09993e..64a94c0 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -60,8 +60,6 @@ These functions generally follow the interface of the corresponding functions in Supporting Functionality ------------------------ -.. autoclass:: DottedName - .. currentmodule:: pytato.array Concrete Array Data @@ -132,18 +130,6 @@ canonicalize type references. Once Sphinx 4.0 is released, we should use the Should be referenced as :class:`pytato.Namespace`. -.. class:: DottedName - - Should be referenced as :class:`pytato.DottedName`. - -.. class:: Tag - - Should be referenced as :class:`pytato.Tag`. - -.. class:: Array - - Should be referenced as :class:`pytato.Array`. - .. class:: DictOfNamedArrays Should be referenced as :class:`pytato.DictOfNamedArrays`. @@ -161,8 +147,8 @@ from typing import ( import numpy as np import pymbolic.primitives as prim from pymbolic import var -from pytools import (is_single_valued, memoize_method, UniqueNameGenerator, - Tag, UniqueTag, TagsType, tag_dataclass) +from pytools import is_single_valued, memoize_method, UniqueNameGenerator +from pytools.tag import Tag, UniqueTag, TagsType, tag_dataclass import pytato.scalar_expr as scalar_expr from pytato.scalar_expr import ScalarExpression -- GitLab From 4c03d753be383b5dc7d5c7224992c0d0a7a7c379 Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Thu, 15 Oct 2020 01:06:33 +0200 Subject: [PATCH 04/11] Add pytools dependency --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 094aa6e..2bae77a 100644 --- a/setup.py +++ b/setup.py @@ -35,6 +35,7 @@ setup(name="pytato", python_requires="~=3.8", install_requires=[ "loo.py", + "pytools>=2020.4.2" ], author="Andreas Kloeckner, Matt Wala, Xiaoyu Wei", -- GitLab From 801779e6ccaeb103ff6bc0f10d3966c4d4e9f331 Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Thu, 15 Oct 2020 01:29:55 +0200 Subject: [PATCH 05/11] Update version.py --- pytato/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytato/version.py b/pytato/version.py index c5f841e..1e45d87 100644 --- a/pytato/version.py +++ b/pytato/version.py @@ -25,6 +25,6 @@ THE SOFTWARE. """ -VERSION = (2020, 1) +VERSION = (2020, 1, 1) VERSION_STATUS = "" VERSION_TEXT = ".".join(str(x) for x in VERSION) + VERSION_STATUS -- GitLab From 7b53f0be787c1f6d66693e5e61e1176e701d1a39 Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Thu, 15 Oct 2020 08:11:12 +0200 Subject: [PATCH 06/11] Import TagsType from pytools --- pytato/visualization.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytato/visualization.py b/pytato/visualization.py index da02fd8..0a616ae 100644 --- a/pytato/visualization.py +++ b/pytato/visualization.py @@ -33,10 +33,11 @@ from typing import Callable, Dict, Union, Iterator, List, Mapping from pytools import UniqueNameGenerator from pytools.codegen import CodeGenerator as CodeGeneratorBase +from pytools.tags import TagsType from pytato.array import ( Array, DictOfNamedArrays, IndexLambda, InputArgumentBase, - Stack, ShapeType, TagsType) + Stack, ShapeType) from pytato.codegen import normalize_outputs import pytato.transform -- GitLab From 09aca0035c25f55c3db4fa2420d35e5a1280c888 Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Thu, 15 Oct 2020 08:12:01 +0200 Subject: [PATCH 07/11] Fix path --- pytato/visualization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytato/visualization.py b/pytato/visualization.py index 0a616ae..76e9eff 100644 --- a/pytato/visualization.py +++ b/pytato/visualization.py @@ -33,7 +33,7 @@ from typing import Callable, Dict, Union, Iterator, List, Mapping from pytools import UniqueNameGenerator from pytools.codegen import CodeGenerator as CodeGeneratorBase -from pytools.tags import TagsType +from pytools.tag import TagsType from pytato.array import ( Array, DictOfNamedArrays, IndexLambda, InputArgumentBase, -- GitLab From 21c8c316eecc07ea6529e7158f85ab5d92d67971 Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Thu, 15 Oct 2020 08:18:47 +0200 Subject: [PATCH 08/11] Remove reference to DottedName from __init__.py --- pytato/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytato/__init__.py b/pytato/__init__.py index 0510394..64d1025 100644 --- a/pytato/__init__.py +++ b/pytato/__init__.py @@ -38,7 +38,7 @@ from pytato.target import Target, PyOpenCLTarget from pytato.visualization import get_dot_graph, show_dot_graph __all__ = ( - "DottedName", "Namespace", "Array", "DictOfNamedArrays", + "Namespace", "Array", "DictOfNamedArrays", "Placeholder", "IndexLambda", "make_dict_of_named_arrays", "make_placeholder", "make_size_param", -- GitLab From 28f8dbdbe233d52e6018de84009b8c442f8c7bed Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Thu, 15 Oct 2020 08:26:21 +0200 Subject: [PATCH 09/11] Restore accidentally deleted lines --- pytato/array.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pytato/array.py b/pytato/array.py index 64a94c0..2c5bcf0 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -130,6 +130,10 @@ canonicalize type references. Once Sphinx 4.0 is released, we should use the Should be referenced as :class:`pytato.Namespace`. +.. class:: Array + + Should be referenced as :class:`pytato.Array`. + .. class:: DictOfNamedArrays Should be referenced as :class:`pytato.DictOfNamedArrays`. -- GitLab From 86330d65ce9fe1beaa157e48381211e03f6f00ad Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Thu, 15 Oct 2020 08:29:58 +0200 Subject: [PATCH 10/11] Remove Tag and UniqueTag from docstring --- pytato/array.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pytato/array.py b/pytato/array.py index 2c5bcf0..b20590e 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -42,8 +42,6 @@ Array Interface .. autoclass:: Namespace .. autoclass:: Array -.. autoclass:: Tag -.. autoclass:: UniqueTag .. autoclass:: DictOfNamedArrays NumPy-Like Interface -- GitLab From bab77408d309f727201a506396c22f82f7f55217 Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Thu, 15 Oct 2020 08:37:55 +0200 Subject: [PATCH 11/11] Fully specify class --- pytato/array.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytato/array.py b/pytato/array.py index b20590e..c8a8775 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -370,7 +370,7 @@ class Array: .. attribute:: tags - A :class:`tuple` of :class:`Tag` instances. + A :class:`tuple` of :class:`pytools.tag.Tag` instances. Motivation: `RDF `__ @@ -525,7 +525,7 @@ class Array: def tagged(self, tag: Tag) -> Array: """ Returns a copy of *self* tagged with *tag*. - If *tag* is a :class:`UniqueTag` and other + If *tag* is a :class:`pytools.tag.UniqueTag` and other tags of this type are already present, an error is raised. """ -- GitLab