From 9bea5b4ac6507c090f17ee37749141bd36e18d31 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Fri, 29 Jan 2021 03:24:16 -0800 Subject: [PATCH 1/3] Implement div for Dual --- src/dual.jl | 6 ++++++ test/DualTest.jl | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/dual.jl b/src/dual.jl index d4e99b44..feeca7d7 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -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) diff --git a/test/DualTest.jl b/test/DualTest.jl index 4e8ac909..d7dae229 100644 --- a/test/DualTest.jl +++ b/test/DualTest.jl @@ -136,6 +136,14 @@ 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(NESTED_FDNUM, 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)) From 68a6bcdd79a226e65d198dfb212550ae3fd3da79 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Fri, 29 Jan 2021 03:24:30 -0800 Subject: [PATCH 2/3] Increment version number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e8f55df4..c3eb5a18 100644 --- a/Project.toml +++ b/Project.toml @@ -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" From 0c2d979fdd131abcf88b7a68f8c34380107445db Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Mon, 1 Feb 2021 14:08:27 -0800 Subject: [PATCH 3/3] Add tests for div with literals --- test/DualTest.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/DualTest.jl b/test/DualTest.jl index d7dae229..a30f9a04 100644 --- a/test/DualTest.jl +++ b/test/DualTest.jl @@ -137,7 +137,12 @@ for N in (0,3), M in (0,4), V in (Int, Float32) @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)