|
1 |
| -@testset "SpecialFunctions" for x in (1.0, -1.0, 0.0, 0.5, 10.0, -17.1, 1.5 + 0.7im) |
2 |
| - test_scalar(SpecialFunctions.erf, x) |
3 |
| - test_scalar(SpecialFunctions.erfc, x) |
4 |
| - test_scalar(SpecialFunctions.erfi, x) |
| 1 | +@testset "general: single input" begin |
| 2 | + for x in (1.0, -1.0, 0.0, 0.5, 10.0, -17.1, 1.5 + 0.7im) |
| 3 | + test_scalar(SpecialFunctions.erf, x) |
| 4 | + test_scalar(SpecialFunctions.erfc, x) |
| 5 | + test_scalar(SpecialFunctions.erfi, x) |
5 | 6 |
|
6 |
| - test_scalar(SpecialFunctions.airyai, x) |
7 |
| - test_scalar(SpecialFunctions.airyaiprime, x) |
8 |
| - test_scalar(SpecialFunctions.airybi, x) |
9 |
| - test_scalar(SpecialFunctions.airybiprime, x) |
| 7 | + test_scalar(SpecialFunctions.airyai, x) |
| 8 | + test_scalar(SpecialFunctions.airyaiprime, x) |
| 9 | + test_scalar(SpecialFunctions.airybi, x) |
| 10 | + test_scalar(SpecialFunctions.airybiprime, x) |
10 | 11 |
|
11 |
| - test_scalar(SpecialFunctions.besselj0, x) |
12 |
| - test_scalar(SpecialFunctions.besselj1, x) |
| 12 | + test_scalar(SpecialFunctions.erfcx, x) |
| 13 | + test_scalar(SpecialFunctions.dawson, x) |
13 | 14 |
|
14 |
| - test_scalar(SpecialFunctions.erfcx, x) |
15 |
| - test_scalar(SpecialFunctions.dawson, x) |
| 15 | + if x isa Real |
| 16 | + test_scalar(SpecialFunctions.invdigamma, x) |
| 17 | + end |
16 | 18 |
|
17 |
| - if x isa Real |
18 |
| - test_scalar(SpecialFunctions.invdigamma, x) |
19 |
| - end |
| 19 | + if x isa Real && 0 < x < 1 |
| 20 | + test_scalar(SpecialFunctions.erfinv, x) |
| 21 | + test_scalar(SpecialFunctions.erfcinv, x) |
| 22 | + end |
20 | 23 |
|
21 |
| - if x isa Real && 0 < x < 1 |
22 |
| - test_scalar(SpecialFunctions.erfinv, x) |
23 |
| - test_scalar(SpecialFunctions.erfcinv, x) |
| 24 | + if x isa Real && x > 0 || x isa Complex |
| 25 | + test_scalar(SpecialFunctions.gamma, x) |
| 26 | + test_scalar(SpecialFunctions.digamma, x) |
| 27 | + test_scalar(SpecialFunctions.trigamma, x) |
| 28 | + end |
24 | 29 | end
|
| 30 | +end |
| 31 | + |
| 32 | +@testset "Bessel functions" begin |
| 33 | + for x in (1.5, 2.5, 10.5, -0.6, -2.6, -3.3, 1.6 + 1.6im, 1.6 - 1.6im, -4.6 + 1.6im) |
| 34 | + test_scalar(SpecialFunctions.besselj0, x) |
| 35 | + test_scalar(SpecialFunctions.besselj1, x) |
| 36 | + |
| 37 | + isreal(x) && x < 0 && continue |
25 | 38 |
|
26 |
| - if x isa Real && x > 0 || x isa Complex |
27 | 39 | test_scalar(SpecialFunctions.bessely0, x)
|
28 | 40 | test_scalar(SpecialFunctions.bessely1, x)
|
29 |
| - test_scalar(SpecialFunctions.gamma, x) |
30 |
| - test_scalar(SpecialFunctions.digamma, x) |
31 |
| - test_scalar(SpecialFunctions.trigamma, x) |
| 41 | + |
| 42 | + for nu in (-1.5, 2.2, 4.0) |
| 43 | + test_frule(SpecialFunctions.besseli, nu, x) |
| 44 | + test_rrule(SpecialFunctions.besseli, nu, x) |
| 45 | + |
| 46 | + test_frule(SpecialFunctions.besselj, nu, x) |
| 47 | + test_rrule(SpecialFunctions.besselj, nu, x) |
| 48 | + |
| 49 | + test_frule(SpecialFunctions.besselk, nu, x) |
| 50 | + test_rrule(SpecialFunctions.besselk, nu, x) |
| 51 | + |
| 52 | + test_frule(SpecialFunctions.bessely, nu, x) |
| 53 | + test_rrule(SpecialFunctions.bessely, nu, x) |
| 54 | + |
| 55 | + # use complex numbers in `rrule` for FiniteDifferences |
| 56 | + test_frule(SpecialFunctions.hankelh1, nu, x) |
| 57 | + test_rrule(SpecialFunctions.hankelh1, nu, complex(x)) |
| 58 | + |
| 59 | + # use complex numbers in `rrule` for FiniteDifferences |
| 60 | + test_frule(SpecialFunctions.hankelh2, nu, x) |
| 61 | + test_rrule(SpecialFunctions.hankelh2, nu, complex(x)) |
| 62 | + end |
| 63 | + end |
| 64 | +end |
| 65 | + |
| 66 | +@testset "beta and logbeta" begin |
| 67 | + test_points = (1.5, 2.5, 10.5, 1.6 + 1.6im, 1.6 - 1.6im, 4.6 + 1.6im) |
| 68 | + for _x in test_points, _y in test_points |
| 69 | + # ensure all complex if any complex for FiniteDifferences |
| 70 | + x, y = promote(_x, _y) |
| 71 | + test_frule(SpecialFunctions.beta, x, y) |
| 72 | + test_rrule(SpecialFunctions.beta, x, y) |
| 73 | + |
| 74 | + if isdefined(SpecialFunctions, :lbeta) |
| 75 | + test_frule(SpecialFunctions.lbeta, x, y) |
| 76 | + test_rrule(SpecialFunctions.lbeta, x, y) |
| 77 | + end |
| 78 | + |
| 79 | + if isdefined(SpecialFunctions, :logbeta) |
| 80 | + test_frule(SpecialFunctions.logbeta, x, y) |
| 81 | + test_rrule(SpecialFunctions.logbeta, x, y) |
| 82 | + end |
32 | 83 | end
|
33 | 84 | end
|
34 | 85 |
|
35 |
| -# SpecialFunctions 0.7->0.8 changes: |
36 | 86 | @testset "log gamma and co" begin
|
37 |
| - #It is important that we have negative numbers with both odd and even integer parts |
38 |
| - for x in (1.5, 2.5, 10.5, -0.6, -2.6, -3.3, 1.6+1.6im, 1.6-1.6im, -4.6+1.6im) |
| 87 | + # It is important that we have negative numbers with both odd and even integer parts |
| 88 | + for x in (1.5, 2.5, 10.5, -0.6, -2.6, -3.3, 1.6 + 1.6im, 1.6 - 1.6im, -4.6 + 1.6im) |
| 89 | + for m in (0, 1, 2, 3) |
| 90 | + test_frule(SpecialFunctions.polygamma, m, x) |
| 91 | + test_rrule(SpecialFunctions.polygamma, m, x) |
| 92 | + end |
| 93 | + |
39 | 94 | if isdefined(SpecialFunctions, :lgamma)
|
40 | 95 | test_scalar(SpecialFunctions.lgamma, x)
|
41 | 96 | end
|
| 97 | + |
42 | 98 | if isdefined(SpecialFunctions, :loggamma)
|
43 | 99 | isreal(x) && x < 0 && continue
|
44 | 100 | test_scalar(SpecialFunctions.loggamma, x)
|
45 | 101 | end
|
46 | 102 |
|
47 | 103 | if isdefined(SpecialFunctions, :logabsgamma)
|
48 | 104 | isreal(x) || continue
|
49 |
| - test_frule(logabsgamma, x) |
50 |
| - test_rrule(logabsgamma, x; output_tangent=(randn(), randn())) |
| 105 | + test_frule(SpecialFunctions.logabsgamma, x) |
| 106 | + test_rrule(SpecialFunctions.logabsgamma, x; output_tangent=(randn(), randn())) |
51 | 107 | end
|
52 | 108 | end
|
53 | 109 | end
|
0 commit comments