pyopencl 2025.1__cp313-cp313-macosx_11_0_arm64.whl → 2025.2.2__cp313-cp313-macosx_11_0_arm64.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.

pyopencl/_mymako.py CHANGED
@@ -1,3 +1,6 @@
1
+ from __future__ import annotations
2
+
3
+
1
4
  try:
2
5
  import mako.template # noqa: F401
3
6
  except ImportError as err:
pyopencl/algorithm.py CHANGED
@@ -1,4 +1,5 @@
1
1
  """Algorithms built on scans."""
2
+ from __future__ import annotations
2
3
 
3
4
 
4
5
  __copyright__ = """
@@ -30,7 +31,7 @@ OTHER DEALINGS IN THE SOFTWARE.
30
31
  """
31
32
 
32
33
  from dataclasses import dataclass
33
- from typing import Optional
34
+ from typing import TYPE_CHECKING
34
35
 
35
36
  import numpy as np
36
37
  from mako.template import Template
@@ -38,12 +39,15 @@ from mako.template import Template
38
39
  from pytools import memoize, memoize_method
39
40
 
40
41
  import pyopencl as cl
41
- import pyopencl.array
42
- from pyopencl.elementwise import ElementwiseKernel
42
+ import pyopencl.array as cl_array
43
43
  from pyopencl.scan import GenericScanKernel, ScanTemplate
44
44
  from pyopencl.tools import dtype_to_ctype, get_arg_offset_adjuster_code
45
45
 
46
46
 
47
+ if TYPE_CHECKING:
48
+ from pyopencl.elementwise import ElementwiseKernel
49
+
50
+
47
51
  # {{{ "extra args" handling utility
48
52
 
49
53
  def _extract_extra_args_types_values(extra_args):
@@ -55,7 +59,7 @@ def _extract_extra_args_types_values(extra_args):
55
59
  extra_args_values = []
56
60
  extra_wait_for = []
57
61
  for name, val in extra_args:
58
- if isinstance(val, cl.array.Array):
62
+ if isinstance(val, cl_array.Array):
59
63
  extra_args_types.append(VectorArg(val.dtype, name, with_offset=False))
60
64
  extra_args_values.append(val)
61
65
  extra_wait_for.extend(val.events)
@@ -117,7 +121,7 @@ def copy_if(ary, predicate, extra_args=None, preamble="", queue=None, wait_for=N
117
121
  type_aliases=(("scan_t", scan_dtype), ("item_t", ary.dtype)),
118
122
  var_values=(("predicate", predicate),),
119
123
  more_preamble=preamble, more_arguments=extra_args_types)
120
- out = cl.array.empty_like(ary)
124
+ out = cl_array.empty_like(ary)
121
125
  count = ary._new_with_changes(data=None, offset=0,
122
126
  shape=(), strides=(), dtype=scan_dtype)
123
127
 
@@ -207,8 +211,8 @@ def partition(ary, predicate, extra_args=None, preamble="",
207
211
  var_values=(("predicate", predicate),),
208
212
  more_preamble=preamble, more_arguments=extra_args_types)
209
213
 
210
- out_true = cl.array.empty_like(ary)
211
- out_false = cl.array.empty_like(ary)
214
+ out_true = cl_array.empty_like(ary)
215
+ out_false = cl_array.empty_like(ary)
212
216
  count = ary._new_with_changes(data=None, offset=0,
213
217
  shape=(), strides=(), dtype=scan_dtype)
214
218
 
@@ -279,7 +283,7 @@ def unique(ary, is_equal_expr="a == b", extra_args=None, preamble="",
279
283
  var_values=(("macro_is_equal_expr", is_equal_expr),),
280
284
  more_preamble=preamble, more_arguments=extra_args_types)
281
285
 
282
- out = cl.array.empty_like(ary)
286
+ out = cl_array.empty_like(ary)
283
287
  count = ary._new_with_changes(data=None, offset=0,
284
288
  shape=(), strides=(), dtype=scan_dtype)
285
289
 
@@ -556,7 +560,7 @@ class RadixSort:
556
560
  base_bit = 0
557
561
  while base_bit < key_bits:
558
562
  sorted_args = [
559
- cl.array.empty(queue, n, arg_descr.dtype, allocator=allocator)
563
+ cl_array.empty(queue, n, arg_descr.dtype, allocator=allocator)
560
564
  for arg_descr in self.arguments
561
565
  if arg_descr.name in self.sort_arg_names]
562
566
 
@@ -574,7 +578,7 @@ class RadixSort:
574
578
  base_bit += self.bits
575
579
 
576
580
  return [arg_val
577
- for arg_descr, arg_val in zip(self.arguments, args)
581
+ for arg_descr, arg_val in zip(self.arguments, args, strict=True)
578
582
  if arg_descr.name in self.sort_arg_names], last_evt
579
583
 
580
584
  # }}}
@@ -725,12 +729,12 @@ def _get_arg_list(arg_list, prefix=""):
725
729
 
726
730
  @dataclass
727
731
  class BuiltList:
728
- count: Optional[int]
729
- starts: Optional[pyopencl.array.Array]
730
- lists: Optional[pyopencl.array.Array] = None
731
- num_nonempty_lists: Optional[int] = None
732
- nonempty_indices: Optional[pyopencl.array.Array] = None
733
- compressed_indices: Optional[pyopencl.array.Array] = None
732
+ count: int | None
733
+ starts: cl_array.Array | None
734
+ lists: cl_array.Array | None = None
735
+ num_nonempty_lists: int | None = None
736
+ nonempty_indices: cl_array.Array | None = None
737
+ compressed_indices: cl_array.Array | None = None
734
738
 
735
739
 
736
740
  class ListOfListsBuilder:
@@ -1139,7 +1143,8 @@ class ListOfListsBuilder:
1139
1143
  compress_kernel = self.get_compress_kernel(index_dtype)
1140
1144
 
1141
1145
  data_args = []
1142
- for i, (arg_descr, arg_val) in enumerate(zip(self.arg_decls, args)):
1146
+ for i, (arg_descr, arg_val) in enumerate(
1147
+ zip(self.arg_decls, args, strict=True)):
1143
1148
  from pyopencl.tools import VectorArg
1144
1149
  if isinstance(arg_descr, VectorArg):
1145
1150
  from pyopencl import MemoryObject
@@ -1179,7 +1184,7 @@ class ListOfListsBuilder:
1179
1184
  count_list_args.append(None)
1180
1185
  continue
1181
1186
 
1182
- counts = cl.array.empty(queue,
1187
+ counts = cl_array.empty(queue,
1183
1188
  (n_objects + 1), index_dtype, allocator=allocator)
1184
1189
  counts[-1] = 0
1185
1190
  wait_for = wait_for + counts.events
@@ -1219,14 +1224,14 @@ class ListOfListsBuilder:
1219
1224
  if name not in self.eliminate_empty_output_lists:
1220
1225
  continue
1221
1226
 
1222
- compressed_counts = cl.array.empty(
1227
+ compressed_counts = cl_array.empty(
1223
1228
  queue, (n_objects + 1,), index_dtype, allocator=allocator)
1224
1229
  info_record = result[name]
1225
- info_record.nonempty_indices = cl.array.empty(
1230
+ info_record.nonempty_indices = cl_array.empty(
1226
1231
  queue, (n_objects + 1,), index_dtype, allocator=allocator)
1227
- info_record.num_nonempty_lists = cl.array.empty(
1232
+ info_record.num_nonempty_lists = cl_array.empty(
1228
1233
  queue, (1,), index_dtype, allocator=allocator)
1229
- info_record.compressed_indices = cl.array.empty(
1234
+ info_record.compressed_indices = cl_array.empty(
1230
1235
  queue, (n_objects + 1,), index_dtype, allocator=allocator)
1231
1236
  info_record.compressed_indices[0] = 0
1232
1237
 
@@ -1301,7 +1306,7 @@ class ListOfListsBuilder:
1301
1306
  else:
1302
1307
  info_record = result[name]
1303
1308
 
1304
- info_record.lists = cl.array.empty(queue,
1309
+ info_record.lists = cl_array.empty(queue,
1305
1310
  info_record.count, dtype, allocator=allocator)
1306
1311
  write_list_args.append(info_record.lists.data)
1307
1312
 
@@ -1431,7 +1436,7 @@ class KeyValueSorter:
1431
1436
  (values_sorted_by_key, keys_sorted_by_key), evt = knl_info.by_target_sorter(
1432
1437
  values, keys, queue=queue, wait_for=wait_for)
1433
1438
 
1434
- starts = (cl.array.empty(queue, (nkeys+1), starts_dtype, allocator=allocator)
1439
+ starts = (cl_array.empty(queue, (nkeys+1), starts_dtype, allocator=allocator)
1435
1440
  .fill(len(values_sorted_by_key), wait_for=[evt]))
1436
1441
  evt, = starts.events
1437
1442