|
43 | 43 | test_scalar(acsch, x)
|
44 | 44 | test_scalar(acoth, x + 1)
|
45 | 45 | end
|
46 |
| - @testset "Inverse degrees" begin |
47 |
| - x = 0.5 |
| 46 | + @testset "Inverse degrees" for x = (0.5, Complex(0.5, 0.25)) |
48 | 47 | test_scalar(asind, x)
|
49 | 48 | test_scalar(acosd, x)
|
50 | 49 | test_scalar(atand, x)
|
|
73 | 72 | @test r === rsincos
|
74 | 73 | @test df(1, 2) === dsincos
|
75 | 74 | end
|
76 |
| - end |
77 |
| - @testset "Misc. Tests" begin |
78 |
| - @testset "*(x, y)" begin |
79 |
| - x, y = rand(3, 2), rand(2, 5) |
80 |
| - z, (dx, dy) = rrule(*, x, y) |
| 75 | + end # Trig |
81 | 76 |
|
82 |
| - @test z == x * y |
| 77 | + @testset "math" begin |
| 78 | + for x in (-0.1, 6.4, 1.0+0.5im, -10.0+0im) |
| 79 | + test_scalar(deg2rad, x) |
| 80 | + test_scalar(rad2deg, x) |
83 | 81 |
|
84 |
| - z̄ = rand(3, 5) |
| 82 | + test_scalar(inv, x) |
85 | 83 |
|
86 |
| - @test dx(z̄) == extern(accumulate(zeros(3, 2), dx, z̄)) |
87 |
| - @test dy(z̄) == extern(accumulate(zeros(2, 5), dy, z̄)) |
| 84 | + test_scalar(exp, x) |
| 85 | + test_scalar(exp2, x) |
| 86 | + test_scalar(exp10, x) |
88 | 87 |
|
89 |
| - test_accumulation(rand(3, 2), dx, z̄, z̄ * y') |
90 |
| - test_accumulation(rand(2, 5), dy, z̄, x' * z̄) |
| 88 | + x isa Real && test_scalar(cbrt, x) |
| 89 | + if (x isa Real && x >= 0) || x isa Complex |
| 90 | + test_scalar(sqrt, x) |
| 91 | + test_scalar(log, x) |
| 92 | + test_scalar(log2, x) |
| 93 | + test_scalar(log10, x) |
| 94 | + test_scalar(log1p, x) |
| 95 | + end |
91 | 96 | end
|
92 |
| - @testset "hypot(x, y)" begin |
93 |
| - x, y = rand(2) |
94 |
| - h, dxy = frule(hypot, x, y) |
| 97 | + end |
95 | 98 |
|
96 |
| - @test extern(dxy(One(), Zero())) === x / h |
97 |
| - @test extern(dxy(Zero(), One())) === y / h |
| 99 | + @testset "*(x, y)" begin |
| 100 | + x, y = rand(3, 2), rand(2, 5) |
| 101 | + z, (dx, dy) = rrule(*, x, y) |
98 | 102 |
|
99 |
| - cx, cy = cast((One(), Zero())), cast((Zero(), One())) |
100 |
| - dx, dy = extern(dxy(cx, cy)) |
101 |
| - @test dx === x / h |
102 |
| - @test dy === y / h |
| 103 | + @test z == x * y |
103 | 104 |
|
104 |
| - cx, cy = cast((rand(), Zero())), cast((Zero(), rand())) |
105 |
| - dx, dy = extern(dxy(cx, cy)) |
106 |
| - @test dx === x / h * cx.value[1] |
107 |
| - @test dy === y / h * cy.value[2] |
108 |
| - end |
| 105 | + z̄ = rand(3, 5) |
| 106 | + |
| 107 | + @test dx(z̄) == extern(accumulate(zeros(3, 2), dx, z̄)) |
| 108 | + @test dy(z̄) == extern(accumulate(zeros(2, 5), dy, z̄)) |
| 109 | + |
| 110 | + test_accumulation(rand(3, 2), dx, z̄, z̄ * y') |
| 111 | + test_accumulation(rand(2, 5), dy, z̄, x' * z̄) |
109 | 112 | end
|
| 113 | + |
| 114 | + @testset "hypot(x, y)" begin |
| 115 | + x, y = rand(2) |
| 116 | + h, dxy = frule(hypot, x, y) |
| 117 | + |
| 118 | + @test extern(dxy(One(), Zero())) === x / h |
| 119 | + @test extern(dxy(Zero(), One())) === y / h |
| 120 | + |
| 121 | + cx, cy = cast((One(), Zero())), cast((Zero(), One())) |
| 122 | + dx, dy = extern(dxy(cx, cy)) |
| 123 | + @test dx === x / h |
| 124 | + @test dy === y / h |
| 125 | + |
| 126 | + cx, cy = cast((rand(), Zero())), cast((Zero(), rand())) |
| 127 | + dx, dy = extern(dxy(cx, cy)) |
| 128 | + @test dx === x / h * cx.value[1] |
| 129 | + @test dy === y / h * cy.value[2] |
| 130 | + end |
| 131 | + |
110 | 132 | @testset "identity" begin
|
111 | 133 | rng = MersenneTwister(1)
|
112 | 134 | n = 4
|
|
0 commit comments