From 80b9d5dfddeaaa444f9ab27846440e3eefe617c5 Mon Sep 17 00:00:00 2001 From: Paul Tiede Date: Fri, 11 Nov 2022 08:27:09 -0500 Subject: [PATCH] dual exponent (#605) * add exponent(::Dual) * revert spacing --- src/dual.jl | 2 ++ test/DualTest.jl | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dual.jl b/src/dual.jl index 1cf31731..7e86e9b2 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -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 diff --git a/test/DualTest.jl b/test/DualTest.jl index b09f0594..0ec2beec 100644 --- a/test/DualTest.jl +++ b/test/DualTest.jl @@ -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 @@ -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) @@ -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)