pyopencl 2025.2.5__cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyopencl might be problematic. Click here for more details.

Files changed (47) hide show
  1. pyopencl/.libs/libOpenCL-83a5a7fd.so.1.0.0 +0 -0
  2. pyopencl/__init__.py +1995 -0
  3. pyopencl/_cl.cpython-310-x86_64-linux-gnu.so +0 -0
  4. pyopencl/_cl.pyi +2006 -0
  5. pyopencl/_cluda.py +57 -0
  6. pyopencl/_monkeypatch.py +1069 -0
  7. pyopencl/_mymako.py +17 -0
  8. pyopencl/algorithm.py +1454 -0
  9. pyopencl/array.py +3441 -0
  10. pyopencl/bitonic_sort.py +245 -0
  11. pyopencl/bitonic_sort_templates.py +597 -0
  12. pyopencl/cache.py +535 -0
  13. pyopencl/capture_call.py +200 -0
  14. pyopencl/characterize/__init__.py +463 -0
  15. pyopencl/characterize/performance.py +240 -0
  16. pyopencl/cl/pyopencl-airy.cl +324 -0
  17. pyopencl/cl/pyopencl-bessel-j-complex.cl +238 -0
  18. pyopencl/cl/pyopencl-bessel-j.cl +1084 -0
  19. pyopencl/cl/pyopencl-bessel-y.cl +435 -0
  20. pyopencl/cl/pyopencl-complex.h +303 -0
  21. pyopencl/cl/pyopencl-eval-tbl.cl +120 -0
  22. pyopencl/cl/pyopencl-hankel-complex.cl +444 -0
  23. pyopencl/cl/pyopencl-random123/array.h +325 -0
  24. pyopencl/cl/pyopencl-random123/openclfeatures.h +93 -0
  25. pyopencl/cl/pyopencl-random123/philox.cl +486 -0
  26. pyopencl/cl/pyopencl-random123/threefry.cl +864 -0
  27. pyopencl/clmath.py +282 -0
  28. pyopencl/clrandom.py +412 -0
  29. pyopencl/cltypes.py +202 -0
  30. pyopencl/compyte/.gitignore +21 -0
  31. pyopencl/compyte/__init__.py +0 -0
  32. pyopencl/compyte/array.py +241 -0
  33. pyopencl/compyte/dtypes.py +316 -0
  34. pyopencl/compyte/pyproject.toml +52 -0
  35. pyopencl/elementwise.py +1178 -0
  36. pyopencl/invoker.py +417 -0
  37. pyopencl/ipython_ext.py +70 -0
  38. pyopencl/py.typed +0 -0
  39. pyopencl/reduction.py +815 -0
  40. pyopencl/scan.py +1916 -0
  41. pyopencl/tools.py +1565 -0
  42. pyopencl/typing.py +61 -0
  43. pyopencl/version.py +11 -0
  44. pyopencl-2025.2.5.dist-info/METADATA +109 -0
  45. pyopencl-2025.2.5.dist-info/RECORD +47 -0
  46. pyopencl-2025.2.5.dist-info/WHEEL +6 -0
  47. pyopencl-2025.2.5.dist-info/licenses/LICENSE +104 -0
@@ -0,0 +1,316 @@
1
+ """Type mapping helpers."""
2
+
3
+
4
+ __copyright__ = "Copyright (C) 2011 Andreas Kloeckner"
5
+
6
+ __license__ = """
7
+ Permission is hereby granted, free of charge, to any person
8
+ obtaining a copy of this software and associated documentation
9
+ files (the "Software"), to deal in the Software without
10
+ restriction, including without limitation the rights to use,
11
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the
13
+ Software is furnished to do so, subject to the following
14
+ conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26
+ OTHER DEALINGS IN THE SOFTWARE.
27
+ """
28
+
29
+ from collections.abc import Sequence
30
+ from typing import Any, Callable, TypeVar
31
+
32
+ import numpy as np
33
+ from numpy.typing import DTypeLike
34
+
35
+
36
+ class TypeNameNotKnown(RuntimeError): # noqa: N818
37
+ pass
38
+
39
+
40
+ # {{{ registry
41
+
42
+ class DTypeRegistry:
43
+ dtype_to_name: dict[np.dtype[Any] | str, str]
44
+ name_to_dtype: dict[str, np.dtype[Any]]
45
+
46
+ def __init__(self):
47
+ self.dtype_to_name = {}
48
+ self.name_to_dtype = {}
49
+
50
+ def get_or_register_dtype(self,
51
+ names: str | Sequence[str],
52
+ dtype: DTypeLike | None = None) -> np.dtype[Any]:
53
+ """Get or register a :class:`numpy.dtype` associated with the C type names
54
+ in the string list *c_names*. If *dtype* is `None`, no registration is
55
+ performed, and the :class:`numpy.dtype` must already have been registered.
56
+ If so, it is returned. If not, :exc:`TypeNameNotKnown` is raised.
57
+
58
+ If *dtype* is not `None`, registration is attempted. If the *c_names* are
59
+ already known and registered to identical :class:`numpy.dtype` objects,
60
+ then the previously dtype object of the previously registered type is
61
+ returned. If the *c_names* are not yet known, the type is registered. If
62
+ one of the *c_names* is known but registered to a different type, an error
63
+ is raised. In this latter case, the type may end up partially registered
64
+ and any further behavior is undefined.
65
+
66
+ .. versionadded:: 2012.2
67
+ """
68
+
69
+ if isinstance(names, str):
70
+ names = [names]
71
+
72
+ if dtype is None:
73
+ from pytools import single_valued
74
+ return single_valued(self.name_to_dtype[name] for name in names)
75
+
76
+ dtype = np.dtype(dtype)
77
+
78
+ # check if we've seen an identical dtype, if so retrieve exact dtype object.
79
+ try:
80
+ existing_name = self.dtype_to_name[dtype]
81
+ except KeyError:
82
+ existed = False
83
+ else:
84
+ existed = True
85
+ existing_dtype = self.name_to_dtype[existing_name]
86
+ assert existing_dtype == dtype
87
+ dtype = existing_dtype
88
+
89
+ for nm in names:
90
+ try:
91
+ name_dtype = self.name_to_dtype[nm]
92
+ except KeyError:
93
+ self.name_to_dtype[nm] = dtype
94
+ else:
95
+ if name_dtype != dtype:
96
+ raise RuntimeError(
97
+ f"name '{nm}' already registered to different dtype")
98
+
99
+ if not existed:
100
+ self.dtype_to_name[dtype] = names[0]
101
+ if str(dtype) not in self.dtype_to_name:
102
+ self.dtype_to_name[str(dtype)] = names[0]
103
+
104
+ return dtype
105
+
106
+ def dtype_to_ctype(self, dtype: DTypeLike) -> str:
107
+ if dtype is None:
108
+ raise ValueError("dtype may not be None")
109
+
110
+ dtype = np.dtype(dtype)
111
+
112
+ try:
113
+ return self.dtype_to_name[dtype]
114
+ except KeyError:
115
+ raise ValueError(f"unable to map dtype '{dtype}'") from None
116
+
117
+ # }}}
118
+
119
+
120
+ # {{{ C types
121
+
122
+ def fill_registry_with_c_types(
123
+ reg: DTypeRegistry,
124
+ respect_windows: bool,
125
+ include_bool: bool = True
126
+ ) -> None:
127
+ import struct
128
+ from sys import platform
129
+
130
+ if include_bool:
131
+ # bool is of unspecified size in the OpenCL spec and may in fact be
132
+ # 4-byte.
133
+ reg.get_or_register_dtype("bool", np.bool_)
134
+
135
+ reg.get_or_register_dtype(["signed char", "char"], np.int8)
136
+ reg.get_or_register_dtype("unsigned char", np.uint8)
137
+ reg.get_or_register_dtype(["short", "signed short",
138
+ "signed short int", "short signed int"], np.int16)
139
+ reg.get_or_register_dtype(["unsigned short",
140
+ "unsigned short int", "short unsigned int"], np.uint16)
141
+ reg.get_or_register_dtype(["int", "signed int"], np.int32)
142
+ reg.get_or_register_dtype(["unsigned", "unsigned int"], np.uint32)
143
+
144
+ is_64_bit = struct.calcsize("@P") * 8 == 64
145
+ if is_64_bit:
146
+ if "win32" in platform and respect_windows:
147
+ i64_name = "long long"
148
+ else:
149
+ i64_name = "long"
150
+
151
+ reg.get_or_register_dtype([
152
+ i64_name,
153
+ f"{i64_name} int",
154
+ f"signed {i64_name} int",
155
+ f"{i64_name} signed int"],
156
+ np.int64)
157
+ reg.get_or_register_dtype([
158
+ f"unsigned {i64_name}",
159
+ f"unsigned {i64_name} int",
160
+ f"{i64_name} unsigned int"],
161
+ np.uint64)
162
+
163
+ reg.get_or_register_dtype("float", np.float32)
164
+ reg.get_or_register_dtype("double", np.float64)
165
+
166
+
167
+ def fill_registry_with_opencl_c_types(reg: DTypeRegistry) -> None:
168
+ reg.get_or_register_dtype(["char", "signed char"], np.int8)
169
+ reg.get_or_register_dtype(["uchar", "unsigned char"], np.uint8)
170
+ reg.get_or_register_dtype(["short", "signed short",
171
+ "signed short int", "short signed int"], np.int16)
172
+ reg.get_or_register_dtype(["ushort", "unsigned short",
173
+ "unsigned short int", "short unsigned int"], np.uint16)
174
+ reg.get_or_register_dtype(["int", "signed int"], np.int32)
175
+ reg.get_or_register_dtype(["uint", "unsigned", "unsigned int"], np.uint32)
176
+
177
+ reg.get_or_register_dtype(
178
+ ["long", "long int", "signed long int",
179
+ "long signed int"],
180
+ np.int64)
181
+ reg.get_or_register_dtype(
182
+ ["ulong", "unsigned long", "unsigned long int",
183
+ "long unsigned int"],
184
+ np.uint64)
185
+
186
+ reg.get_or_register_dtype(["intptr_t"], np.intp)
187
+ reg.get_or_register_dtype(["uintptr_t"], np.uintp)
188
+
189
+ reg.get_or_register_dtype("float", np.float32)
190
+ reg.get_or_register_dtype("double", np.float64)
191
+
192
+
193
+ def fill_registry_with_c99_stdint_types(reg: DTypeRegistry) -> None:
194
+ reg.get_or_register_dtype("bool", np.bool_)
195
+
196
+ reg.get_or_register_dtype("int8_t", np.int8)
197
+ reg.get_or_register_dtype("uint8_t", np.uint8)
198
+ reg.get_or_register_dtype("int16_t", np.int16)
199
+ reg.get_or_register_dtype("uint16_t", np.uint16)
200
+ reg.get_or_register_dtype("int32_t", np.int32)
201
+ reg.get_or_register_dtype("uint32_t", np.uint32)
202
+ reg.get_or_register_dtype("int64_t", np.int64)
203
+ reg.get_or_register_dtype("uint64_t", np.uint64)
204
+ reg.get_or_register_dtype("uintptr_t", np.uintp)
205
+
206
+ reg.get_or_register_dtype("float", np.float32)
207
+ reg.get_or_register_dtype("double", np.float64)
208
+
209
+
210
+ def fill_registry_with_c99_complex_types(reg: DTypeRegistry) -> None:
211
+ reg.get_or_register_dtype("float complex", np.complex64)
212
+ reg.get_or_register_dtype("double complex", np.complex128)
213
+ reg.get_or_register_dtype("long double complex", np.clongdouble)
214
+
215
+ # }}}
216
+
217
+
218
+ # {{{ backward compatibility
219
+
220
+ TYPE_REGISTRY = DTypeRegistry()
221
+
222
+ # These are deprecated and should no longer be used
223
+ DTYPE_TO_NAME = TYPE_REGISTRY.dtype_to_name
224
+ NAME_TO_DTYPE = TYPE_REGISTRY.name_to_dtype
225
+
226
+ dtype_to_ctype = TYPE_REGISTRY.dtype_to_ctype
227
+ get_or_register_dtype = TYPE_REGISTRY.get_or_register_dtype
228
+
229
+
230
+ def _fill_dtype_registry(respect_windows, include_bool=True):
231
+ fill_registry_with_c_types(
232
+ TYPE_REGISTRY, respect_windows, include_bool)
233
+
234
+ # }}}
235
+
236
+
237
+ # {{{ c declarator parsing
238
+
239
+ ArgTypeT = TypeVar("ArgTypeT")
240
+
241
+
242
+ def parse_c_arg_backend(
243
+ c_arg: str,
244
+ scalar_arg_factory: Callable[[np.dtype[Any], str], ArgTypeT],
245
+ vec_arg_factory: Callable[[np.dtype[Any], str], ArgTypeT],
246
+ name_to_dtype: Callable[[str], np.dtype[Any]] | DTypeRegistry | None = None,
247
+ ):
248
+ if isinstance(name_to_dtype, DTypeRegistry):
249
+ name_to_dtype_clbl = name_to_dtype.name_to_dtype.__getitem__
250
+ elif name_to_dtype is None:
251
+ name_to_dtype_clbl = NAME_TO_DTYPE.__getitem__
252
+ else:
253
+ name_to_dtype_clbl = name_to_dtype
254
+
255
+ c_arg = (c_arg
256
+ .replace("const", "")
257
+ .replace("volatile", "")
258
+ .replace("__restrict__", "")
259
+ .replace("restrict", ""))
260
+
261
+ # process and remove declarator
262
+ import re
263
+ decl_re = re.compile(r"(\**)\s*([_a-zA-Z0-9]+)(\s*\[[ 0-9]*\])*\s*$")
264
+ decl_match = decl_re.search(c_arg)
265
+
266
+ if decl_match is None:
267
+ raise ValueError(f"couldn't parse C declarator '{c_arg}'")
268
+
269
+ name = decl_match.group(2)
270
+
271
+ if decl_match.group(1) or decl_match.group(3) is not None:
272
+ arg_class = vec_arg_factory
273
+ else:
274
+ arg_class = scalar_arg_factory
275
+
276
+ tp = c_arg[:decl_match.start()]
277
+ tp = " ".join(tp.split())
278
+
279
+ try:
280
+ dtype = name_to_dtype_clbl(tp)
281
+ except KeyError:
282
+ raise ValueError(f"unknown type '{tp}'") from None
283
+
284
+ return arg_class(dtype, name)
285
+
286
+ # }}}
287
+
288
+
289
+ def register_dtype(
290
+ dtype: DTypeLike,
291
+ c_names: Sequence[str] | str,
292
+ alias_ok: bool = False
293
+ ) -> None:
294
+ from warnings import warn
295
+ warn("register_dtype is deprecated. Use get_or_register_dtype instead.",
296
+ DeprecationWarning, stacklevel=2)
297
+
298
+ if isinstance(c_names, str):
299
+ c_names = [c_names]
300
+
301
+ dtype = np.dtype(dtype)
302
+
303
+ # check if we've seen this dtype before and error out if a) it was seen before
304
+ # and b) alias_ok is False.
305
+
306
+ name = TYPE_REGISTRY.dtype_to_name.get(dtype)
307
+ if not alias_ok and name is not None:
308
+ c_names_join = "', '".join(c_names)
309
+ raise RuntimeError(
310
+ f"dtype '{dtype}' already registered "
311
+ f"(as '{name}', new names '{c_names_join}')")
312
+
313
+ TYPE_REGISTRY.get_or_register_dtype(c_names, dtype)
314
+
315
+
316
+ # vim: foldmethod=marker
@@ -0,0 +1,52 @@
1
+ [tool.ruff]
2
+ preview = true
3
+
4
+ [tool.ruff.lint]
5
+ extend-select = [
6
+ "B", # flake8-bugbear
7
+ "C", # flake8-comprehensions
8
+ "E", # pycodestyle
9
+ "F", # pyflakes
10
+ "I", # flake8-isort
11
+ "N", # pep8-naming
12
+ "NPY", # numpy
13
+ "Q", # flake8-quotes
14
+ "RUF", # ruff
15
+ "UP", # pyupgrade
16
+ "W", # pycodestyle
17
+ ]
18
+ extend-ignore = [
19
+ "C90", # McCabe complexity
20
+ "E402", # module level import not at the top of file
21
+ "E226", # missing whitespace around operator
22
+ ]
23
+
24
+ [tool.ruff.lint.flake8-quotes]
25
+ docstring-quotes = "double"
26
+ inline-quotes = "double"
27
+ multiline-quotes = "double"
28
+
29
+ [tool.ruff.lint.isort]
30
+ combine-as-imports = true
31
+ known-first-party = [
32
+ "pytools",
33
+ ]
34
+ lines-after-imports = 2
35
+
36
+
37
+ [tool.basedpyright]
38
+ reportImplicitStringConcatenation = "none"
39
+ reportUnnecessaryIsInstance = "none"
40
+ reportUnusedCallResult = "none"
41
+ reportExplicitAny = "none"
42
+ reportUnreachable = "hint"
43
+ # array.py looks like stdlib array, but pyright doesn't know this
44
+ # won't ever be a top-level anything.
45
+ reportShadowedImports = "none"
46
+
47
+ # This reports even cycles that are qualified by 'if TYPE_CHECKING'. Not what
48
+ # we care about at this moment.
49
+ # https://github.com/microsoft/pyright/issues/746
50
+ reportImportCycles = "none"
51
+ pythonVersion = "3.10"
52
+ pythonPlatform = "All"