|
5 | 5 | for x in (1.0, -1.0, 0.0, 0.5, 10.0, -17.1, 1.5 + 0.7im)
|
6 | 6 | test_scalar(erf, x)
|
7 | 7 | test_scalar(erfc, x)
|
| 8 | + test_scalar(erfcx, x) |
8 | 9 | test_scalar(erfi, x)
|
9 | 10 |
|
10 | 11 | test_scalar(airyai, x)
|
11 | 12 | test_scalar(airyaiprime, x)
|
12 | 13 | test_scalar(airybi, x)
|
13 | 14 | test_scalar(airybiprime, x)
|
14 | 15 |
|
15 |
| - test_scalar(erfcx, x) |
16 | 16 | test_scalar(dawson, x)
|
17 | 17 |
|
18 | 18 | if x isa Real
|
| 19 | + test_scalar(logerfc, x) |
| 20 | + test_scalar(logerfcx, x) |
| 21 | + |
19 | 22 | test_scalar(invdigamma, x)
|
20 | 23 | end
|
21 | 24 |
|
|
28 | 31 | test_scalar(gamma, x)
|
29 | 32 | test_scalar(digamma, x)
|
30 | 33 | test_scalar(trigamma, x)
|
| 34 | + |
| 35 | + if x isa Real |
| 36 | + test_scalar(airyaix, x) |
| 37 | + test_scalar(airyaiprimex, x) |
| 38 | + end |
31 | 39 | end
|
32 | 40 | end
|
33 | 41 | end
|
|
51 | 59 |
|
52 | 60 | test_frule(besselk, nu, x)
|
53 | 61 | test_rrule(besselk, nu, x)
|
| 62 | + test_frule(besselkx, nu, x) |
| 63 | + test_rrule(besselkx, nu, x) |
54 | 64 |
|
55 | 65 | test_frule(bessely, nu, x)
|
56 | 66 | test_rrule(bessely, nu, x)
|
57 | 67 |
|
58 |
| - # use complex numbers in `rrule` for FiniteDifferences |
59 | 68 | test_frule(hankelh1, nu, x)
|
60 |
| - test_rrule(hankelh1, nu, complex(x)) |
| 69 | + test_rrule(hankelh1, nu, x) |
| 70 | + test_frule(hankelh1x, nu, x) |
| 71 | + test_rrule(hankelh1x, nu, x) |
61 | 72 |
|
62 |
| - # use complex numbers in `rrule` for FiniteDifferences |
63 | 73 | test_frule(hankelh2, nu, x)
|
64 |
| - test_rrule(hankelh2, nu, complex(x)) |
| 74 | + test_rrule(hankelh2, nu, x) |
| 75 | + test_frule(hankelh2x, nu, x) |
| 76 | + test_rrule(hankelh2x, nu, x) |
65 | 77 | end
|
66 | 78 | end
|
67 | 79 | end
|
68 | 80 |
|
69 |
| - @testset "beta and logbeta" begin |
| 81 | + @testset "erf, beta, and logbeta" begin |
70 | 82 | test_points = (1.5, 2.5, 10.5, 1.6 + 1.6im, 1.6 - 1.6im, 4.6 + 1.6im)
|
71 |
| - for _x in test_points, _y in test_points |
72 |
| - # ensure all complex if any complex for FiniteDifferences |
73 |
| - x, y = promote(_x, _y) |
| 83 | + for x in test_points, y in test_points |
74 | 84 | test_frule(beta, x, y)
|
75 | 85 | test_rrule(beta, x, y)
|
76 | 86 |
|
77 | 87 | test_frule(logbeta, x, y)
|
78 | 88 | test_rrule(logbeta, x, y)
|
| 89 | + |
| 90 | + if x isa Real && y isa Real |
| 91 | + test_frule(erf, x, y) |
| 92 | + test_rrule(erf, x, y) |
| 93 | + end |
79 | 94 | end
|
80 | 95 | end
|
81 | 96 |
|
|
91 | 106 | isreal(x) && x < 0 && continue
|
92 | 107 | test_scalar(loggamma, x)
|
93 | 108 | for a in test_points
|
94 |
| - # ensure all complex if any complex for FiniteDifferences |
95 |
| - _a, _x = promote(a, x) |
96 |
| - test_frule(gamma, _a, _x; rtol=1e-8) |
97 |
| - test_rrule(gamma, _a, _x; rtol=1e-8) |
| 109 | + test_frule(gamma, a, x; rtol=1e-8) |
| 110 | + test_rrule(gamma, a, x; rtol=1e-8) |
98 | 111 |
|
99 |
| - test_frule(loggamma, _a, _x) |
100 |
| - test_rrule(loggamma, _a, _x) |
| 112 | + test_frule(loggamma, a, x) |
| 113 | + test_rrule(loggamma, a, x) |
101 | 114 | end
|
102 | 115 |
|
103 | 116 | isreal(x) || continue
|
|
117 | 130 | test_scalar(expintx, x)
|
118 | 131 |
|
119 | 132 | for nu in (-1.5, 2.2, 4.0)
|
120 |
| - # ensure all complex if any complex for FiniteDifferences |
121 |
| - _x, _nu = promote(x, nu) |
| 133 | + test_frule(expint, nu, x) |
| 134 | + test_rrule(expint, nu, x) |
122 | 135 |
|
123 |
| - test_frule(expint, _nu, _x) |
124 |
| - test_rrule(expint, _nu, _x) |
125 |
| - |
126 |
| - test_frule(expintx, _nu, _x) |
127 |
| - test_rrule(expintx, _nu, _x) |
| 136 | + test_frule(expintx, nu, x) |
| 137 | + test_rrule(expintx, nu, x) |
128 | 138 | end
|
129 | 139 |
|
130 | 140 | isreal(x) || continue
|
|
133 | 143 | test_scalar(cosint, x)
|
134 | 144 | end
|
135 | 145 | end
|
| 146 | + |
| 147 | + # https://github.com/JuliaMath/SpecialFunctions.jl/issues/307 |
| 148 | + @testset "promotions" begin |
| 149 | + # one argument |
| 150 | + for f in (erf, erfc, logerfc, erfcinv, erfcx, logerfcx, erfi, erfinv, sinint) |
| 151 | + _, ẏ = frule((NoTangent(), 1f0), f, 1f0) |
| 152 | + @test ẏ isa Float32 |
| 153 | + _, back = rrule(f, 1f0) |
| 154 | + _, x̄ = back(1f0) |
| 155 | + @test x̄ isa Float32 |
| 156 | + end |
| 157 | + |
| 158 | + # two arguments |
| 159 | + _, ẏ = frule((NoTangent(), 1f0, 1f0), erf, 1f0, 1f0) |
| 160 | + @test ẏ isa Float32 |
| 161 | + _, back = rrule(erf, 1f0, 1f0) |
| 162 | + _, x̄ = back(1f0) |
| 163 | + @test x̄ isa Float32 |
| 164 | + end |
136 | 165 | end
|
0 commit comments