|
28 | 28 | sd = NoSparsityDetector() |
29 | 29 |
|
30 | 30 | for x in (rand(2), rand(2, 3)), f in (f_jac1, f_jac2) |
| 31 | + |
31 | 32 | y = f(x) |
32 | 33 | Js = jacobian_sparsity(f, x, sd) |
33 | 34 | @test Js isa AbstractMatrix |
|
36 | 37 | end |
37 | 38 |
|
38 | 39 | for x in (rand(2), rand(2, 3)), y in (rand(5), rand(5, 6)) |
| 40 | + |
39 | 41 | Js = jacobian_sparsity(f_jac!, y, x, sd) |
40 | 42 | @test Js isa AbstractMatrix |
41 | 43 | @test size(Js) == (length(y), length(x)) |
|
54 | 56 | @testset "Jacobian sparsity detection" begin |
55 | 57 | @testset "Out-of-place functions" begin |
56 | 58 | for sx in ((2,), (2, 3)), f in (f_jac1, f_jac2) |
| 59 | + |
57 | 60 | x = rand(sx...) |
58 | 61 | nx = length(x) |
59 | 62 | Jref = rand(Bool, 2 * nx, nx) |
|
66 | 69 | end |
67 | 70 | @testset "In-place functions" begin |
68 | 71 | for sx in ((2,), (2, 3)), sy in ((5,), (5, 6)) |
| 72 | + |
69 | 73 | x, y = rand(sx...), rand(sy...) |
70 | 74 | nx, ny = length(x), length(y) |
71 | 75 | Jref = rand(Bool, ny, nx) |
|
89 | 93 | @testset "Exceptions: DimensionMismatch" begin |
90 | 94 | sd = KnownJacobianSparsityDetector(rand(Bool, 6, 7)) # wrong Jacobian size |
91 | 95 | for x in (rand(2), rand(2, 3)), f in (f_jac1, f_jac2) |
| 96 | + |
92 | 97 | @test_throws DimensionMismatch jacobian_sparsity(f, x, sd) |
93 | 98 | end |
94 | 99 | for x in (rand(2), rand(2, 3)), y in (rand(5), rand(5, 6)) |
| 100 | + |
95 | 101 | @test_throws DimensionMismatch jacobian_sparsity(f_jac!, y, x, sd) |
96 | 102 | end |
97 | 103 | end |
|
114 | 120 | @testset "Exceptions: Jacobian sparsity detection not supported" begin |
115 | 121 | @testset "Out-of-place functions" begin |
116 | 122 | for sx in ((2,), (2, 3)), f in (f_jac1, f_jac2) |
| 123 | + |
117 | 124 | x = rand(sx...) |
118 | 125 | nx = length(x) |
119 | 126 | Jref = rand(Bool, 2 * nx, nx) |
|
123 | 130 | end |
124 | 131 | @testset "In-place functions" begin |
125 | 132 | for sx in ((2,), (2, 3)), sy in ((5,), (5, 6)) |
| 133 | + |
126 | 134 | x, y = rand(sx...), rand(sy...) |
127 | 135 | nx, ny = length(x), length(y) |
128 | 136 | Jref = rand(Bool, ny, nx) |
|
0 commit comments