|
1 | 1 | @testset "helper functions" begin
|
2 |
| - # Hits fallback, since we can't update `Diagonal`s in place |
3 |
| - X = Diagonal([1, 1]) |
4 |
| - Y = copy(X) |
5 |
| - @test ChainRules._update!(X, [1 2; 3 4]) == [2 2; 3 5] |
6 |
| - @test X == Y # no change to X |
| 2 | + @testset "_update! Array" begin |
| 3 | + # Hits fallback, since we can't update `Diagonal`s in place |
| 4 | + X = Diagonal([1, 1]) |
| 5 | + Y = copy(X) |
| 6 | + @test ChainRules._update!(X, [1 2; 3 4]) == [2 2; 3 5] |
| 7 | + @test X == Y # no change to X |
7 | 8 |
|
8 |
| - X = [1 2; 3 4] |
9 |
| - Y = copy(X) |
10 |
| - @test ChainRules._update!(X, Diagonal([1, 1])) == [2 2; 3 5] |
11 |
| - @test X != Y # X has been updated |
| 9 | + X = [1 2; 3 4] |
| 10 | + Y = copy(X) |
| 11 | + @test ChainRules._update!(X, Diagonal([1, 1])) == [2 2; 3 5] |
| 12 | + @test X != Y # X has been updated |
| 13 | + end |
12 | 14 |
|
13 |
| - # Reusing above X |
14 |
| - @test ChainRules._update!(X, Zero()) === X |
15 |
| - @test ChainRules._update!(Zero(), X) === X |
16 |
| - @test ChainRules._update!(Zero(), Zero()) === Zero() |
| 15 | + @testset "_update! Zero" begin |
| 16 | + X = [1 2; 3 4] |
| 17 | + @test ChainRules._update!(X, Zero()) === X |
| 18 | + @test ChainRules._update!(Zero(), X) === X |
| 19 | + @test ChainRules._update!(Zero(), Zero()) === Zero() |
17 | 20 |
|
18 |
| - X = (A=[1 0; 0 1], B=[2 2; 2 2]) |
19 |
| - Y = deepcopy(X) |
20 |
| - @test ChainRules._update!(X, Y) == (A=[2 0; 0 2], B=[4 4; 4 4]) |
21 |
| - @test X.A != Y.A |
22 |
| - @test X.B != Y.B |
| 21 | + X = (A=[1 0; 0 1], B=[2 2; 2 2]) |
| 22 | + Y = deepcopy(X) |
| 23 | + @test ChainRules._update!(X, Y) == (A=[2 0; 0 2], B=[4 4; 4 4]) |
| 24 | + @test X.A != Y.A |
| 25 | + @test X.B != Y.B |
| 26 | + end |
23 | 27 |
|
24 |
| - try |
25 |
| - @eval cool(x,y)=x+y |
26 |
| - # We defined a 2-arg method for `cool` but no `rrule` |
27 |
| - ChainRules._checked_rrule(cool, 1.0, 2.0) |
28 |
| - catch e |
29 |
| - @test e isa ArgumentError |
30 |
| - @test e.msg == "can't differentiate `cool(::Float64, ::Float64)`; no " * |
31 |
| - "matching `rrule` is defined" |
| 28 | + @testset "_checked_rrule" begin |
| 29 | + try |
| 30 | + @eval cool(x,y)= x + y |
| 31 | + # We defined a 2-arg method for `cool` but no `rrule` |
| 32 | + ChainRules._checked_rrule(cool, 1.0, 2.0) |
| 33 | + catch e |
| 34 | + @test e isa ArgumentError |
| 35 | + @test e.msg == "can't differentiate `cool(::Float64, ::Float64)`; no " * |
| 36 | + "matching `rrule` is defined" |
| 37 | + end |
32 | 38 | end
|
33 | 39 | end
|
0 commit comments