diff --git a/pytato/__init__.py b/pytato/__init__.py index d65fefcc8dbb71f20edbae81a4ed6cca0940b0f2..64d10257b721f74327bd28ad5c1596c6c500293c 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, @@ -39,8 +38,8 @@ from pytato.target import Target, PyOpenCLTarget from pytato.visualization import get_dot_graph, show_dot_graph __all__ = ( - "DottedName", "Namespace", "Array", "DictOfNamedArrays", - "Tag", "UniqueTag", "Placeholder", "IndexLambda", + "Namespace", "Array", "DictOfNamedArrays", + "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 1b5406f163b444070f0eaf1435e4a899f29470eb..c8a8775f749809a039634a0e2858788b41dd1275 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 @@ -60,8 +58,6 @@ These functions generally follow the interface of the corresponding functions in Supporting Functionality ------------------------ -.. autoclass:: DottedName - .. currentmodule:: pytato.array Concrete Array Data @@ -132,14 +128,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`. @@ -154,15 +142,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 +from pytools.tag import Tag, UniqueTag, TagsType, tag_dataclass import pytato.scalar_expr as scalar_expr from pytato.scalar_expr import ScalarExpression @@ -181,47 +169,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 +245,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, ...] @@ -470,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 `__ @@ -625,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. """ diff --git a/pytato/version.py b/pytato/version.py index c5f841e4d793717349cf4c91b5091985bea7363b..1e45d8711444a469a9e7d93c65aa325746f83613 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 diff --git a/pytato/visualization.py b/pytato/visualization.py index da02fd848817b1da3b152273e067210c4305a546..76e9effd10c8bd5dfdfa2d811656d5e5745aa54f 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.tag import TagsType from pytato.array import ( Array, DictOfNamedArrays, IndexLambda, InputArgumentBase, - Stack, ShapeType, TagsType) + Stack, ShapeType) from pytato.codegen import normalize_outputs import pytato.transform diff --git a/setup.py b/setup.py index 094aa6e632b101742659c7b3619a440a8bf77ef3..2bae77aaeb9148f230fa3ea502a73d0d77023414 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",