-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path__init__.py
186 lines (153 loc) · 6.43 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
"""
An array context is an abstraction that helps you dispatch between multiple
implementations of :mod:`numpy`-like :math:`n`-dimensional arrays.
"""
__copyright__ = """
Copyright (C) 2020-1 University of Illinois Board of Trustees
"""
__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import sys
from .context import (
ArrayContext,
Scalar, ScalarLike,
Array, ArrayT,
ArrayOrContainer, ArrayOrContainerT,
ArrayOrContainerOrScalar, ArrayOrContainerOrScalarT,
tag_axes)
from .transform_metadata import (CommonSubexpressionTag,
ElementwiseMapKernelTag)
# deprecated, remove in 2022.
from .metadata import _FirstAxisIsElementsTag
from .container import (
ArrayContainer, ArrayContainerT,
NotAnArrayContainerError,
is_array_container, is_array_container_type,
get_container_context_opt,
get_container_context_recursively, get_container_context_recursively_opt,
serialize_container, deserialize_container,
register_multivector_as_array_container)
from .container.arithmetic import with_container_arithmetic
from .container.dataclass import dataclass_array_container
from .container.traversal import (
map_array_container,
multimap_array_container,
rec_map_array_container,
rec_multimap_array_container,
mapped_over_array_containers,
multimapped_over_array_containers,
map_reduce_array_container,
multimap_reduce_array_container,
rec_map_reduce_array_container,
rec_multimap_reduce_array_container,
thaw, freeze,
flatten, unflatten, flat_size_and_dtype,
from_numpy, to_numpy,
outer, with_array_context)
from .impl.pyopencl import PyOpenCLArrayContext
from .impl.pytato import (PytatoPyOpenCLArrayContext,
PytatoJAXArrayContext)
from .impl.jax import EagerJAXArrayContext
from .impl.numpy import NumpyArrayContext
from .impl.torch import TorchArrayContext
from .pytest import (
PytestArrayContextFactory,
PytestPyOpenCLArrayContextFactory,
pytest_generate_tests_for_array_contexts,
pytest_generate_tests_for_pyopencl_array_context)
from .loopy import make_loopy_program
__all__ = (
"ArrayContext", "Scalar", "Array",
"Scalar", "ScalarLike",
"Array", "ArrayT",
"ArrayOrContainer", "ArrayOrContainerT",
"ArrayOrContainerOrScalar", "ArrayOrContainerOrScalarT",
"tag_axes",
"CommonSubexpressionTag",
"ElementwiseMapKernelTag",
"ArrayContainer", "ArrayContainerT",
"NotAnArrayContainerError",
"is_array_container", "is_array_container_type",
"get_container_context_opt",
"get_container_context_recursively_opt",
"get_container_context_recursively",
"serialize_container", "deserialize_container",
"register_multivector_as_array_container",
"with_container_arithmetic",
"dataclass_array_container",
"map_array_container", "multimap_array_container",
"rec_map_array_container", "rec_multimap_array_container",
"mapped_over_array_containers",
"multimapped_over_array_containers",
"map_reduce_array_container", "multimap_reduce_array_container",
"rec_map_reduce_array_container", "rec_multimap_reduce_array_container",
"thaw", "freeze",
"flatten", "unflatten", "flat_size_and_dtype",
"from_numpy", "to_numpy", "with_array_context",
"outer",
"PyOpenCLArrayContext", "PytatoPyOpenCLArrayContext",
"PytatoJAXArrayContext",
"EagerJAXArrayContext",
"NumpyArrayContext", "TorchArrayContext",
"make_loopy_program",
"PytestArrayContextFactory",
"PytestPyOpenCLArrayContextFactory",
"pytest_generate_tests_for_array_contexts",
"pytest_generate_tests_for_pyopencl_array_context"
)
# {{{ deprecation handling
def _deprecated_acf():
"""A tiny undocumented function to pass to tests that take an ``actx_factory``
argument when running them from the command line.
"""
import pyopencl as cl
context = cl._csc()
queue = cl.CommandQueue(context)
return PyOpenCLArrayContext(queue)
_depr_name_to_replacement_and_obj = {
"get_container_context": (
"get_container_context_opt",
get_container_context_opt, 2022),
"FirstAxisIsElementsTag": (
"meshmode.transform_metadata.FirstAxisIsElementsTag",
_FirstAxisIsElementsTag, 2022),
"_acf": ("<no replacement yet>", _deprecated_acf, 2022),
"DeviceArray": ("Array", Array, 2023),
"DeviceScalar": ("Scalar", Scalar, 2023),
}
if sys.version_info >= (3, 7):
def __getattr__(name):
replacement_and_obj = _depr_name_to_replacement_and_obj.get(name, None)
if replacement_and_obj is not None:
replacement, obj, year = replacement_and_obj
from warnings import warn
warn(f"'arraycontext.{name}' is deprecated. "
f"Use '{replacement}' instead. "
f"'arraycontext.{name}' will continue to work until {year}.",
DeprecationWarning, stacklevel=2)
return obj
else:
raise AttributeError(name)
else:
FirstAxisIsElementsTag = _FirstAxisIsElementsTag
_acf = _deprecated_acf
get_container_context = get_container_context_opt
DeviceArray = Array
DeviceScalar = Scalar
# }}}
# vim: foldmethod=marker