Skip to content

Commit c1b63f0

Browse files
authored
fix constructor ambiguity introduced by #337 (#342)
1 parent 6797445 commit c1b63f0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/dual.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ end
4545
@inline Dual{T}(value::Real, partials::Tuple{}) where {T} = Dual{T}(value, Partials{0,typeof(value)}(partials))
4646
@inline Dual{T}(value::Real, partials::Real...) where {T} = Dual{T}(value, partials)
4747
@inline Dual{T}(value::V, ::Chunk{N}, p::Val{i}) where {T,V<:Real,N,i} = Dual{T}(value, single_seed(Partials{N,V}, p))
48-
4948
@inline Dual(args...) = Dual{Nothing}(args...)
5049

50+
function Dual{T,V,N}(x::Real) where {T,V,N}
51+
Base.depwarn("Dual{$T,$V,$N}(x::Real) is deprecated, use `convert(Dual{$T,$V,$N}, x)` instead.", :Dual)
52+
return convert(Dual{T,V,N}, x)
53+
end
54+
55+
function Dual{T,V}(x::Real) where {T,V}
56+
Base.depwarn("Dual{$T,$V}(x::Real) is deprecated, use `convert(Dual{$T,$V}, x)` instead.", :Dual)
57+
return convert(Dual{T,V}, x)
58+
end
59+
5160
##############################
5261
# Utility/Accessor Functions #
5362
##############################
@@ -315,7 +324,6 @@ end
315324
Base.convert(::Type{Dual{T,V,N}}, d::Dual{T}) where {T,V<:Real,N} = Dual{T}(convert(V, value(d)), convert(Partials{N,V}, partials(d)))
316325
Base.convert(::Type{Dual{T,V,N}}, x::Real) where {T,V<:Real,N} = Dual{T}(convert(V, x), zero(Partials{N,V}))
317326
Base.convert(::Type{D}, d::D) where {D<:Dual} = d
318-
(::Type{D})(x::Real) where {D<:Dual} = convert(D, x)
319327

320328
Base.float(d::Dual{T,V,N}) where {T,V,N} = convert(Dual{T,promote_type(V, Float16),N}, d)
321329
Base.AbstractFloat(d::Dual{T,V,N}) where {T,V,N} = convert(Dual{T,promote_type(V, Float16),N}, d)

test/DualTest.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
5454
################
5555

5656
@test Dual{TestTag()}(PRIMAL, PARTIALS...) === FDNUM
57+
@test Dual(PRIMAL, PARTIALS...) === Dual{Nothing}(PRIMAL, PARTIALS...)
58+
@test Dual(PRIMAL) === Dual{Nothing}(PRIMAL)
59+
5760
@test typeof(Dual{TestTag()}(widen(V)(PRIMAL), PARTIALS)) === Dual{TestTag(),widen(V),N}
5861
@test typeof(Dual{TestTag()}(widen(V)(PRIMAL), PARTIALS.values)) === Dual{TestTag(),widen(V),N}
5962
@test typeof(Dual{TestTag()}(widen(V)(PRIMAL), PARTIALS...)) === Dual{TestTag(),widen(V),N}

0 commit comments

Comments
 (0)