|
| 1 | +@testset "chainrules.jl" begin |
| 2 | + x = rand() |
| 3 | + test_frule(xlogx, x) |
| 4 | + test_rrule(xlogx, x) |
| 5 | + for x in (-x, 0.0, x) |
| 6 | + y = rand() |
| 7 | + test_frule(xlogy, x, y) |
| 8 | + test_rrule(xlogy, x, y) |
| 9 | + end |
| 10 | + |
| 11 | + test_frule(logit, x) |
| 12 | + test_rrule(logit, x) |
| 13 | + |
| 14 | + for x in (-randexp(), randexp()) |
| 15 | + test_frule(log1psq, x) |
| 16 | + test_rrule(log1psq, x) |
| 17 | + end |
| 18 | + |
| 19 | + # test all `Float64` and `Float32` branches of `logistic` |
| 20 | + for x in (-821.4, -23.5, 12.3, 41.2) |
| 21 | + test_frule(logistic, x) |
| 22 | + test_rrule(logistic, x) |
| 23 | + end |
| 24 | + for x in (-123.2f0, -21.4f0, 8.3f0, 21.5f0) |
| 25 | + test_frule(logistic, x; rtol=1f-3, atol=1f-3) |
| 26 | + test_rrule(logistic, x; rtol=1f-3, atol=1f-3) |
| 27 | + end |
| 28 | + |
| 29 | + # test all branches of `log1pexp` |
| 30 | + for x in (-20.9, 15.4, 41.5) |
| 31 | + test_frule(log1pexp, x) |
| 32 | + test_rrule(log1pexp, x) |
| 33 | + end |
| 34 | + for x in (8.3f0, 12.5f0, 21.2f0) |
| 35 | + test_frule(log1pexp, x; rtol=1f-3, atol=1f-3) |
| 36 | + test_rrule(log1pexp, x; rtol=1f-3, atol=1f-3) |
| 37 | + end |
| 38 | + |
| 39 | + for x in (-10.2, -3.3, -0.3) |
| 40 | + test_frule(log1mexp, x) |
| 41 | + test_rrule(log1mexp, x) |
| 42 | + end |
| 43 | + |
| 44 | + for x in (-10.2, -3.3, -0.3, 0.5) |
| 45 | + test_frule(log2mexp, x) |
| 46 | + test_rrule(log2mexp, x) |
| 47 | + end |
| 48 | + |
| 49 | + # test all branches of `logexpm1` |
| 50 | + for x in (5.2, 21.4, 41.5) |
| 51 | + test_frule(logexpm1, x) |
| 52 | + test_rrule(logexpm1, x) |
| 53 | + end |
| 54 | + for x in (4.3f0, 12.5f0, 21.2f0) |
| 55 | + test_frule(logexpm1, x; rtol=1f-3, atol=1f-3) |
| 56 | + test_rrule(logexpm1, x; rtol=1f-3, atol=1f-3) |
| 57 | + end |
| 58 | + |
| 59 | + for x in (-randexp(), randexp()), y in (-randexp(), randexp()) |
| 60 | + test_frule(logaddexp, x, y) |
| 61 | + test_rrule(logaddexp, x, y) |
| 62 | + |
| 63 | + test_frule(logsubexp, x, y) |
| 64 | + test_rrule(logsubexp, x, y) |
| 65 | + end |
| 66 | + |
| 67 | + for x in (randn(10), randn(10, 8)), dims in (:, 1, 1:2, 2) |
| 68 | + dims isa Colon || all(d <= ndims(x) for d in dims) || continue |
| 69 | + test_frule(logsumexp, x; fkwargs=(dims=dims,)) |
| 70 | + test_rrule(logsumexp, x; fkwargs=(dims=dims,)) |
| 71 | + end |
| 72 | + |
| 73 | + for x in (randn(10), randn(10, 8)) |
| 74 | + for r in (similar(x), similar(x, 1, size(x)...)) |
| 75 | + test_frule(softmax!, r, x) |
| 76 | + test_rrule(softmax!, r, x) |
| 77 | + end |
| 78 | + end |
| 79 | +end |
0 commit comments