Skip to content

Commit

Permalink
Merge pull request #503 from sethaxen/div
Browse files Browse the repository at this point in the history
Overload div for Dual
  • Loading branch information
oxinabox authored Feb 2, 2021
2 parents 966eb27 + 0c2d979 commit a884ddd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ForwardDiff"
uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "0.10.15"
version = "0.10.16"

[deps]
CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950"
Expand Down
6 changes: 6 additions & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ Base.trunc(d::Dual) = trunc(value(d))
Base.round(::Type{R}, d::Dual) where {R<:Real} = round(R, value(d))
Base.round(d::Dual) = round(value(d))

if VERSION v"1.4"
Base.div(x::Dual, y::Dual, r::RoundingMode) = div(value(x), value(y), r)
else
Base.div(x::Dual, y::Dual) = div(value(x), value(y))
end

Base.hash(d::Dual) = hash(value(d))
Base.hash(d::Dual, hsh::UInt) = hash(value(d), hsh)

Expand Down
13 changes: 13 additions & 0 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
@test round(FDNUM2) === round(PRIMAL2)
@test round(NESTED_FDNUM) === round(PRIMAL)

@test div(FDNUM, FDNUM2) === div(PRIMAL, PRIMAL2)
@test div(FDNUM, PRIMAL2) === div(PRIMAL, PRIMAL2)
@test div(PRIMAL, FDNUM2) === div(PRIMAL, PRIMAL2)

@test div(NESTED_FDNUM, NESTED_FDNUM2) === div(PRIMAL, PRIMAL2)
@test div(NESTED_FDNUM, PRIMAL2) === div(PRIMAL, PRIMAL2)
@test div(PRIMAL, NESTED_FDNUM2) === div(PRIMAL, PRIMAL2)

if VERSION v"1.4"
@test div(FDNUM, FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)
@test div(NESTED_FDNUM, NESTED_FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)
end

@test Base.rtoldefault(typeof(FDNUM)) Base.rtoldefault(typeof(PRIMAL))
@test Dual{TestTag()}(PRIMAL-eps(V), PARTIALS) FDNUM
@test Base.rtoldefault(typeof(NESTED_FDNUM)) Base.rtoldefault(typeof(PRIMAL))
Expand Down

2 comments on commit a884ddd

@oxinabox
Copy link
Member Author

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/29180

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.16 -m "<description of version>" a884ddd1f71f54db765cf41e6ecc5a38fd6db70e
git push origin v0.10.16

Please sign in to comment.