pyopencl 2025.2.7__cp314-cp314t-musllinux_1_2_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-4a7ed9fc.so.1.0.0 +0 -0
  2. pyopencl/__init__.py +1995 -0
  3. pyopencl/_cl.cpython-314t-x86_64-linux-musl.so +0 -0
  4. pyopencl/_cl.pyi +2009 -0
  5. pyopencl/_cluda.py +57 -0
  6. pyopencl/_monkeypatch.py +1104 -0
  7. pyopencl/_mymako.py +17 -0
  8. pyopencl/algorithm.py +1454 -0
  9. pyopencl/array.py +3530 -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 +461 -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 +281 -0
  28. pyopencl/clrandom.py +412 -0
  29. pyopencl/cltypes.py +217 -0
  30. pyopencl/compyte/.gitignore +21 -0
  31. pyopencl/compyte/__init__.py +0 -0
  32. pyopencl/compyte/array.py +211 -0
  33. pyopencl/compyte/dtypes.py +314 -0
  34. pyopencl/compyte/pyproject.toml +49 -0
  35. pyopencl/elementwise.py +1288 -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 +1921 -0
  41. pyopencl/tools.py +1680 -0
  42. pyopencl/typing.py +61 -0
  43. pyopencl/version.py +11 -0
  44. pyopencl-2025.2.7.dist-info/METADATA +108 -0
  45. pyopencl-2025.2.7.dist-info/RECORD +47 -0
  46. pyopencl-2025.2.7.dist-info/WHEEL +5 -0
  47. pyopencl-2025.2.7.dist-info/licenses/LICENSE +104 -0
@@ -0,0 +1,314 @@
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 Callable, Sequence
30
+ from typing import Any, 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
+ def __init__(self) -> None:
44
+ self.dtype_to_name: dict[np.dtype[Any] | str, str] = {}
45
+ self.name_to_dtype: dict[str, np.dtype[Any]] = {}
46
+
47
+ def get_or_register_dtype(
48
+ self,
49
+ names: str | Sequence[str],
50
+ dtype: DTypeLike | None = None) -> np.dtype[Any]:
51
+ """Get or register a :class:`numpy.dtype` associated with the C type names
52
+ in the string list *c_names*. If *dtype* is `None`, no registration is
53
+ performed, and the :class:`numpy.dtype` must already have been registered.
54
+ If so, it is returned. If not, :exc:`TypeNameNotKnown` is raised.
55
+
56
+ If *dtype* is not `None`, registration is attempted. If the *c_names* are
57
+ already known and registered to identical :class:`numpy.dtype` objects,
58
+ then the previously dtype object of the previously registered type is
59
+ returned. If the *c_names* are not yet known, the type is registered. If
60
+ one of the *c_names* is known but registered to a different type, an error
61
+ is raised. In this latter case, the type may end up partially registered
62
+ and any further behavior is undefined.
63
+
64
+ .. versionadded:: 2012.2
65
+ """
66
+
67
+ if isinstance(names, str):
68
+ names = [names]
69
+
70
+ if dtype is None:
71
+ from pytools import single_valued
72
+ return single_valued(self.name_to_dtype[name] for name in names)
73
+
74
+ dtype = np.dtype(dtype)
75
+
76
+ # check if we've seen an identical dtype, if so retrieve exact dtype object.
77
+ try:
78
+ existing_name = self.dtype_to_name[dtype]
79
+ except KeyError:
80
+ existed = False
81
+ else:
82
+ existed = True
83
+ existing_dtype = self.name_to_dtype[existing_name]
84
+ assert existing_dtype == dtype
85
+ dtype = existing_dtype
86
+
87
+ for nm in names:
88
+ try:
89
+ name_dtype = self.name_to_dtype[nm]
90
+ except KeyError:
91
+ self.name_to_dtype[nm] = dtype
92
+ else:
93
+ if name_dtype != dtype:
94
+ raise RuntimeError(
95
+ f"name '{nm}' already registered to different dtype")
96
+
97
+ if not existed:
98
+ self.dtype_to_name[dtype] = names[0]
99
+ if str(dtype) not in self.dtype_to_name:
100
+ self.dtype_to_name[str(dtype)] = names[0]
101
+
102
+ return dtype
103
+
104
+ def dtype_to_ctype(self, dtype: DTypeLike) -> str:
105
+ if dtype is None:
106
+ raise ValueError("dtype may not be None")
107
+
108
+ dtype = np.dtype(dtype)
109
+
110
+ try:
111
+ return self.dtype_to_name[dtype]
112
+ except KeyError:
113
+ raise ValueError(f"unable to map dtype '{dtype}'") from None
114
+
115
+ # }}}
116
+
117
+
118
+ # {{{ C types
119
+
120
+ def fill_registry_with_c_types(
121
+ reg: DTypeRegistry,
122
+ respect_windows: bool,
123
+ include_bool: bool = True
124
+ ) -> None:
125
+ import struct
126
+ from sys import platform
127
+
128
+ if include_bool:
129
+ # bool is of unspecified size in the OpenCL spec and may in fact be
130
+ # 4-byte.
131
+ reg.get_or_register_dtype("bool", np.bool_)
132
+
133
+ reg.get_or_register_dtype(["signed char", "char"], np.int8)
134
+ reg.get_or_register_dtype("unsigned char", np.uint8)
135
+ reg.get_or_register_dtype(["short", "signed short",
136
+ "signed short int", "short signed int"], np.int16)
137
+ reg.get_or_register_dtype(["unsigned short",
138
+ "unsigned short int", "short unsigned int"], np.uint16)
139
+ reg.get_or_register_dtype(["int", "signed int"], np.int32)
140
+ reg.get_or_register_dtype(["unsigned", "unsigned int"], np.uint32)
141
+
142
+ is_64_bit = struct.calcsize("@P") * 8 == 64
143
+ if is_64_bit:
144
+ if "win32" in platform and respect_windows:
145
+ i64_name = "long long"
146
+ else:
147
+ i64_name = "long"
148
+
149
+ reg.get_or_register_dtype([
150
+ i64_name,
151
+ f"{i64_name} int",
152
+ f"signed {i64_name} int",
153
+ f"{i64_name} signed int"],
154
+ np.int64)
155
+ reg.get_or_register_dtype([
156
+ f"unsigned {i64_name}",
157
+ f"unsigned {i64_name} int",
158
+ f"{i64_name} unsigned int"],
159
+ np.uint64)
160
+
161
+ reg.get_or_register_dtype("float", np.float32)
162
+ reg.get_or_register_dtype("double", np.float64)
163
+
164
+
165
+ def fill_registry_with_opencl_c_types(reg: DTypeRegistry) -> None:
166
+ reg.get_or_register_dtype(["char", "signed char"], np.int8)
167
+ reg.get_or_register_dtype(["uchar", "unsigned char"], np.uint8)
168
+ reg.get_or_register_dtype(["short", "signed short",
169
+ "signed short int", "short signed int"], np.int16)
170
+ reg.get_or_register_dtype(["ushort", "unsigned short",
171
+ "unsigned short int", "short unsigned int"], np.uint16)
172
+ reg.get_or_register_dtype(["int", "signed int"], np.int32)
173
+ reg.get_or_register_dtype(["uint", "unsigned", "unsigned int"], np.uint32)
174
+
175
+ reg.get_or_register_dtype(
176
+ ["long", "long int", "signed long int",
177
+ "long signed int"],
178
+ np.int64)
179
+ reg.get_or_register_dtype(
180
+ ["ulong", "unsigned long", "unsigned long int",
181
+ "long unsigned int"],
182
+ np.uint64)
183
+
184
+ reg.get_or_register_dtype(["intptr_t"], np.intp)
185
+ reg.get_or_register_dtype(["uintptr_t"], np.uintp)
186
+
187
+ reg.get_or_register_dtype("float", np.float32)
188
+ reg.get_or_register_dtype("double", np.float64)
189
+
190
+
191
+ def fill_registry_with_c99_stdint_types(reg: DTypeRegistry) -> None:
192
+ reg.get_or_register_dtype("bool", np.bool_)
193
+
194
+ reg.get_or_register_dtype("int8_t", np.int8)
195
+ reg.get_or_register_dtype("uint8_t", np.uint8)
196
+ reg.get_or_register_dtype("int16_t", np.int16)
197
+ reg.get_or_register_dtype("uint16_t", np.uint16)
198
+ reg.get_or_register_dtype("int32_t", np.int32)
199
+ reg.get_or_register_dtype("uint32_t", np.uint32)
200
+ reg.get_or_register_dtype("int64_t", np.int64)
201
+ reg.get_or_register_dtype("uint64_t", np.uint64)
202
+ reg.get_or_register_dtype("uintptr_t", np.uintp)
203
+
204
+ reg.get_or_register_dtype("float", np.float32)
205
+ reg.get_or_register_dtype("double", np.float64)
206
+
207
+
208
+ def fill_registry_with_c99_complex_types(reg: DTypeRegistry) -> None:
209
+ reg.get_or_register_dtype("float complex", np.complex64)
210
+ reg.get_or_register_dtype("double complex", np.complex128)
211
+ reg.get_or_register_dtype("long double complex", np.clongdouble)
212
+
213
+ # }}}
214
+
215
+
216
+ # {{{ backward compatibility
217
+
218
+ TYPE_REGISTRY = DTypeRegistry()
219
+
220
+ # These are deprecated and should no longer be used
221
+ DTYPE_TO_NAME = TYPE_REGISTRY.dtype_to_name
222
+ NAME_TO_DTYPE = TYPE_REGISTRY.name_to_dtype
223
+
224
+ dtype_to_ctype = TYPE_REGISTRY.dtype_to_ctype
225
+ get_or_register_dtype = TYPE_REGISTRY.get_or_register_dtype
226
+
227
+
228
+ def _fill_dtype_registry(respect_windows: bool, include_bool: bool = True) -> None:
229
+ fill_registry_with_c_types(
230
+ TYPE_REGISTRY, respect_windows, include_bool)
231
+
232
+ # }}}
233
+
234
+
235
+ # {{{ c declarator parsing
236
+
237
+ ArgTypeT = TypeVar("ArgTypeT")
238
+
239
+
240
+ def parse_c_arg_backend(
241
+ c_arg: str,
242
+ scalar_arg_factory: Callable[[np.dtype[Any], str], ArgTypeT],
243
+ vec_arg_factory: Callable[[np.dtype[Any], str], ArgTypeT],
244
+ name_to_dtype: Callable[[str], np.dtype[Any]] | DTypeRegistry | None = None,
245
+ ) -> ArgTypeT:
246
+ if isinstance(name_to_dtype, DTypeRegistry):
247
+ name_to_dtype_clbl = name_to_dtype.name_to_dtype.__getitem__
248
+ elif name_to_dtype is None:
249
+ name_to_dtype_clbl = NAME_TO_DTYPE.__getitem__
250
+ else:
251
+ name_to_dtype_clbl = name_to_dtype
252
+
253
+ c_arg = (c_arg
254
+ .replace("const", "")
255
+ .replace("volatile", "")
256
+ .replace("__restrict__", "")
257
+ .replace("restrict", ""))
258
+
259
+ # process and remove declarator
260
+ import re
261
+ decl_re = re.compile(r"(\**)\s*([_a-zA-Z0-9]+)(\s*\[[ 0-9]*\])*\s*$")
262
+ decl_match = decl_re.search(c_arg)
263
+
264
+ if decl_match is None:
265
+ raise ValueError(f"couldn't parse C declarator '{c_arg}'")
266
+
267
+ name = decl_match.group(2)
268
+
269
+ if decl_match.group(1) or decl_match.group(3) is not None:
270
+ arg_class = vec_arg_factory
271
+ else:
272
+ arg_class = scalar_arg_factory
273
+
274
+ tp = c_arg[:decl_match.start()]
275
+ tp = " ".join(tp.split())
276
+
277
+ try:
278
+ dtype = name_to_dtype_clbl(tp)
279
+ except KeyError:
280
+ raise ValueError(f"unknown type '{tp}'") from None
281
+
282
+ return arg_class(dtype, name)
283
+
284
+ # }}}
285
+
286
+
287
+ def register_dtype(
288
+ dtype: DTypeLike,
289
+ c_names: Sequence[str] | str,
290
+ alias_ok: bool = False
291
+ ) -> None:
292
+ from warnings import warn
293
+ warn("register_dtype is deprecated. Use get_or_register_dtype instead.",
294
+ DeprecationWarning, stacklevel=2)
295
+
296
+ if isinstance(c_names, str):
297
+ c_names = [c_names]
298
+
299
+ dtype = np.dtype(dtype)
300
+
301
+ # check if we've seen this dtype before and error out if a) it was seen before
302
+ # and b) alias_ok is False.
303
+
304
+ name = TYPE_REGISTRY.dtype_to_name.get(dtype)
305
+ if not alias_ok and name is not None:
306
+ c_names_join = "', '".join(c_names)
307
+ raise RuntimeError(
308
+ f"dtype '{dtype}' already registered "
309
+ f"(as '{name}', new names '{c_names_join}')")
310
+
311
+ TYPE_REGISTRY.get_or_register_dtype(c_names, dtype)
312
+
313
+
314
+ # vim: foldmethod=marker
@@ -0,0 +1,49 @@
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
+
44
+ # This reports even cycles that are qualified by 'if TYPE_CHECKING'. Not what
45
+ # we care about at this moment.
46
+ # https://github.com/microsoft/pyright/issues/746
47
+ reportImportCycles = "none"
48
+ pythonVersion = "3.10"
49
+ pythonPlatform = "All"