|
104 | 104 |
|
105 | 105 | @testset "Comparison vs Calculus.jl" begin
|
106 | 106 |
|
| 107 | +@testset "$f(x::Vector)::Vector" for f in DiffTests.VECTOR_TO_VECTOR_FUNCS |
| 108 | + v = f(X) |
| 109 | + j = ForwardDiff.jacobian(f, X) |
| 110 | + @test isapprox(j, Calculus.jacobian(f, X, :forward), atol=1.3FINITEDIFF_ERROR) |
| 111 | + |
| 112 | + @testset "chunk size = $c and tag = $(repr(tag))" for c in CHUNK_SIZES, tag in (nothing, Tag(f, eltype(X))) |
| 113 | + cfg = JacobianConfig(f, X, ForwardDiff.Chunk{c}(), tag) |
| 114 | + |
| 115 | + out = ForwardDiff.jacobian(f, X, cfg) |
| 116 | + @test isapprox(out, j) |
| 117 | + |
| 118 | + out = similar(X, length(v), length(X)) |
| 119 | + ForwardDiff.jacobian!(out, f, X, cfg) |
| 120 | + @test isapprox(out, j) |
| 121 | + |
| 122 | + out = DiffResults.DiffResult(similar(v, length(v)), similar(v, length(v), length(X))) |
| 123 | + ForwardDiff.jacobian!(out, f, X, cfg) |
| 124 | + @test isapprox(DiffResults.value(out), v) |
| 125 | + @test isapprox(DiffResults.jacobian(out), j) |
| 126 | + end |
| 127 | +end |
| 128 | + |
| 129 | +@testset "$f(x::Matrix)::Matrix" for f in DiffTests.MATRIX_TO_MATRIX_FUNCS |
| 130 | + v = f(XX) |
| 131 | + j = ForwardDiff.jacobian(f, XX) |
| 132 | + @test isapprox(j, Calculus.jacobian(x -> vec(f(reshape(x, size(XX)))), vec(XX), :forward), atol=1.3FINITEDIFF_ERROR) |
| 133 | + |
| 134 | + @testset "chunk size = $c and tag = $(repr(tag))" for c in CHUNK_SIZES, tag in (nothing, Tag(f, eltype(XX))) |
| 135 | + cfg = JacobianConfig(f, XX, ForwardDiff.Chunk{c}(), tag) |
| 136 | + |
| 137 | + out = ForwardDiff.jacobian(f, XX, cfg) |
| 138 | + @test isapprox(out, j) |
| 139 | + |
| 140 | + out = similar(XX, length(v), length(XX)) |
| 141 | + ForwardDiff.jacobian!(out, f, XX, cfg) |
| 142 | + @test isapprox(out, j) |
| 143 | + |
| 144 | + out = DiffResults.DiffResult(similar(v, length(v)), similar(v, length(v), length(XX))) |
| 145 | + ForwardDiff.jacobian!(out, f, XX, cfg) |
| 146 | + @test isapprox(DiffResults.value(out), vec(v)) |
| 147 | + @test isapprox(DiffResults.jacobian(out), j) |
| 148 | + end |
| 149 | +end |
| 150 | + |
107 | 151 | @testset "$f(x::Array)::Array" for f in DiffTests.ARRAY_TO_ARRAY_FUNCS
|
108 | 152 | v = f(X)
|
109 | 153 | j = ForwardDiff.jacobian(f, X)
|
|
0 commit comments