Skip to content

Commit

Permalink
dual exponent (#605)
Browse files Browse the repository at this point in the history
* add exponent(::Dual)

* revert spacing
  • Loading branch information
ptiede authored Nov 11, 2022
1 parent 25f8f73 commit 80b9d5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

2 comments on commit 80b9d5d

@mcabbott
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/72057

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.33 -m "<description of version>" 80b9d5dfddeaaa444f9ab27846440e3eefe617c5
git push origin v0.10.33

Please sign in to comment.