Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
version:
- '1.6'
- '1'
- 'nightly'
# - 'nightly'
os:
- ubuntu-latest
arch:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LogExpFunctions = "0.3"
NaNMath = "1"
Preferences = "1"
SpecialFunctions = "1, 2"
StaticArrays = "1.5"
StaticArrays = "1.5 - 1.6"
julia = "1.6"

[extras]
Expand Down
16 changes: 12 additions & 4 deletions test/AllocationsTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,25 @@ convert_test_574() = convert(ForwardDiff.Dual{Nothing,ForwardDiff.Dual{Nothing,F
index = 1
alloc = @allocated ForwardDiff.seed!(duals, x, index, seeds)
alloc = @allocated ForwardDiff.seed!(duals, x, index, seeds)
@test alloc == 0
if VERSION < v"1.9"
@test alloc == 0
else
@test_broken alloc == 0
end

index = 1
alloc = @allocated ForwardDiff.seed!(duals, x, index, seed)
alloc = @allocated ForwardDiff.seed!(duals, x, index, seed)
@test alloc == 0

if VERSION < v"1.9"
@test alloc == 0
else
@test_broken alloc == 0
end

alloc = @allocated convert_test_574()
alloc = @allocated convert_test_574()
@test alloc == 0

end

end
9 changes: 3 additions & 6 deletions test/DerivativeTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ Random.seed!(1)

const x = 1

for f in DiffTests.NUMBER_TO_NUMBER_FUNCS
println(" ...testing $f")
@testset "$f" for f in DiffTests.NUMBER_TO_NUMBER_FUNCS
v = f(x)
d = ForwardDiff.derivative(f, x)
@test isapprox(d, Calculus.derivative(f, x), atol=FINITEDIFF_ERROR)
Expand All @@ -29,8 +28,7 @@ for f in DiffTests.NUMBER_TO_NUMBER_FUNCS
@test isapprox(DiffResults.derivative(out), d)
end

for f in DiffTests.NUMBER_TO_ARRAY_FUNCS
println(" ...testing $f")
@testset "$f" for f in DiffTests.NUMBER_TO_ARRAY_FUNCS
v = f(x)
d = ForwardDiff.derivative(f, x)

Expand All @@ -47,8 +45,7 @@ for f in DiffTests.NUMBER_TO_ARRAY_FUNCS
@test isapprox(DiffResults.derivative(out), d)
end

for f! in DiffTests.INPLACE_NUMBER_TO_ARRAY_FUNCS
println(" ...testing $f!")
@testset "$(f!)" for f! in DiffTests.INPLACE_NUMBER_TO_ARRAY_FUNCS
m, n = 3, 2
y = fill(0.0, m, n)
f = x -> (tmp = similar(y, promote_type(eltype(y), typeof(x)), m, n); f!(tmp, x); tmp)
Expand Down
4 changes: 1 addition & 3 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ ForwardDiff.:≺(::Type{TestTag}, ::Type{OuterTestTag}) = true
ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false

@testset "Dual{Z,$V,$N} and Dual{Z,Dual{Z,$V,$M},$N}" for N in (0,3), M in (0,4), V in (Int, Float32)
println(" ...testing Dual{TestTag(),$V,$N} and Dual{TestTag(),Dual{TestTag(),$V,$M},$N}")

PARTIALS = Partials{N,V}(ntuple(n -> intrand(V), N))
PRIMAL = intrand(V)
Expand Down Expand Up @@ -466,13 +465,12 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false
@test abs(NESTED_FDNUM) === NESTED_FDNUM

if V != Int
@testset "$f" for (M, f, arity) in DiffRules.diffrules(filter_modules = nothing)
@testset "$(M).$(f) with $arity arguments" for (M, f, arity) in DiffRules.diffrules(filter_modules = nothing)
if f in (:/, :rem2pi)
continue # Skip these rules
elseif !(isdefined(@__MODULE__, M) && isdefined(getfield(@__MODULE__, M), f))
continue # Skip rules for methods not defined in the current scope
end
println(" ...auto-testing $(M).$(f) with $arity arguments")
if arity == 1
deriv = DiffRules.diffrule(M, f, :x)
modifier = if in(f, (:asec, :acsc, :asecd, :acscd, :acosh, :acoth))
Expand Down
12 changes: 4 additions & 8 deletions test/GradientTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ v = f(x)
g = [-9.4, 15.6, 52.0]

@testset "Rosenbrock, chunk size = $c and tag = $(repr(tag))" for c in (1, 2, 3), tag in (nothing, Tag(f, eltype(x)))
println(" ...running hardcoded test with chunk size = $c and tag = $(repr(tag))")
cfg = ForwardDiff.GradientConfig(f, x, ForwardDiff.Chunk{c}(), tag)

@test eltype(cfg) == Dual{typeof(tag), eltype(x), c}
Expand Down Expand Up @@ -60,8 +59,7 @@ cfgx = ForwardDiff.GradientConfig(sin, x)
v = f(X)
g = ForwardDiff.gradient(f, X)
@test isapprox(g, Calculus.gradient(f, X), atol=FINITEDIFF_ERROR)
for c in CHUNK_SIZES, tag in (nothing, Tag(f, eltype(x)))
println(" ...testing $f with chunk size = $c and tag = $(repr(tag))")
@testset "... with chunk size = $c and tag = $(repr(tag))" for c in CHUNK_SIZES, tag in (nothing, Tag(f, eltype(x)))
cfg = ForwardDiff.GradientConfig(f, X, ForwardDiff.Chunk{c}(), tag)

out = ForwardDiff.gradient(f, X, cfg)
Expand All @@ -82,9 +80,7 @@ end
# test specialized StaticArray codepaths #
##########################################

println(" ...testing specialized StaticArray codepaths")

@testset "$T" for T in (StaticArrays.SArray, StaticArrays.MArray)
@testset "Specialized StaticArray codepaths: $T" for T in (StaticArrays.SArray, StaticArrays.MArray)
x = rand(3, 3)

sx = T{Tuple{3,3}}(x)
Expand Down Expand Up @@ -172,7 +168,7 @@ end
function f(p)
sum(collect(0.0:p[1]:p[2]))
end
@test ForwardDiff.gradient(f, [0.2,25.0]) == [7875.0, 0.0]
@test ForwardDiff.gradient(f, [0.3, 25.0]) == [3486.0, 0.0]
end

@testset "det with branches" begin
Expand All @@ -193,7 +189,7 @@ end

# And issue 407
@test ForwardDiff.hessian(det, A) ≈ ForwardDiff.hessian(det2, A)

# https://discourse.julialang.org/t/forwarddiff-and-zygote-return-wrong-jacobian-for-log-det-l/77961
S = [1.0 0.8; 0.8 1.0]
L = cholesky(S).L
Expand Down
8 changes: 3 additions & 5 deletions test/HessianTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ h = [-66.0 -40.0 0.0;
-40.0 130.0 -80.0;
0.0 -80.0 200.0]

for c in HESSIAN_CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
println(" ...running hardcoded test with chunk size = $c and tag = $(repr(tag))")
@testset "running hardcoded test with chunk size = $c and tag = $(repr(tag))" for c in HESSIAN_CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
cfg = ForwardDiff.HessianConfig(f, x, ForwardDiff.Chunk{c}(), tag)
resultcfg = ForwardDiff.HessianConfig(f, DiffResults.HessianResult(x), x, ForwardDiff.Chunk{c}(), tag)

Expand Down Expand Up @@ -69,8 +68,7 @@ for f in DiffTests.VECTOR_TO_NUMBER_FUNCS
h = ForwardDiff.hessian(f, X)
# finite difference approximation error is really bad for Hessians...
@test isapprox(h, Calculus.hessian(f, X), atol=0.02)
for c in HESSIAN_CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
println(" ...testing $f with chunk size = $c and tag = $(repr(tag))")
@testset "$f with chunk size = $c and tag = $(repr(tag))" for c in HESSIAN_CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
cfg = ForwardDiff.HessianConfig(f, X, ForwardDiff.Chunk{c}(), tag)
resultcfg = ForwardDiff.HessianConfig(f, DiffResults.HessianResult(X), X, ForwardDiff.Chunk{c}(), tag)

Expand All @@ -93,7 +91,7 @@ end
# test specialized StaticArray codepaths #
##########################################

println(" ...testing specialized StaticArray codepaths")
@info "testing specialized StaticArray codepaths"

x = rand(3, 3)
for T in (StaticArrays.SArray, StaticArrays.MArray)
Expand Down
8 changes: 3 additions & 5 deletions test/JacobianTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ for f in DiffTests.ARRAY_TO_ARRAY_FUNCS
v = f(X)
j = ForwardDiff.jacobian(f, X)
@test isapprox(j, Calculus.jacobian(x -> vec(f(x)), X, :forward), atol=1.3FINITEDIFF_ERROR)
for c in CHUNK_SIZES, tag in (nothing, Tag)
@testset "$f with chunk size = $c and tag = $(repr(tag))" for c in CHUNK_SIZES, tag in (nothing, Tag)
if tag == Tag
tag = Tag(f, eltype(X))
end
println(" ...testing $f with chunk size = $c and tag = $(repr(tag))")
cfg = JacobianConfig(f, X, ForwardDiff.Chunk{c}(), tag)

out = ForwardDiff.jacobian(f, X, cfg)
Expand All @@ -129,8 +128,7 @@ for f! in DiffTests.INPLACE_ARRAY_TO_ARRAY_FUNCS
f!(v, X)
j = ForwardDiff.jacobian(f!, fill!(similar(Y), 0.0), X)
@test isapprox(j, Calculus.jacobian(x -> (y = fill!(similar(Y), 0.0); f!(y, x); vec(y)), X, :forward), atol=FINITEDIFF_ERROR)
for c in CHUNK_SIZES, tag in (nothing, Tag(f!, eltype(X)))
println(" ...testing $(f!) with chunk size = $c and tag = $(repr(tag))")
@testset "$(f!) with chunk size = $c and tag = $(repr(tag))" for c in CHUNK_SIZES, tag in (nothing, Tag(f!, eltype(X)))
ycfg = JacobianConfig(f!, fill!(similar(Y), 0.0), X, ForwardDiff.Chunk{c}(), tag)

y = fill!(similar(Y), 0.0)
Expand Down Expand Up @@ -164,7 +162,7 @@ end
# test specialized StaticArray codepaths #
##########################################

println(" ...testing specialized StaticArray codepaths")
@info "testing specialized StaticArray codepaths"

x = rand(3, 3)
for T in (StaticArrays.SArray, StaticArrays.MArray)
Expand Down
1 change: 0 additions & 1 deletion test/PartialsTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using ForwardDiff: Partials
samerng() = MersenneTwister(1)

@testset "Partials{$N,$T}" for N in (0, 3), T in (Int, Float32, Float64)
println(" ...testing Partials{$N,$T}")

VALUES = (rand(T,N)...,)
PARTIALS = Partials{N,T}(VALUES)
Expand Down