|
| 1 | +@testset "accumulation.jl" begin |
| 2 | + @testset "scalar" begin |
| 3 | + @test 16 == add!!(12, 4) |
| 4 | + end |
| 5 | + |
| 6 | + @testset "Differentials" begin |
| 7 | + @test 16 == add!!(12, @thunk(2*2)) |
| 8 | + @test 16 == add!!(16, Zero()) |
| 9 | + |
| 10 | + @test 16 == add!!(16, DoesNotExist()) # Should this be an error? |
| 11 | + end |
| 12 | + |
| 13 | + @testset "Array" begin |
| 14 | + @testset "Happy Path" begin |
| 15 | + @testset "RHS Array" begin |
| 16 | + A = [1.0 2.0; 3.0 4.0] |
| 17 | + result = -1.0*ones(2,2) |
| 18 | + ret = add!!(result, A) |
| 19 | + @test ret === result # must be same object |
| 20 | + @test result == [0.0 1.0; 2.0 3.0] |
| 21 | + end |
| 22 | + |
| 23 | + @testset "RHS StaticArray" begin |
| 24 | + A = @SMatrix[1.0 2.0; 3.0 4.0] |
| 25 | + result = -1.0*ones(2,2) |
| 26 | + ret = add!!(result, A) |
| 27 | + @test ret === result # must be same object |
| 28 | + @test result == [0.0 1.0; 2.0 3.0] |
| 29 | + end |
| 30 | + |
| 31 | + @testset "RHS Diagonal" begin |
| 32 | + A = Diagonal([1.0, 2.0]) |
| 33 | + result = -1.0*ones(2,2) |
| 34 | + ret = add!!(result, A) |
| 35 | + @test ret === result # must be same object |
| 36 | + @test result == [0.0 -1.0; -1.0 1.0] |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + @testset "Unhappy Path" begin |
| 41 | + # wrong length |
| 42 | + @test_throws DimensionMismatch add!!(ones(4,4), ones(2,2)) |
| 43 | + # wrong shape |
| 44 | + @test_throws DimensionMismatch add!!(ones(4,4), ones(16)) |
| 45 | + # wrong type (adding scalar to array) |
| 46 | + @test_throws MethodError add!!(ones(4), 21.0) |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + @testset "InplaceableThunk" begin |
| 51 | + A=[1.0 2.0; 3.0 4.0] |
| 52 | + ithunk = InplaceableThunk( |
| 53 | + @thunk(A*B), |
| 54 | + x -> x.+=A |
| 55 | + ) |
| 56 | + |
| 57 | + result = -1.0*ones(2,2) |
| 58 | + ret = add!!(result, ithunk) |
| 59 | + @test ret === result # must be same object |
| 60 | + @test result == [0.0 1.0; 2.0 3.0] |
| 61 | + end |
| 62 | +end |
0 commit comments