pyopencl 2024.2.2__cp38-cp38-macosx_11_0_arm64.whl → 2024.2.4__cp38-cp38-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.

Files changed (102) hide show
  1. pyopencl/__init__.py +16 -4
  2. pyopencl/_cl.cpython-38-darwin.so +0 -0
  3. pyopencl/algorithm.py +3 -1
  4. pyopencl/bitonic_sort.py +2 -0
  5. pyopencl/characterize/__init__.py +23 -0
  6. pyopencl/compyte/.git +1 -0
  7. pyopencl/compyte/.github/workflows/autopush.yml +21 -0
  8. pyopencl/compyte/.github/workflows/ci.yml +30 -0
  9. pyopencl/compyte/.gitignore +21 -0
  10. pyopencl/compyte/ndarray/Makefile +31 -0
  11. pyopencl/compyte/ndarray/gpu_ndarray.h +35 -0
  12. pyopencl/compyte/ndarray/pygpu_language.h +207 -0
  13. pyopencl/compyte/ndarray/pygpu_language_cuda.cu +622 -0
  14. pyopencl/compyte/ndarray/pygpu_language_opencl.cpp +317 -0
  15. pyopencl/compyte/ndarray/pygpu_ndarray.cpp +1546 -0
  16. pyopencl/compyte/ndarray/pygpu_ndarray.h +71 -0
  17. pyopencl/compyte/ndarray/pygpu_ndarray_object.h +232 -0
  18. pyopencl/compyte/setup.cfg +9 -0
  19. pyopencl/tools.py +60 -56
  20. pyopencl/version.py +7 -3
  21. {pyopencl-2024.2.2.dist-info → pyopencl-2024.2.4.dist-info}/METADATA +14 -14
  22. pyopencl-2024.2.4.dist-info/RECORD +59 -0
  23. {pyopencl-2024.2.2.dist-info → pyopencl-2024.2.4.dist-info}/WHEEL +1 -1
  24. pyopencl-2024.2.2.data/data/CITATION.cff +0 -74
  25. pyopencl-2024.2.2.data/data/CMakeLists.txt +0 -83
  26. pyopencl-2024.2.2.data/data/Makefile.in +0 -21
  27. pyopencl-2024.2.2.data/data/README.rst +0 -70
  28. pyopencl-2024.2.2.data/data/README_SETUP.txt +0 -34
  29. pyopencl-2024.2.2.data/data/aksetup_helper.py +0 -1013
  30. pyopencl-2024.2.2.data/data/configure.py +0 -6
  31. pyopencl-2024.2.2.data/data/contrib/cldis.py +0 -91
  32. pyopencl-2024.2.2.data/data/contrib/fortran-to-opencl/README +0 -29
  33. pyopencl-2024.2.2.data/data/contrib/fortran-to-opencl/translate.py +0 -1441
  34. pyopencl-2024.2.2.data/data/contrib/pyopencl.vim +0 -84
  35. pyopencl-2024.2.2.data/data/doc/Makefile +0 -23
  36. pyopencl-2024.2.2.data/data/doc/algorithm.rst +0 -214
  37. pyopencl-2024.2.2.data/data/doc/array.rst +0 -305
  38. pyopencl-2024.2.2.data/data/doc/conf.py +0 -26
  39. pyopencl-2024.2.2.data/data/doc/howto.rst +0 -105
  40. pyopencl-2024.2.2.data/data/doc/index.rst +0 -137
  41. pyopencl-2024.2.2.data/data/doc/make_constants.py +0 -561
  42. pyopencl-2024.2.2.data/data/doc/misc.rst +0 -885
  43. pyopencl-2024.2.2.data/data/doc/runtime.rst +0 -51
  44. pyopencl-2024.2.2.data/data/doc/runtime_const.rst +0 -30
  45. pyopencl-2024.2.2.data/data/doc/runtime_gl.rst +0 -78
  46. pyopencl-2024.2.2.data/data/doc/runtime_memory.rst +0 -527
  47. pyopencl-2024.2.2.data/data/doc/runtime_platform.rst +0 -184
  48. pyopencl-2024.2.2.data/data/doc/runtime_program.rst +0 -364
  49. pyopencl-2024.2.2.data/data/doc/runtime_queue.rst +0 -182
  50. pyopencl-2024.2.2.data/data/doc/subst.rst +0 -36
  51. pyopencl-2024.2.2.data/data/doc/tools.rst +0 -4
  52. pyopencl-2024.2.2.data/data/doc/types.rst +0 -42
  53. pyopencl-2024.2.2.data/data/examples/black-hole-accretion.py +0 -2227
  54. pyopencl-2024.2.2.data/data/examples/demo-struct-reduce.py +0 -75
  55. pyopencl-2024.2.2.data/data/examples/demo.py +0 -39
  56. pyopencl-2024.2.2.data/data/examples/demo_array.py +0 -32
  57. pyopencl-2024.2.2.data/data/examples/demo_array_svm.py +0 -37
  58. pyopencl-2024.2.2.data/data/examples/demo_elementwise.py +0 -34
  59. pyopencl-2024.2.2.data/data/examples/demo_elementwise_complex.py +0 -53
  60. pyopencl-2024.2.2.data/data/examples/demo_mandelbrot.py +0 -183
  61. pyopencl-2024.2.2.data/data/examples/demo_meta_codepy.py +0 -56
  62. pyopencl-2024.2.2.data/data/examples/demo_meta_template.py +0 -55
  63. pyopencl-2024.2.2.data/data/examples/dump-performance.py +0 -38
  64. pyopencl-2024.2.2.data/data/examples/dump-properties.py +0 -86
  65. pyopencl-2024.2.2.data/data/examples/gl_interop_demo.py +0 -84
  66. pyopencl-2024.2.2.data/data/examples/gl_particle_animation.py +0 -218
  67. pyopencl-2024.2.2.data/data/examples/ipython-demo.ipynb +0 -203
  68. pyopencl-2024.2.2.data/data/examples/median-filter.py +0 -99
  69. pyopencl-2024.2.2.data/data/examples/n-body.py +0 -1070
  70. pyopencl-2024.2.2.data/data/examples/narray.py +0 -37
  71. pyopencl-2024.2.2.data/data/examples/noisyImage.jpg +0 -0
  72. pyopencl-2024.2.2.data/data/examples/pi-monte-carlo.py +0 -1166
  73. pyopencl-2024.2.2.data/data/examples/svm.py +0 -82
  74. pyopencl-2024.2.2.data/data/examples/transpose.py +0 -229
  75. pyopencl-2024.2.2.data/data/pytest.ini +0 -3
  76. pyopencl-2024.2.2.data/data/src/bitlog.cpp +0 -51
  77. pyopencl-2024.2.2.data/data/src/bitlog.hpp +0 -83
  78. pyopencl-2024.2.2.data/data/src/clinfo_ext.h +0 -134
  79. pyopencl-2024.2.2.data/data/src/mempool.hpp +0 -444
  80. pyopencl-2024.2.2.data/data/src/pyopencl_ext.h +0 -77
  81. pyopencl-2024.2.2.data/data/src/tools.hpp +0 -90
  82. pyopencl-2024.2.2.data/data/src/wrap_cl.cpp +0 -61
  83. pyopencl-2024.2.2.data/data/src/wrap_cl.hpp +0 -5853
  84. pyopencl-2024.2.2.data/data/src/wrap_cl_part_1.cpp +0 -369
  85. pyopencl-2024.2.2.data/data/src/wrap_cl_part_2.cpp +0 -702
  86. pyopencl-2024.2.2.data/data/src/wrap_constants.cpp +0 -1274
  87. pyopencl-2024.2.2.data/data/src/wrap_helpers.hpp +0 -213
  88. pyopencl-2024.2.2.data/data/src/wrap_mempool.cpp +0 -738
  89. pyopencl-2024.2.2.data/data/test/add-vectors-32.spv +0 -0
  90. pyopencl-2024.2.2.data/data/test/add-vectors-64.spv +0 -0
  91. pyopencl-2024.2.2.data/data/test/empty-header.h +0 -1
  92. pyopencl-2024.2.2.data/data/test/test_algorithm.py +0 -1180
  93. pyopencl-2024.2.2.data/data/test/test_array.py +0 -2392
  94. pyopencl-2024.2.2.data/data/test/test_arrays_in_structs.py +0 -100
  95. pyopencl-2024.2.2.data/data/test/test_clmath.py +0 -529
  96. pyopencl-2024.2.2.data/data/test/test_clrandom.py +0 -75
  97. pyopencl-2024.2.2.data/data/test/test_enqueue_copy.py +0 -271
  98. pyopencl-2024.2.2.data/data/test/test_wrapper.py +0 -1565
  99. pyopencl-2024.2.2.dist-info/LICENSE +0 -282
  100. pyopencl-2024.2.2.dist-info/RECORD +0 -123
  101. pyopencl-2024.2.2.dist-info/top_level.txt +0 -1
  102. {pyopencl-2024.2.2.data/data → pyopencl-2024.2.4.dist-info/licenses}/LICENSE +0 -0
@@ -1,100 +0,0 @@
1
- __copyright__ = "Copyright (C) 2020 Sotiris Niarchos"
2
-
3
- __license__ = """
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- """
22
-
23
- import numpy as np
24
-
25
- import pyopencl as cl
26
- import pyopencl.cltypes as cltypes
27
- import pyopencl.tools as cl_tools
28
- from pyopencl import mem_flags
29
- from pyopencl.tools import \
30
- pytest_generate_tests_for_pyopencl as pytest_generate_tests # noqa: F401
31
-
32
-
33
- def test_struct_with_array_fields(ctx_factory):
34
- #
35
- # typedef struct {
36
- # uint x[2];
37
- # float y;
38
- # uint z[3][4];
39
- # } my_struct;
40
- #
41
- cl_ctx = ctx_factory()
42
- device = cl_ctx.devices[0]
43
- queue = cl.CommandQueue(cl_ctx)
44
-
45
- my_struct = np.dtype([
46
- ("x", cltypes.uint, 2),
47
- ("y", cltypes.int),
48
- ("z", cltypes.uint, (3, 4))
49
- ])
50
- my_struct, cdecl = cl_tools.match_dtype_to_c_struct(
51
- device, "my_struct", my_struct
52
- )
53
-
54
- # a random buffer of 4 structs
55
- my_struct_arr = np.array([
56
- ([81, 24], -57, [[15, 28, 45, 7], [71, 95, 65, 84], [2, 11, 59, 9]]),
57
- ([5, 20], 47, [[15, 53, 7, 59], [73, 22, 27, 86], [59, 6, 39, 49]]),
58
- ([11, 99], -32, [[73, 83, 4, 65], [19, 21, 22, 27], [1, 55, 6, 64]]),
59
- ([57, 38], -54, [[74, 90, 38, 67], [77, 30, 99, 18], [91, 3, 63, 67]])
60
- ], dtype=my_struct)
61
-
62
- expected_res = []
63
- for x in my_struct_arr:
64
- expected_res.append(int(np.sum(x[0]) + x[1] + np.sum(x[2])))
65
- expected_res = np.array(expected_res, dtype=cltypes.int)
66
-
67
- kernel_src = """%s
68
- // this kernel sums every number contained in each struct
69
- __kernel void array_structs(__global my_struct *structs, __global int *res) {
70
- int i = get_global_id(0);
71
- my_struct s = structs[i];
72
- res[i] = s.x[0] + s.x[1] + s.y;
73
- for (int r = 0; r < 3; r++)
74
- for (int c = 0; c < 4; c++)
75
- res[i] += s.z[r][c];
76
- }""" % cdecl
77
-
78
- mem_flags1 = mem_flags.READ_ONLY | mem_flags.COPY_HOST_PTR
79
- mem_flags2 = mem_flags.WRITE_ONLY
80
-
81
- my_struct_buf = cl.Buffer(cl_ctx, mem_flags1, hostbuf=my_struct_arr)
82
- res_buf = cl.Buffer(cl_ctx, mem_flags2, size=expected_res.nbytes)
83
-
84
- program = cl.Program(cl_ctx, kernel_src).build()
85
- kernel = program.array_structs
86
- kernel(queue, (4,), None, my_struct_buf, res_buf)
87
-
88
- res = np.empty_like(expected_res)
89
- cl.enqueue_copy(queue, res, res_buf)
90
-
91
- assert (res == expected_res).all()
92
-
93
-
94
- if __name__ == "__main__":
95
- import sys
96
- if len(sys.argv) > 1:
97
- exec(sys.argv[1])
98
- else:
99
- from pytest import main
100
- main([__file__])
@@ -1,529 +0,0 @@
1
- __copyright__ = "Copyright (C) 2009 Andreas Kloeckner"
2
-
3
- __license__ = """
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- """
22
-
23
- import math
24
-
25
- import numpy as np
26
- import pytest
27
-
28
- import pyopencl as cl
29
- import pyopencl.array as cl_array
30
- import pyopencl.clmath as clmath
31
- from pyopencl.characterize import has_double_support, has_struct_arg_count_bug
32
- from pyopencl.tools import \
33
- pytest_generate_tests_for_pyopencl as pytest_generate_tests # noqa: F401
34
-
35
-
36
- try:
37
- import faulthandler
38
- except ImportError:
39
- pass
40
- else:
41
- faulthandler.enable()
42
-
43
-
44
- sizes = [10, 128, 1 << 10, 1 << 11, 1 << 13]
45
-
46
-
47
- numpy_func_names = {
48
- "asin": "arcsin",
49
- "acos": "arccos",
50
- "atan": "arctan",
51
- }
52
-
53
-
54
- def make_unary_function_test(name, limits=(0, 1), threshold=0, use_complex=False):
55
- (a, b) = limits
56
- a = float(a)
57
- b = float(b)
58
-
59
- def test(ctx_factory):
60
- context = ctx_factory()
61
- queue = cl.CommandQueue(context)
62
-
63
- gpu_func = getattr(clmath, name)
64
- cpu_func = getattr(np, numpy_func_names.get(name, name))
65
-
66
- dev = context.devices[0]
67
-
68
- if has_double_support(dev):
69
- if use_complex and has_struct_arg_count_bug(dev) == "apple":
70
- dtypes = [np.float32, np.float64, np.complex64]
71
- elif use_complex:
72
- dtypes = [np.float32, np.float64, np.complex64, np.complex128]
73
- else:
74
- dtypes = [np.float32, np.float64]
75
- else:
76
- if use_complex:
77
- dtypes = [np.float32, np.complex64]
78
- else:
79
- dtypes = [np.float32]
80
-
81
- for s in sizes:
82
- for dtype in dtypes:
83
- dtype = np.dtype(dtype)
84
-
85
- args = cl_array.arange(queue, a, b, (b-a)/s, dtype=dtype)
86
- if dtype.kind == "c":
87
- # args = args + dtype.type(1j) * args
88
- args = args + args * dtype.type(1j)
89
-
90
- gpu_results = gpu_func(args).get()
91
- cpu_results = cpu_func(args.get())
92
-
93
- my_threshold = threshold
94
- if dtype.kind == "c" and isinstance(use_complex, float):
95
- my_threshold = use_complex
96
-
97
- max_err = np.max(np.abs(cpu_results - gpu_results))
98
- assert (max_err <= my_threshold).all(), \
99
- (max_err, name, dtype)
100
-
101
- return test
102
-
103
-
104
- test_ceil = make_unary_function_test("ceil", (-10, 10))
105
- test_floor = make_unary_function_test("ceil", (-10, 10))
106
- test_fabs = make_unary_function_test("fabs", (-10, 10))
107
- test_exp = make_unary_function_test("exp", (-3, 3), 1e-5, use_complex=True)
108
- test_log = make_unary_function_test("log", (1e-5, 1), 1e-6, use_complex=True)
109
- test_log10 = make_unary_function_test("log10", (1e-5, 1), 5e-7)
110
- test_sqrt = make_unary_function_test("sqrt", (1e-5, 1), 3e-7, use_complex=True)
111
-
112
- test_sin = make_unary_function_test("sin", (-10, 10), 2e-7, use_complex=2e-2)
113
- test_cos = make_unary_function_test("cos", (-10, 10), 2e-7, use_complex=2e-2)
114
- test_asin = make_unary_function_test("asin", (-0.9, 0.9), 5e-7)
115
- test_acos = make_unary_function_test("acos", (-0.9, 0.9), 5e-7)
116
- test_tan = make_unary_function_test("tan",
117
- (-math.pi/2 + 0.1, math.pi/2 - 0.1), 4e-5, use_complex=True)
118
- test_atan = make_unary_function_test("atan", (-10, 10), 2e-7)
119
-
120
- test_sinh = make_unary_function_test("sinh", (-3, 3), 3e-6, use_complex=2e-3)
121
- test_cosh = make_unary_function_test("cosh", (-3, 3), 3e-6, use_complex=2e-3)
122
- test_tanh = make_unary_function_test("tanh", (-3, 3), 2e-6, use_complex=True)
123
-
124
-
125
- def test_atan2(ctx_factory):
126
- context = ctx_factory()
127
- queue = cl.CommandQueue(context)
128
-
129
- for s in sizes:
130
- a = (cl_array.arange(queue, s, dtype=np.float32) - np.float32(s / 2)) / 100
131
- a2 = (s / 2 - 1 - cl_array.arange(queue, s, dtype=np.float32)) / 100
132
- b = clmath.atan2(a, a2)
133
-
134
- a = a.get()
135
- a2 = a2.get()
136
- b = b.get()
137
-
138
- for i in range(s):
139
- assert abs(math.atan2(a[i], a2[i]) - b[i]) < 1e-6
140
-
141
-
142
- def test_atan2pi(ctx_factory):
143
- context = ctx_factory()
144
- queue = cl.CommandQueue(context)
145
-
146
- for s in sizes:
147
- a = (cl_array.arange(queue, s, dtype=np.float32) - np.float32(s / 2)) / 100
148
- a2 = (s / 2 - 1 - cl_array.arange(queue, s, dtype=np.float32)) / 100
149
- b = clmath.atan2pi(a, a2)
150
-
151
- a = a.get()
152
- a2 = a2.get()
153
- b = b.get()
154
-
155
- for i in range(s):
156
- assert abs(math.atan2(a[i], a2[i]) / math.pi - b[i]) < 1e-6
157
-
158
-
159
- def test_fmod(ctx_factory):
160
- context = ctx_factory()
161
- queue = cl.CommandQueue(context)
162
-
163
- for s in sizes:
164
- a = cl_array.arange(queue, s, dtype=np.float32)/10
165
- a2 = cl_array.arange(queue, s, dtype=np.float32)/45.2 + 0.1
166
- b = clmath.fmod(a, a2)
167
-
168
- # https://salsa.debian.org/opencl-team/python-pyopencl/-/merge_requests/3#note_383761
169
- assert np.max(np.abs((np.fmod(a.get(), a2.get()) - b.get()))) < 1e-4
170
-
171
-
172
- def test_ldexp(ctx_factory):
173
- context = ctx_factory()
174
- queue = cl.CommandQueue(context)
175
-
176
- for s in sizes:
177
- a = cl_array.arange(queue, s, dtype=np.float32)
178
- a2 = cl_array.arange(queue, s, dtype=np.float32)*1e-3
179
- b = clmath.ldexp(a, a2)
180
-
181
- a = a.get()
182
- a2 = a2.get()
183
- b = b.get()
184
-
185
- for i in range(s):
186
- assert math.ldexp(a[i], int(a2[i])) == b[i]
187
-
188
-
189
- def test_modf(ctx_factory):
190
- context = ctx_factory()
191
- queue = cl.CommandQueue(context)
192
-
193
- for s in sizes:
194
- a = cl_array.arange(queue, s, dtype=np.float32)/10
195
- fracpart, intpart = clmath.modf(a)
196
-
197
- a = a.get()
198
- intpart = intpart.get()
199
- fracpart = fracpart.get()
200
-
201
- for i in range(s):
202
- fracpart_true, intpart_true = math.modf(a[i])
203
-
204
- assert intpart_true == intpart[i]
205
- assert abs(fracpart_true - fracpart[i]) < 1e-4
206
-
207
-
208
- def test_frexp(ctx_factory):
209
- context = ctx_factory()
210
- queue = cl.CommandQueue(context)
211
-
212
- for s in sizes:
213
- a = cl_array.arange(queue, s, dtype=np.float32)/10
214
- significands, exponents = clmath.frexp(a)
215
-
216
- a = a.get()
217
- significands = significands.get()
218
- exponents = exponents.get()
219
-
220
- for i in range(s):
221
- sig_true, ex_true = math.frexp(a[i])
222
-
223
- assert sig_true == significands[i]
224
- assert ex_true == exponents[i]
225
-
226
-
227
- def test_bessel(ctx_factory):
228
- try:
229
- import scipy.special as spec
230
- except ImportError:
231
- from pytest import skip
232
- skip("scipy not present--cannot test Bessel function")
233
-
234
- ctx = ctx_factory()
235
- queue = cl.CommandQueue(ctx)
236
-
237
- if not has_double_support(ctx.devices[0]):
238
- from pytest import skip
239
- skip("no double precision support--cannot test bessel function")
240
-
241
- nterms = 30
242
-
243
- try:
244
- from pyfmmlib import hank103_vec, jfuns2d
245
- except ImportError:
246
- use_pyfmmlib = False
247
- else:
248
- use_pyfmmlib = True
249
-
250
- print("PYFMMLIB", use_pyfmmlib)
251
-
252
- if use_pyfmmlib:
253
- a = np.logspace(-3, 3, 10**6)
254
- else:
255
- a = np.logspace(-5, 5, 10**6)
256
-
257
- for which_func, cl_func, scipy_func, is_rel in [
258
- ("j", clmath.bessel_jn, spec.jn, False),
259
- ("y", clmath.bessel_yn, spec.yn, True)
260
- ]:
261
- if is_rel:
262
- def get_err(check, ref):
263
- return np.max(np.abs(check-ref)) / np.max(np.abs(ref))
264
- else:
265
- def get_err(check, ref):
266
- return np.max(np.abs(check-ref))
267
-
268
- if use_pyfmmlib:
269
- pfymm_result = np.empty((len(a), nterms), dtype=np.complex128)
270
- if which_func == "j":
271
- for i, a_i in enumerate(a):
272
- if i % 100000 == 0:
273
- print("%.1f %%" % (100 * i/len(a)))
274
- ier, fjs, _, _ = jfuns2d(nterms, a_i, 1, 0, 10000)
275
- pfymm_result[i] = fjs[:nterms]
276
- assert ier == 0
277
- elif which_func == "y":
278
- h0, h1 = hank103_vec(a, ifexpon=1)
279
- pfymm_result[:, 0] = h0.imag
280
- pfymm_result[:, 1] = h1.imag
281
-
282
- a_dev = cl_array.to_device(queue, a)
283
-
284
- for n in range(0, nterms):
285
- cl_bessel = cl_func(n, a_dev).get()
286
- scipy_bessel = scipy_func(n, a)
287
-
288
- error_scipy = get_err(cl_bessel, scipy_bessel)
289
- assert error_scipy < 1e-10, error_scipy
290
-
291
- if use_pyfmmlib and (
292
- which_func == "j"
293
- or (which_func == "y" and n in [0, 1])):
294
- pyfmm_bessel = pfymm_result[:, n]
295
- error_pyfmm = get_err(cl_bessel, pyfmm_bessel)
296
- assert error_pyfmm < 1e-10, error_pyfmm
297
- error_pyfmm_scipy = get_err(scipy_bessel, pyfmm_bessel)
298
- print(which_func, n, error_scipy, error_pyfmm, error_pyfmm_scipy)
299
- else:
300
- print(which_func, n, error_scipy)
301
-
302
- assert not np.isnan(cl_bessel).any()
303
-
304
- if 0 and n == 15:
305
- import matplotlib.pyplot as pt
306
-
307
- #pt.plot(scipy_bessel)
308
- #pt.plot(cl_bessel)
309
-
310
- pt.loglog(a, np.abs(cl_bessel-scipy_bessel), label="vs scipy")
311
- if use_pyfmmlib:
312
- pt.loglog(a, np.abs(cl_bessel-pyfmm_bessel), label="vs pyfmmlib")
313
- pt.legend()
314
- pt.show()
315
-
316
-
317
- @pytest.mark.parametrize("ref_src", ["pyfmmlib", "scipy"])
318
- def test_complex_bessel(ctx_factory, ref_src):
319
- ctx = ctx_factory()
320
- queue = cl.CommandQueue(ctx)
321
-
322
- if not has_double_support(ctx.devices[0]):
323
- from pytest import skip
324
- skip("no double precision support--cannot test complex bessel function")
325
-
326
- v = 40
327
- n = 10**5
328
-
329
- rng = np.random.default_rng(seed=13)
330
- z = (
331
- np.logspace(-5, 2, n)
332
- * np.exp(1j * 2 * np.pi * rng.random(n)))
333
-
334
- if ref_src == "pyfmmlib":
335
- pyfmmlib = pytest.importorskip("pyfmmlib")
336
-
337
- jv_ref = np.zeros(len(z), "complex")
338
-
339
- vin = v+1
340
-
341
- for i in range(len(z)):
342
- ier, fjs, _, _ = pyfmmlib.jfuns2d(vin, z[i], 1, 0, 10000)
343
- assert ier == 0
344
- jv_ref[i] = fjs[v]
345
-
346
- elif ref_src == "scipy":
347
- spec = pytest.importorskip("scipy.special")
348
- jv_ref = spec.jv(v, z)
349
-
350
- else:
351
- raise ValueError("ref_src")
352
-
353
- z_dev = cl_array.to_device(queue, z)
354
-
355
- jv_dev = clmath.bessel_jn(v, z_dev)
356
-
357
- abs_err_jv = np.abs(jv_dev.get() - jv_ref)
358
- abs_jv_ref = np.abs(jv_ref)
359
- rel_err_jv = abs_err_jv/abs_jv_ref
360
-
361
- # use absolute error instead if the function value itself is too small
362
- tiny = 1e-300
363
- ind = abs_jv_ref < tiny
364
- rel_err_jv[ind] = abs_err_jv[ind]
365
-
366
- # if the reference value is inf or nan, set the error to zero
367
- ind1 = np.isinf(abs_jv_ref)
368
- ind2 = np.isnan(abs_jv_ref)
369
-
370
- rel_err_jv[ind1] = 0
371
- rel_err_jv[ind2] = 0
372
-
373
- if 0:
374
- print(abs(z))
375
- print(np.abs(jv_ref))
376
- print(np.abs(jv_dev.get()))
377
- print(rel_err_jv)
378
-
379
- max_err = np.max(rel_err_jv)
380
- assert max_err <= 2e-13, max_err
381
-
382
- print("Jv", np.max(rel_err_jv))
383
-
384
- if 0:
385
- import matplotlib.pyplot as pt
386
- pt.loglog(np.abs(z), rel_err_jv)
387
- pt.show()
388
-
389
-
390
- @pytest.mark.parametrize("ref_src", ["pyfmmlib", "scipy"])
391
- def test_hankel_01_complex(ctx_factory, ref_src):
392
- ctx = ctx_factory()
393
- queue = cl.CommandQueue(ctx)
394
-
395
- if not has_double_support(ctx.devices[0]):
396
- from pytest import skip
397
- skip("no double precision support--cannot test complex bessel function")
398
-
399
- rng = np.random.default_rng(seed=11)
400
- n = 10**6
401
- z = (
402
- np.logspace(-5, 2, n)
403
- * np.exp(1j * 2 * np.pi * rng.random(n)))
404
-
405
- def get_err(check, ref):
406
- return np.max(np.abs(check-ref)) / np.max(np.abs(ref))
407
-
408
- if ref_src == "pyfmmlib":
409
- pyfmmlib = pytest.importorskip("pyfmmlib")
410
- h0_ref, h1_ref = pyfmmlib.hank103_vec(z, ifexpon=1)
411
- elif ref_src == "scipy":
412
- spec = pytest.importorskip("scipy.special")
413
- h0_ref = spec.hankel1(0, z)
414
- h1_ref = spec.hankel1(1, z)
415
-
416
- else:
417
- raise ValueError("ref_src")
418
-
419
- z_dev = cl_array.to_device(queue, z)
420
-
421
- h0_dev, h1_dev = clmath.hankel_01(z_dev)
422
-
423
- rel_err_h0 = np.abs(h0_dev.get() - h0_ref)/np.abs(h0_ref)
424
- rel_err_h1 = np.abs(h1_dev.get() - h1_ref)/np.abs(h1_ref)
425
-
426
- max_rel_err_h0 = np.max(rel_err_h0)
427
- max_rel_err_h1 = np.max(rel_err_h1)
428
-
429
- print("H0", max_rel_err_h0)
430
- print("H1", max_rel_err_h1)
431
-
432
- assert max_rel_err_h0 < 4e-13
433
- assert max_rel_err_h1 < 2e-13
434
-
435
- if 0:
436
- import matplotlib.pyplot as pt
437
- pt.loglog(np.abs(z), rel_err_h0)
438
- pt.loglog(np.abs(z), rel_err_h1)
439
- pt.show()
440
-
441
-
442
- @pytest.mark.parametrize("dtype", [np.complex64, np.complex128])
443
- def test_complex_muladd(ctx_factory, dtype):
444
- ctx = ctx_factory()
445
- queue = cl.CommandQueue(ctx)
446
-
447
- if dtype == np.complex128 and not has_double_support(ctx.devices[0]):
448
- from pytest import skip
449
- skip("no double precision support")
450
-
451
- if dtype == np.complex64:
452
- real_type = np.float32
453
- real_type_name = "float"
454
- else:
455
- real_type = np.float64
456
- real_type_name = "double"
457
-
458
- rng = np.random.default_rng(seed=11)
459
- n = 100
460
-
461
- arrs = [rng.random(n, dtype=real_type) + 1j*rng.random(n, dtype=real_type)
462
- for i in range(3)]
463
- arrs = [arr.astype(dtype) for arr in arrs]
464
-
465
- arrs_dev = [cl_array.to_device(queue, arr) for arr in arrs]
466
-
467
- prg_str = """
468
- #if __OPENCL_C_VERSION__ < 120
469
- #pragma OPENCL EXTENSION cl_khr_fp64: enable
470
- #endif
471
- #define PYOPENCL_DEFINE_CDOUBLE
472
-
473
- #include <pyopencl-complex.h>
474
-
475
- __kernel void foo(
476
- __global const c{real_type_name}_t *a,
477
- __global const c{real_type_name}_t *b,
478
- __global const c{real_type_name}_t *c,
479
- __global c{real_type_name}_t *res
480
- )
481
- {{
482
- int gid = get_global_id(0);
483
- res[gid] = c{real_type_name}_fma(a[gid], b[gid], c[gid]);
484
- }}
485
- """.format(real_type_name=real_type_name)
486
-
487
- prg = cl.Program(ctx, prg_str).build()
488
- knl = prg.foo
489
-
490
- result_dev = cl_array.empty_like(arrs_dev[0])
491
- knl(queue, (n,), None, arrs_dev[0].data,
492
- arrs_dev[1].data, arrs_dev[2].data, result_dev.data)
493
-
494
- ref = arrs[0] * arrs[1] + arrs[2]
495
-
496
- rel_err = np.abs(result_dev.get() - ref)/np.abs(ref)
497
-
498
- if dtype == np.complex64:
499
- assert np.max(rel_err) < 1e-6
500
- else:
501
- assert np.max(rel_err) < 1e-12
502
-
503
-
504
- def test_outoforderqueue_clmath(ctx_factory):
505
- context = ctx_factory()
506
- try:
507
- queue = cl.CommandQueue(context,
508
- properties=cl.command_queue_properties.OUT_OF_ORDER_EXEC_MODE_ENABLE)
509
- except Exception:
510
- pytest.skip("out-of-order queue not available")
511
-
512
- rng = np.random.default_rng(seed=42)
513
- a = rng.random(10**6, dtype=np.float32)
514
- a_gpu = cl_array.to_device(queue, a)
515
- # testing that clmath functions wait for and create events
516
- b_gpu = clmath.fabs(clmath.sin(a_gpu * 5))
517
- queue.finish()
518
- b1 = b_gpu.get()
519
- b = np.abs(np.sin(a * 5))
520
- assert np.abs(b1 - b).mean() < 1e-5
521
-
522
-
523
- if __name__ == "__main__":
524
- import sys
525
- if len(sys.argv) > 1:
526
- exec(sys.argv[1])
527
- else:
528
- from pytest import main
529
- main([__file__])
@@ -1,75 +0,0 @@
1
- __copyright__ = "Copyright (C) 2018 Matt Wala"
2
-
3
- __license__ = """
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- """
22
-
23
- import numpy as np
24
- import pytest
25
-
26
- import pyopencl as cl
27
- import pyopencl.clrandom as clrandom
28
- import pyopencl.cltypes as cltypes
29
- from pyopencl.characterize import has_double_support
30
- from pyopencl.tools import \
31
- pytest_generate_tests_for_pyopencl as pytest_generate_tests # noqa: F401
32
-
33
-
34
- try:
35
- import faulthandler
36
- except ImportError:
37
- pass
38
- else:
39
- faulthandler.enable()
40
-
41
-
42
- @pytest.mark.parametrize("rng_class", [
43
- clrandom.PhiloxGenerator,
44
- clrandom.ThreefryGenerator])
45
- @pytest.mark.parametrize("dtype", [
46
- np.int32,
47
- np.int64,
48
- np.float32,
49
- np.float64,
50
- cltypes.float2, # type: ignore[attr-defined]
51
- cltypes.float3, # type: ignore[attr-defined]
52
- cltypes.float4, # type: ignore[attr-defined]
53
- ])
54
- def test_clrandom_dtypes(ctx_factory, rng_class, dtype):
55
- cl_ctx = ctx_factory()
56
- if dtype == np.float64 and not has_double_support(cl_ctx.devices[0]):
57
- pytest.skip("double precision not supported on this device")
58
- rng = rng_class(cl_ctx)
59
-
60
- size = 10
61
-
62
- with cl.CommandQueue(cl_ctx) as queue:
63
- rng.uniform(queue, size, dtype)
64
-
65
- if dtype not in (np.int32, np.int64):
66
- rng.normal(queue, size, dtype)
67
-
68
-
69
- if __name__ == "__main__":
70
- import sys
71
- if len(sys.argv) > 1:
72
- exec(sys.argv[1])
73
- else:
74
- from pytest import main
75
- main([__file__])