Skip to content

Commit

Permalink
Merge pull request #71 from timholy/teh/coerce
Browse files Browse the repository at this point in the history
Support Dual{T}(x)
  • Loading branch information
dlfivefifty committed Nov 25, 2018
2 parents 27a7578 + 6c4ad98 commit 9801c7f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions test/automatic_differentiation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 9801c7f

Please sign in to comment.