From 6c4ad98bb7f53a36436cfbb48f7cb3ff9605fa3b Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 25 Nov 2018 10:21:14 -0600 Subject: [PATCH] Support Dual{T}(x) --- src/dual.jl | 1 + test/automatic_differentiation_test.jl | 1 + test/runtests.jl | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/dual.jl b/src/dual.jl index 653e559..fd70e87 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -6,6 +6,7 @@ struct Dual{T<:ReComp} <: Number end Dual(x::S, y::T) where {S<:ReComp,T<:ReComp} = Dual(promote(x,y)...) Dual(x::ReComp) = Dual(x, zero(x)) +Dual{T}(x::ReComp) where T<:ReComp = Dual{T}(T(x), zero(T)) const ɛ = Dual(false, true) const imɛ = Dual(Complex(false, false), Complex(false, true)) diff --git a/test/automatic_differentiation_test.jl b/test/automatic_differentiation_test.jl index 1d6faee..a0d44a1 100644 --- a/test/automatic_differentiation_test.jl +++ b/test/automatic_differentiation_test.jl @@ -25,6 +25,7 @@ y = abs(-x) @test epsilon(y) ≈ 1.0 @test isequal(1.0,Dual(1.0)) +@test Dual{Float32}(3) === Dual{Float32}(3.0f0, 0.0f0) y = 1/x @test value(y) ≈ 1/2 diff --git a/test/runtests.jl b/test/runtests.jl index d993c20..9ff3071 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,8 @@ using DualNumbers using Test +@test isempty(detect_ambiguities(DualNumbers, Base, Core)) + @test checkindex(Bool, 1:3, dual(2)) # wrap in individual modules to avoid name conflicts.