Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Apr 24, 2022
1 parent c3203bf commit 5f4bf0f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
34 changes: 23 additions & 11 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
PARTIALS3 = Partials{N,V}(ntuple(n -> intrand(V), N))
PRIMAL3 = intrand(V)
FDNUM3 = Dual{TestTag()}(PRIMAL3, PARTIALS3)

if !allunique([PRIMAL, PRIMAL2, PRIMAL3])
@info "testing with non-unique primals" PRIMAL PRIMAL2 PRIMAL3
end
if N > 0 && !allunique([PARTIALS, PARTIALS2, PARTIALS3])
@info "testing with non-unique partials" PARTIALS PARTIALS2 PARTIALS3
end

M_PARTIALS = Partials{M,V}(ntuple(m -> intrand(V), M))
NESTED_PARTIALS = convert(Partials{N,Dual{TestTag(),V,M}}, PARTIALS)
Expand Down Expand Up @@ -210,22 +217,27 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
@test ForwardDiff.isconstant(one(NESTED_FDNUM))
@test ForwardDiff.isconstant(NESTED_FDNUM) == (N == 0)

@test isequal(FDNUM, Dual{TestTag()}(PRIMAL, PARTIALS2)) == (N == 0)
@test isequal(PRIMAL, PRIMAL2) == isequal(FDNUM, FDNUM2)

# Recall that FDNUM = Dual{TestTag()}(PRIMAL, PARTIALS) has N partials,
# and FDNUM2 has everything with a 2, and all random numbers nonzero.
# M is the length of M_PARTIALS, which affects:
# NESTED_FDNUM = Dual{TestTag()}(Dual{TestTag()}(PRIMAL, M_PARTIALS), NESTED_PARTIALS)

@show N M NESTED_FDNUM PRIMAL M_PARTIALS2 NESTED_PARTIALS2
@test isequal(NESTED_FDNUM, Dual{TestTag()}(Dual{TestTag()}(PRIMAL, M_PARTIALS2), NESTED_PARTIALS2)) == (N == M == 0)
@show N M NESTED_FDNUM NESTED_FDNUM2 PRIMAL PRIMAL2
@test isequal(NESTED_FDNUM, NESTED_FDNUM2) == isequal(PRIMAL, PRIMAL2)

@test (FDNUM == Dual{TestTag()}(PRIMAL, PARTIALS2)) == (N == 0)
@test (PRIMAL == PRIMAL2) == (FDNUM == FDNUM2)
@test (PRIMAL == PRIMAL2) == (NESTED_FDNUM == NESTED_FDNUM2)
@test (FDNUM == Dual{TestTag()}(PRIMAL, PARTIALS2)) == (PARTIALS == PARTIALS2)
@test isequal(FDNUM, Dual{TestTag()}(PRIMAL, PARTIALS2)) == (PARTIALS == PARTIALS2)
@test isequal(NESTED_FDNUM, Dual{TestTag()}(Dual{TestTag()}(PRIMAL, M_PARTIALS2), NESTED_PARTIALS2)) == ((M_PARTIALS == M_PARTIALS2) && (NESTED_PARTIALS == NESTED_PARTIALS2))

if PRIMAL == PRIMAL2
@test isequal(FDNUM, Dual{TestTag()}(PRIMAL, PARTIALS2)) == (PARTIALS == PARTIALS2)
@test isequal(FDNUM, FDNUM2) == (PARTIALS == PARTIALS2)

@test (FDNUM == FDNUM2) == (PARTIALS == PARTIALS2)
@test (NESTED_FDNUM == NESTED_FDNUM2) == ((M_PARTIALS == M_PARTIALS2) && (NESTED_PARTIALS == NESTED_PARTIALS2))
else
@test !isequal(FDNUM, FDNUM2)

@test FDNUM != FDNUM2
@test NESTED_FDNUM != NESTED_FDNUM2
end

@test isless(Dual{TestTag()}(1, PARTIALS), Dual{TestTag()}(2, PARTIALS2))
@test !(isless(Dual{TestTag()}(1, PARTIALS), Dual{TestTag()}(1, PARTIALS2)))
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ForwardDiff, Test, Random

SEED = trunc(Int, time())
println("Testing with Random.seed!($SEED)")
println("##### Random.seed!($SEED), on VERSION == $VERSION")
Random.seed!(SEED)

@testset "ForwardDiff.jl" begin
Expand Down Expand Up @@ -53,5 +53,5 @@ Random.seed!(SEED)
println("##### done (took $t seconds).")
end
end
println("##### Running all ForwardDiff tests took $(t0 - time()) seconds.")
println("##### Running all ForwardDiff tests took $(time() - t0) seconds.")
end

0 comments on commit 5f4bf0f

Please sign in to comment.