Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dual exponent #605

Merged
merged 2 commits into from
Nov 11, 2022
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: 2 additions & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ Base.fld(x::Dual, y::Dual) = fld(value(x), value(y))

Base.cld(x::Dual, y::Dual) = cld(value(x), value(y))

Base.exponent(x::Dual) = exponent(value(x))

if VERSION ≥ v"1.4"
Base.div(x::Dual, y::Dual, r::RoundingMode) = div(value(x), value(y), r)
else
Expand Down
8 changes: 6 additions & 2 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::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
Expand Down Expand Up @@ -162,6 +162,10 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false
@test fld(FDNUM, PRIMAL2) === fld(PRIMAL, PRIMAL2)
@test fld(PRIMAL, FDNUM2) === fld(PRIMAL, PRIMAL2)

@test exponent(FDNUM) === exponent(PRIMAL)
@test exponent(FDNUM2) === exponent(PRIMAL2)
@test exponent(NESTED_FDNUM) === exponent(PRIMAL)

@test cld(FDNUM, FDNUM2) === cld(PRIMAL, PRIMAL2)
@test cld(FDNUM, PRIMAL2) === cld(PRIMAL, PRIMAL2)
@test cld(PRIMAL, FDNUM2) === cld(PRIMAL, PRIMAL2)
Expand Down Expand Up @@ -414,7 +418,7 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false
#----------#

if M > 0 && N > 0
# Recall that FDNUM = Dual{TestTag()}(PRIMAL, PARTIALS) has N partials,
# Recall that FDNUM = Dual{TestTag()}(PRIMAL, PARTIALS) has N partials,
# all random numbers nonzero, and FDNUM2 another draw. M only affects NESTED_FDNUM.
@test Dual{1}(FDNUM) / Dual{1}(PRIMAL) === Dual{1}(FDNUM / PRIMAL)
@test Dual{1}(PRIMAL) / Dual{1}(FDNUM) === Dual{1}(PRIMAL / FDNUM)
Expand Down