pyopencl 2025.2.7__cp314-cp314-macosx_10_15_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.
- pyopencl/__init__.py +1995 -0
- pyopencl/_cl.cpython-314-darwin.so +0 -0
- pyopencl/_cl.pyi +2009 -0
- pyopencl/_cluda.py +57 -0
- pyopencl/_monkeypatch.py +1104 -0
- pyopencl/_mymako.py +17 -0
- pyopencl/algorithm.py +1454 -0
- pyopencl/array.py +3530 -0
- pyopencl/bitonic_sort.py +245 -0
- pyopencl/bitonic_sort_templates.py +597 -0
- pyopencl/cache.py +535 -0
- pyopencl/capture_call.py +200 -0
- pyopencl/characterize/__init__.py +461 -0
- pyopencl/characterize/performance.py +240 -0
- pyopencl/cl/pyopencl-airy.cl +324 -0
- pyopencl/cl/pyopencl-bessel-j-complex.cl +238 -0
- pyopencl/cl/pyopencl-bessel-j.cl +1084 -0
- pyopencl/cl/pyopencl-bessel-y.cl +435 -0
- pyopencl/cl/pyopencl-complex.h +303 -0
- pyopencl/cl/pyopencl-eval-tbl.cl +120 -0
- pyopencl/cl/pyopencl-hankel-complex.cl +444 -0
- pyopencl/cl/pyopencl-random123/array.h +325 -0
- pyopencl/cl/pyopencl-random123/openclfeatures.h +93 -0
- pyopencl/cl/pyopencl-random123/philox.cl +486 -0
- pyopencl/cl/pyopencl-random123/threefry.cl +864 -0
- pyopencl/clmath.py +281 -0
- pyopencl/clrandom.py +412 -0
- pyopencl/cltypes.py +217 -0
- pyopencl/compyte/.gitignore +21 -0
- pyopencl/compyte/__init__.py +0 -0
- pyopencl/compyte/array.py +211 -0
- pyopencl/compyte/dtypes.py +314 -0
- pyopencl/compyte/pyproject.toml +49 -0
- pyopencl/elementwise.py +1288 -0
- pyopencl/invoker.py +417 -0
- pyopencl/ipython_ext.py +70 -0
- pyopencl/py.typed +0 -0
- pyopencl/reduction.py +815 -0
- pyopencl/scan.py +1921 -0
- pyopencl/tools.py +1680 -0
- pyopencl/typing.py +61 -0
- pyopencl/version.py +11 -0
- pyopencl-2025.2.7.dist-info/METADATA +108 -0
- pyopencl-2025.2.7.dist-info/RECORD +46 -0
- pyopencl-2025.2.7.dist-info/WHEEL +6 -0
- pyopencl-2025.2.7.dist-info/licenses/LICENSE +282 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
__copyright__ = "Copyright (C) 2009 Andreas Kloeckner"
|
|
5
|
+
|
|
6
|
+
__license__ = """
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
import numpy as np
|
|
27
|
+
|
|
28
|
+
import pyopencl as cl
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# {{{ timing helpers
|
|
32
|
+
|
|
33
|
+
class Timer:
|
|
34
|
+
def __init__(self, queue):
|
|
35
|
+
self.queue = queue
|
|
36
|
+
|
|
37
|
+
def start(self):
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
def stop(self):
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
def add_event(self, evt):
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
def get_elapsed(self):
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class WallTimer(Timer):
|
|
51
|
+
def start(self):
|
|
52
|
+
from time import time
|
|
53
|
+
self.queue.finish()
|
|
54
|
+
self.start_time = time()
|
|
55
|
+
|
|
56
|
+
def stop(self):
|
|
57
|
+
from time import time
|
|
58
|
+
self.queue.finish()
|
|
59
|
+
self.end_time = time()
|
|
60
|
+
|
|
61
|
+
def get_elapsed(self):
|
|
62
|
+
return self.end_time-self.start_time
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _get_time(queue, f, timer_factory=None, desired_duration=0.1,
|
|
66
|
+
warmup_rounds=3):
|
|
67
|
+
|
|
68
|
+
if timer_factory is None:
|
|
69
|
+
timer_factory = WallTimer
|
|
70
|
+
|
|
71
|
+
count = 1
|
|
72
|
+
|
|
73
|
+
while True:
|
|
74
|
+
timer = timer_factory(queue)
|
|
75
|
+
|
|
76
|
+
for _i in range(warmup_rounds):
|
|
77
|
+
f()
|
|
78
|
+
warmup_rounds = 0
|
|
79
|
+
|
|
80
|
+
timer.start()
|
|
81
|
+
for _i in range(count):
|
|
82
|
+
timer.add_event(f())
|
|
83
|
+
timer.stop()
|
|
84
|
+
|
|
85
|
+
elapsed = timer.get_elapsed()
|
|
86
|
+
if elapsed < desired_duration:
|
|
87
|
+
if elapsed == 0:
|
|
88
|
+
count *= 5
|
|
89
|
+
else:
|
|
90
|
+
new_count = int(desired_duration/elapsed)
|
|
91
|
+
|
|
92
|
+
new_count = max(2*count, new_count)
|
|
93
|
+
new_count = min(10*count, new_count)
|
|
94
|
+
count = new_count
|
|
95
|
+
|
|
96
|
+
else:
|
|
97
|
+
return elapsed/count
|
|
98
|
+
|
|
99
|
+
# }}}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# {{{ transfer measurements
|
|
103
|
+
|
|
104
|
+
class HostDeviceTransferBase:
|
|
105
|
+
def __init__(self, queue, block_size):
|
|
106
|
+
self.queue = queue
|
|
107
|
+
self.host_buf = np.empty(block_size, dtype=np.uint8)
|
|
108
|
+
self.dev_buf = cl.Buffer(queue.context, cl.mem_flags.READ_WRITE, block_size)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class HostToDeviceTransfer(HostDeviceTransferBase):
|
|
112
|
+
def do(self):
|
|
113
|
+
return cl.enqueue_copy(self. queue, self.dev_buf, self.host_buf)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class DeviceToHostTransfer(HostDeviceTransferBase):
|
|
117
|
+
def do(self):
|
|
118
|
+
return cl.enqueue_copy(self. queue, self.host_buf, self.dev_buf)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class DeviceToDeviceTransfer:
|
|
122
|
+
def __init__(self, queue, block_size):
|
|
123
|
+
self.queue = queue
|
|
124
|
+
mf = cl.mem_flags
|
|
125
|
+
self.dev_buf_1 = cl.Buffer(queue.context, mf.READ_WRITE, block_size)
|
|
126
|
+
self.dev_buf_2 = cl.Buffer(queue.context, mf.READ_WRITE, block_size)
|
|
127
|
+
|
|
128
|
+
def do(self):
|
|
129
|
+
return cl.enqueue_copy(self. queue, self.dev_buf_2, self.dev_buf_1)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def transfer_latency(queue, transfer_type, timer_factory=None):
|
|
133
|
+
transfer = transfer_type(queue, 1)
|
|
134
|
+
return _get_time(queue, transfer.do, timer_factory=timer_factory)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def transfer_bandwidth(queue, transfer_type, block_size, timer_factory=None):
|
|
138
|
+
"""Measures one-sided bandwidth."""
|
|
139
|
+
|
|
140
|
+
transfer = transfer_type(queue, block_size)
|
|
141
|
+
return block_size/_get_time(queue, transfer.do, timer_factory=timer_factory)
|
|
142
|
+
|
|
143
|
+
# }}}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def get_profiling_overhead(ctx, timer_factory=None):
|
|
147
|
+
no_prof_queue = cl.CommandQueue(ctx)
|
|
148
|
+
transfer = DeviceToDeviceTransfer(no_prof_queue, 1)
|
|
149
|
+
no_prof_time = _get_time(no_prof_queue, transfer.do, timer_factory=timer_factory)
|
|
150
|
+
|
|
151
|
+
prof_queue = cl.CommandQueue(ctx,
|
|
152
|
+
properties=cl.command_queue_properties.PROFILING_ENABLE)
|
|
153
|
+
transfer = DeviceToDeviceTransfer(prof_queue, 1)
|
|
154
|
+
prof_time = _get_time(prof_queue, transfer.do, timer_factory=timer_factory)
|
|
155
|
+
|
|
156
|
+
return prof_time - no_prof_time, prof_time
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def get_empty_kernel_time(queue, timer_factory=None):
|
|
160
|
+
prg = cl.Program(queue.context, """
|
|
161
|
+
__kernel void empty()
|
|
162
|
+
{ }
|
|
163
|
+
""").build()
|
|
164
|
+
|
|
165
|
+
knl = prg.empty
|
|
166
|
+
|
|
167
|
+
def f():
|
|
168
|
+
knl(queue, (1,), None)
|
|
169
|
+
|
|
170
|
+
return _get_time(queue, f, timer_factory=timer_factory)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _get_full_machine_kernel_rate(queue, src, args, name="benchmark",
|
|
174
|
+
timer_factory=None):
|
|
175
|
+
prg = cl.Program(queue.context, src).build()
|
|
176
|
+
|
|
177
|
+
knl = getattr(prg, name)
|
|
178
|
+
|
|
179
|
+
dev = queue.device
|
|
180
|
+
global_size = 4 * dev.max_compute_units
|
|
181
|
+
|
|
182
|
+
def f():
|
|
183
|
+
knl(queue, (global_size,), None, *args)
|
|
184
|
+
|
|
185
|
+
rates = []
|
|
186
|
+
num_dips = 0
|
|
187
|
+
|
|
188
|
+
while True:
|
|
189
|
+
elapsed = _get_time(queue, f, timer_factory=timer_factory)
|
|
190
|
+
rate = global_size/elapsed
|
|
191
|
+
|
|
192
|
+
keep_trying = not rates
|
|
193
|
+
|
|
194
|
+
if rates and rate > 1.05*max(rates): # big improvement
|
|
195
|
+
keep_trying = True
|
|
196
|
+
num_dips = 0
|
|
197
|
+
|
|
198
|
+
if rates and rate < 0.9*max(rates) and num_dips < 3: # big dip
|
|
199
|
+
keep_trying = True
|
|
200
|
+
num_dips += 1
|
|
201
|
+
|
|
202
|
+
if keep_trying:
|
|
203
|
+
global_size *= 2
|
|
204
|
+
rates.append(rate)
|
|
205
|
+
else:
|
|
206
|
+
rates.append(rate)
|
|
207
|
+
return max(rates)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def get_add_rate(queue, type="float", timer_factory=None):
|
|
211
|
+
return 50*10*_get_full_machine_kernel_rate(queue, """
|
|
212
|
+
typedef %(op_t)s op_t;
|
|
213
|
+
__kernel void benchmark()
|
|
214
|
+
{
|
|
215
|
+
local op_t tgt[1024];
|
|
216
|
+
op_t val = get_global_id(0);
|
|
217
|
+
|
|
218
|
+
for (int i = 0; i < 10; ++i)
|
|
219
|
+
{
|
|
220
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
221
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
222
|
+
|
|
223
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
224
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
225
|
+
|
|
226
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
227
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
228
|
+
|
|
229
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
230
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
231
|
+
|
|
232
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
233
|
+
val += val; val += val; val += val; val += val; val += val;
|
|
234
|
+
}
|
|
235
|
+
tgt[get_local_id(0)] = val;
|
|
236
|
+
}
|
|
237
|
+
""" % {"op_t": type}, ())
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
# vim: foldmethod=marker:filetype=pyopencl
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// Ported from Cephes by
|
|
2
|
+
// Andreas Kloeckner (C) 2012
|
|
3
|
+
//
|
|
4
|
+
// Cephes Math Library Release 2.8: June, 2000
|
|
5
|
+
// Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
|
|
6
|
+
// What you see here may be used freely, but it comes with no support or
|
|
7
|
+
// guarantee.
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include <pyopencl-eval-tbl.cl>
|
|
12
|
+
|
|
13
|
+
__constant const double airy_maxairy = 103.892;
|
|
14
|
+
|
|
15
|
+
__constant const double airy_sqrt3 = 1.732050807568877293527;
|
|
16
|
+
__constant const double airy_sqpii = 5.64189583547756286948E-1;
|
|
17
|
+
|
|
18
|
+
__constant const double airy_c1 = 0.35502805388781723926;
|
|
19
|
+
__constant const double airy_c2 = 0.258819403792806798405;
|
|
20
|
+
|
|
21
|
+
__constant const unsigned short AN[32] = {
|
|
22
|
+
0x3fd6,0x2dae,0x2537,0xb658,
|
|
23
|
+
0x4028,0x03e3,0x871a,0x9067,
|
|
24
|
+
0x4053,0x11e5,0x0de2,0xe1e3,
|
|
25
|
+
0x4065,0x02da,0xee40,0x073c,
|
|
26
|
+
0x4063,0xf834,0x5ba1,0xfddf,
|
|
27
|
+
0x4051,0xa24f,0x4f4c,0xea4f,
|
|
28
|
+
0x402c,0x0d8d,0x5c2a,0x0f4d,
|
|
29
|
+
0x3ff0,0x0000,0x0000,0x0000,
|
|
30
|
+
};
|
|
31
|
+
__constant const unsigned short AD[32] = {
|
|
32
|
+
0x3fe2,0x29bc,0x0262,0x4d31,
|
|
33
|
+
0x402d,0x8334,0x0533,0x2ca5,
|
|
34
|
+
0x4055,0x20e3,0xb04d,0x51a0,
|
|
35
|
+
0x4066,0x2a2d,0xc730,0xb7b0,
|
|
36
|
+
0x4064,0x8782,0x9a9f,0xfa61,
|
|
37
|
+
0x4051,0xde94,0xee91,0xd35f,
|
|
38
|
+
0x402c,0x311b,0x950d,0x9d81,
|
|
39
|
+
0x3ff0,0x0000,0x0000,0x0000,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
__constant const unsigned short APN[32] = {
|
|
43
|
+
0x3fe3,0xa3ea,0x4d4c,0xab3e,
|
|
44
|
+
0x402d,0x7dad,0xdc67,0x2bcf,
|
|
45
|
+
0x4054,0x83bd,0x0724,0xa9a6,
|
|
46
|
+
0x4065,0x65e9,0xba99,0xc9ba,
|
|
47
|
+
0x4063,0xea2b,0xcdc2,0x64d7,
|
|
48
|
+
0x4051,0x7e95,0x41d4,0x1646,
|
|
49
|
+
0x402b,0xe4e8,0x6aa7,0x4099,
|
|
50
|
+
0x3ff0,0x0000,0x0000,0x0000,
|
|
51
|
+
};
|
|
52
|
+
__constant const unsigned short APD[32] = {
|
|
53
|
+
0x3fd5,0x6397,0xd288,0xd5b3,
|
|
54
|
+
0x4026,0x5caf,0xedc9,0x327e,
|
|
55
|
+
0x4051,0xcb0e,0x1800,0x97e6,
|
|
56
|
+
0x4063,0xd8e6,0x1132,0xdbd1,
|
|
57
|
+
0x4063,0x269b,0x0dcb,0x3316,
|
|
58
|
+
0x4051,0x2b36,0xf9d0,0xf72f,
|
|
59
|
+
0x402b,0xb321,0x4e35,0x7982,
|
|
60
|
+
0x3ff0,0x0000,0x0000,0x0000,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
__constant const unsigned short BN16[20] = {
|
|
64
|
+
0xbfd0,0x3518,0xe211,0x6751,
|
|
65
|
+
0x3fe2,0x68bc,0x7072,0x2383,
|
|
66
|
+
0xbfd5,0x1d32,0x6785,0xcf29,
|
|
67
|
+
0x3fb0,0x7f2a,0xa027,0x78a8,
|
|
68
|
+
0xbf6f,0x5604,0x2dba,0xcd1b,
|
|
69
|
+
};
|
|
70
|
+
__constant const unsigned short BD16[20] = {
|
|
71
|
+
/*0x3ff0,0x0000,0x0000,0x0000,*/
|
|
72
|
+
0xc01c,0xa09d,0x891b,0xab58,
|
|
73
|
+
0x4025,0x3539,0xfe0b,0x1101,
|
|
74
|
+
0xc014,0xee0b,0xa9a7,0x70e8,
|
|
75
|
+
0x3fee,0xa2fc,0xa6da,0x95ff,
|
|
76
|
+
0xbfac,0x33d0,0x8f8e,0x86c9,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
__constant const unsigned short BPPN[20] = {
|
|
80
|
+
0x3fdd,0xca1d,0x9deb,0x377b,
|
|
81
|
+
0xbff1,0x7051,0xc6be,0xe420,
|
|
82
|
+
0x3fe4,0x710c,0xf199,0x5ff3,
|
|
83
|
+
0xbfc0,0x3c6f,0x8681,0xa8fa,
|
|
84
|
+
0x3f7f,0x3b43,0xb8ce,0xb896,
|
|
85
|
+
};
|
|
86
|
+
__constant const unsigned short BPPD[20] = {
|
|
87
|
+
/*0x3ff0,0x0000,0x0000,0x0000,*/
|
|
88
|
+
0xc021,0x6996,0xb340,0xbc45,
|
|
89
|
+
0x402b,0xcc73,0x2ea4,0xbb8b,
|
|
90
|
+
0xc01c,0x908c,0xa04a,0xed59,
|
|
91
|
+
0x3ff5,0x70fd,0xf9a5,0x70a9,
|
|
92
|
+
0xbfb4,0x13d0,0x1b60,0x52e8,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
__constant const unsigned short AFN[36] = {
|
|
96
|
+
0xbfc0,0xdb6c,0xd50a,0xe6fb,
|
|
97
|
+
0xbfe4,0x0bee,0x9856,0x6852,
|
|
98
|
+
0xbfe6,0x2e59,0xc2f7,0x9f7d,
|
|
99
|
+
0xbfd1,0xe7ea,0x4bb3,0xf40b,
|
|
100
|
+
0xbfa9,0x2f6e,0xf47d,0xbd8a,
|
|
101
|
+
0xbf70,0xa401,0xc8d9,0xe090,
|
|
102
|
+
0xbf24,0xe06e,0xaf4b,0x009c,
|
|
103
|
+
0xbec7,0x4a78,0x1d42,0x366d,
|
|
104
|
+
0xbe52,0x041c,0xf68e,0xa2d2,
|
|
105
|
+
};
|
|
106
|
+
__constant const unsigned short AFD[36] = {
|
|
107
|
+
/*0x3ff0,0x0000,0x0000,0x0000,*/
|
|
108
|
+
0x402a,0xb64b,0x2572,0xedf2,
|
|
109
|
+
0x4040,0x575c,0x4478,0x7b1a,
|
|
110
|
+
0x403a,0xbc98,0xa3b7,0x3410,
|
|
111
|
+
0x4022,0x5fc8,0x2ac9,0x9873,
|
|
112
|
+
0x3ff7,0x9acb,0x39de,0x9319,
|
|
113
|
+
0x3fbd,0x9dac,0xb404,0x5a2b,
|
|
114
|
+
0x3f72,0x08ca,0xe03a,0xf617,
|
|
115
|
+
0x3f13,0xc8d7,0xaf76,0xe73b,
|
|
116
|
+
0x3e9e,0x52b9,0xb995,0x18a7,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
__constant const unsigned short AGN[44] = {
|
|
120
|
+
0x3f94,0x3525,0xddcf,0xbbde,
|
|
121
|
+
0x3fd9,0x07d5,0x0064,0x37b7,
|
|
122
|
+
0x3ff1,0x0d83,0x3a20,0x34eb,
|
|
123
|
+
0x3fee,0x0dac,0xa0ef,0x1acb,
|
|
124
|
+
0x3fd6,0x7e69,0xcea8,0xfe1d,
|
|
125
|
+
0x3fb0,0x3a41,0x21e9,0x0978,
|
|
126
|
+
0x3f77,0xfe99,0xf12f,0x5043,
|
|
127
|
+
0x3f32,0x8976,0x600e,0x17a2,
|
|
128
|
+
0x3edd,0x4f3d,0x69f8,0x574e,
|
|
129
|
+
0x3e75,0xca92,0xbbad,0x11c8,
|
|
130
|
+
0x3df7,0x78a4,0x7d97,0xee7a,
|
|
131
|
+
};
|
|
132
|
+
__constant const unsigned short AGD[40] = {
|
|
133
|
+
/*0x3ff0,0x0000,0x0000,0x0000,*/
|
|
134
|
+
0x4022,0x9e2b,0xf3d5,0x6b40,
|
|
135
|
+
0x4033,0xd5d5,0xc0ef,0x18d4,
|
|
136
|
+
0x402f,0x211b,0x7ea7,0xdc35,
|
|
137
|
+
0x4015,0xe84e,0x2b79,0xdbce,
|
|
138
|
+
0x3fee,0x8992,0xc195,0xece3,
|
|
139
|
+
0x3fb6,0x221d,0xed64,0xa9ee,
|
|
140
|
+
0x3f70,0xe704,0x6be3,0x93bb,
|
|
141
|
+
0x3f1a,0x8b61,0xd603,0xa5a0,
|
|
142
|
+
0x3eb3,0xa845,0xdb07,0x24e8,
|
|
143
|
+
0x3e35,0x1fc7,0x3dd5,0x89d4,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
__constant const unsigned short APFN[36] = {
|
|
147
|
+
0x3fc7,0xba0f,0x8e7d,0x5db5,
|
|
148
|
+
0x3fec,0x5ff2,0x3d14,0xd07e,
|
|
149
|
+
0x3fef,0x98b7,0x11be,0x01af,
|
|
150
|
+
0x3fd9,0xadef,0x1397,0x84a1,
|
|
151
|
+
0x3fb2,0x2f0d,0xeadc,0x33d1,
|
|
152
|
+
0x3f78,0x3115,0xe347,0xa140,
|
|
153
|
+
0x3f2e,0x8be8,0x5d03,0x8059,
|
|
154
|
+
0x3ed1,0x2495,0x9f80,0x12af,
|
|
155
|
+
0x3e5a,0xab6a,0x654d,0x7d86,
|
|
156
|
+
};
|
|
157
|
+
__constant const unsigned short APFD[36] = {
|
|
158
|
+
/*0x3ff0,0x0000,0x0000,0x0000,*/
|
|
159
|
+
0x402d,0x781b,0x9628,0xcc60,
|
|
160
|
+
0x4042,0xc56d,0x2524,0x0e31,
|
|
161
|
+
0x403f,0x773d,0x09cc,0xffb8,
|
|
162
|
+
0x4025,0xfe6b,0x5163,0x03f7,
|
|
163
|
+
0x3ffc,0x9f21,0xc07a,0xc9fd,
|
|
164
|
+
0x3fc2,0x2450,0xe40e,0xf796,
|
|
165
|
+
0x3f76,0x48f2,0x3a5a,0x351a,
|
|
166
|
+
0x3f18,0xa059,0x7cfb,0x63a1,
|
|
167
|
+
0x3ea2,0xfdb8,0x5a24,0x1e2e,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
__constant const unsigned short APGN[44] = {
|
|
171
|
+
0xbfa2,0x351f,0x5f87,0xaf5b,
|
|
172
|
+
0xbfe4,0x64db,0x1ff7,0x5c76,
|
|
173
|
+
0xbffb,0x564a,0xc221,0x7e49,
|
|
174
|
+
0xbff8,0x0916,0x7f6e,0x0b07,
|
|
175
|
+
0xbfe2,0x0910,0xd8b0,0x6edb,
|
|
176
|
+
0xbfba,0x234b,0x0d8c,0x9903,
|
|
177
|
+
0xbf83,0x6c54,0x7f6c,0x50df,
|
|
178
|
+
0xbf3e,0x2afa,0x2424,0x2ad0,
|
|
179
|
+
0xbee7,0xf87a,0xbc17,0xf631,
|
|
180
|
+
0xbe81,0xe81f,0x501e,0x6c10,
|
|
181
|
+
0xbe03,0x5f45,0x5e46,0x870d,
|
|
182
|
+
};
|
|
183
|
+
__constant const unsigned short APGD[40] = {
|
|
184
|
+
/*0x3ff0,0x0000,0x0000,0x0000,*/
|
|
185
|
+
0x4023,0xb7a2,0x060a,0x9812,
|
|
186
|
+
0x4035,0xa3e3,0x4724,0xfc96,
|
|
187
|
+
0x4031,0x5025,0xdb2c,0x819a,
|
|
188
|
+
0x4018,0xb702,0xd5cd,0x94e2,
|
|
189
|
+
0x3ff1,0x6a71,0x4927,0x1eb1,
|
|
190
|
+
0x3fb9,0x78de,0x4ad7,0x7bc5,
|
|
191
|
+
0x3f73,0x991a,0x4b2b,0xc1d7,
|
|
192
|
+
0x3f1e,0xf98f,0x0b16,0xbe1c,
|
|
193
|
+
0x3eb7,0x10bf,0xfdde,0x4ef3,
|
|
194
|
+
0x3e38,0xe834,0x9dc8,0x647e,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
int airy( double x, double *ai, double *aip, double *bi, double *bip )
|
|
198
|
+
{
|
|
199
|
+
typedef __constant const double *data_t;
|
|
200
|
+
double z, zz, t, f, g, uf, ug, k, zeta, theta;
|
|
201
|
+
int domflg;
|
|
202
|
+
|
|
203
|
+
domflg = 0;
|
|
204
|
+
if( x > airy_maxairy )
|
|
205
|
+
{
|
|
206
|
+
*ai = 0;
|
|
207
|
+
*aip = 0;
|
|
208
|
+
*bi = DBL_MAX;
|
|
209
|
+
*bip = DBL_MAX;
|
|
210
|
+
return(-1);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if( x < -2.09 )
|
|
214
|
+
{
|
|
215
|
+
domflg = 15;
|
|
216
|
+
t = sqrt(-x);
|
|
217
|
+
zeta = -2.0 * x * t / 3.0;
|
|
218
|
+
t = sqrt(t);
|
|
219
|
+
k = airy_sqpii / t;
|
|
220
|
+
z = 1.0/zeta;
|
|
221
|
+
zz = z * z;
|
|
222
|
+
uf = 1.0 + zz * cephes_polevl( zz, (data_t) AFN, 8 ) / cephes_p1evl( zz, (data_t) AFD, 9 );
|
|
223
|
+
ug = z * cephes_polevl( zz, (data_t) AGN, 10 ) / cephes_p1evl( zz, (data_t) AGD, 10 );
|
|
224
|
+
theta = zeta + 0.25 * M_PI;
|
|
225
|
+
f = sin( theta );
|
|
226
|
+
g = cos( theta );
|
|
227
|
+
*ai = k * (f * uf - g * ug);
|
|
228
|
+
*bi = k * (g * uf + f * ug);
|
|
229
|
+
uf = 1.0 + zz * cephes_polevl( zz, (data_t) APFN, 8 ) / cephes_p1evl( zz, (data_t) APFD, 9 );
|
|
230
|
+
ug = z * cephes_polevl( zz, (data_t) APGN, 10 ) / cephes_p1evl( zz, (data_t) APGD, 10 );
|
|
231
|
+
k = airy_sqpii * t;
|
|
232
|
+
*aip = -k * (g * uf + f * ug);
|
|
233
|
+
*bip = k * (f * uf - g * ug);
|
|
234
|
+
return(0);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if( x >= 2.09 ) /* cbrt(9) */
|
|
238
|
+
{
|
|
239
|
+
domflg = 5;
|
|
240
|
+
t = sqrt(x);
|
|
241
|
+
zeta = 2.0 * x * t / 3.0;
|
|
242
|
+
g = exp( zeta );
|
|
243
|
+
t = sqrt(t);
|
|
244
|
+
k = 2.0 * t * g;
|
|
245
|
+
z = 1.0/zeta;
|
|
246
|
+
f = cephes_polevl( z, (data_t) AN, 7 ) / cephes_polevl( z, (data_t) AD, 7 );
|
|
247
|
+
*ai = airy_sqpii * f / k;
|
|
248
|
+
k = -0.5 * airy_sqpii * t / g;
|
|
249
|
+
f = cephes_polevl( z, (data_t) APN, 7 ) / cephes_polevl( z, (data_t) APD, 7 );
|
|
250
|
+
*aip = f * k;
|
|
251
|
+
|
|
252
|
+
if( x > 8.3203353 ) /* zeta > 16 */
|
|
253
|
+
{
|
|
254
|
+
f = z * cephes_polevl( z, (data_t) BN16, 4 ) / cephes_p1evl( z, (data_t) BD16, 5 );
|
|
255
|
+
k = airy_sqpii * g;
|
|
256
|
+
*bi = k * (1.0 + f) / t;
|
|
257
|
+
f = z * cephes_polevl( z, (data_t) BPPN, 4 ) / cephes_p1evl( z, (data_t) BPPD, 5 );
|
|
258
|
+
*bip = k * t * (1.0 + f);
|
|
259
|
+
return(0);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
f = 1.0;
|
|
264
|
+
g = x;
|
|
265
|
+
t = 1.0;
|
|
266
|
+
uf = 1.0;
|
|
267
|
+
ug = x;
|
|
268
|
+
k = 1.0;
|
|
269
|
+
z = x * x * x;
|
|
270
|
+
while( t > DBL_EPSILON )
|
|
271
|
+
{
|
|
272
|
+
uf *= z;
|
|
273
|
+
k += 1.0;
|
|
274
|
+
uf /=k;
|
|
275
|
+
ug *= z;
|
|
276
|
+
k += 1.0;
|
|
277
|
+
ug /=k;
|
|
278
|
+
uf /=k;
|
|
279
|
+
f += uf;
|
|
280
|
+
k += 1.0;
|
|
281
|
+
ug /=k;
|
|
282
|
+
g += ug;
|
|
283
|
+
t = fabs(uf/f);
|
|
284
|
+
}
|
|
285
|
+
uf = airy_c1 * f;
|
|
286
|
+
ug = airy_c2 * g;
|
|
287
|
+
if( (domflg & 1) == 0 )
|
|
288
|
+
*ai = uf - ug;
|
|
289
|
+
if( (domflg & 2) == 0 )
|
|
290
|
+
*bi = airy_sqrt3 * (uf + ug);
|
|
291
|
+
|
|
292
|
+
/* the deriviative of ai */
|
|
293
|
+
k = 4.0;
|
|
294
|
+
uf = x * x/2.0;
|
|
295
|
+
ug = z/3.0;
|
|
296
|
+
f = uf;
|
|
297
|
+
g = 1.0 + ug;
|
|
298
|
+
uf /= 3.0;
|
|
299
|
+
t = 1.0;
|
|
300
|
+
|
|
301
|
+
while( t > DBL_EPSILON )
|
|
302
|
+
{
|
|
303
|
+
uf *= z;
|
|
304
|
+
ug /=k;
|
|
305
|
+
k += 1.0;
|
|
306
|
+
ug *= z;
|
|
307
|
+
uf /=k;
|
|
308
|
+
f += uf;
|
|
309
|
+
k += 1.0;
|
|
310
|
+
ug /=k;
|
|
311
|
+
uf /=k;
|
|
312
|
+
g += ug;
|
|
313
|
+
k += 1.0;
|
|
314
|
+
t = fabs(ug/g);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
uf = airy_c1 * f;
|
|
318
|
+
ug = airy_c2 * g;
|
|
319
|
+
if( (domflg & 4) == 0 )
|
|
320
|
+
*aip = uf - ug;
|
|
321
|
+
if( (domflg & 8) == 0 )
|
|
322
|
+
*bip = airy_sqrt3 * (uf + ug);
|
|
323
|
+
return(0);
|
|
324
|
+
}
|