-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathspecialfunctions.jl
57 lines (45 loc) · 1.57 KB
/
specialfunctions.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using KernelAbstractions
import SpecialFunctions
@kernel function gamma_knl(A, @Const(B))
I = @index(Global)
@inbounds A[I] = SpecialFunctions.gamma(B[I])
end
@kernel function erf_knl(A, @Const(B))
I = @index(Global)
@inbounds A[I] = SpecialFunctions.erf(B[I])
end
@kernel function erfc_knl(A, @Const(B))
I = @index(Global)
@inbounds A[I] = SpecialFunctions.erfc(B[I])
end
function specialfunctions_testsuite(Backend)
backend = Backend()
@testset "special functions: gamma" begin
x = Float32[1.0, 2.0, 3.0, 5.5]
cx = allocate(backend, Float32, length(x))
KernelAbstractions.copyto!(backend, cx, x)
cy = similar(cx)
gamma_knl(backend)(cy, cx; ndrange = length(x))
synchronize(backend)
@test Array(cy) ≈ SpecialFunctions.gamma.(x)
end
@testset "special functions: erf" begin
x = Float32[-1.0, -0.5, 0.0, 1.0e-3, 1.0, 2.0, 5.5]
cx = allocate(backend, Float32, length(x))
KernelAbstractions.copyto!(backend, cx, x)
cy = similar(cx)
erf_knl(backend)(cy, cx; ndrange = length(x))
synchronize(backend)
@test Array(cy) ≈ SpecialFunctions.erf.(x)
end
@testset "special functions: erfc" begin
x = Float32[-1.0, -0.5, 0.0, 1.0e-3, 1.0, 2.0, 5.5]
cx = allocate(backend, Float32, length(x))
KernelAbstractions.copyto!(backend, cx, x)
cy = similar(cx)
erfc_knl(backend)(cy, cx; ndrange = length(x))
synchronize(backend)
@test Array(cy) ≈ SpecialFunctions.erfc.(x)
end
return
end