Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

float(::Dual) disagrees with Base #492

Closed
mcabbott opened this issue Jan 7, 2021 · 1 comment · Fixed by #535
Closed

float(::Dual) disagrees with Base #492

mcabbott opened this issue Jan 7, 2021 · 1 comment · Fixed by #535

Comments

@mcabbott
Copy link
Member

mcabbott commented Jan 7, 2021

I was surprised by this:

using ForwardDiff: Dual, value
x1 = Dual.(1:4, 2:5, 3:6)
value.(float.(x1)) # Vector{Float16}
float.(value.(x1)) # Vector{Float64}

While one could argue that Julia should have different promotion / widening rules, it seems hard to argue that Dual types should disagree. This example caught me when trying to wrap a function which only accepts Float32 & Float64, as seems fairly common for C libraries.

Edit -- xref #419, about AbstractFloat.

And #362, about Int -> Float16. Example from here is ForwardDiff.derivative(first∘sincos, 1) isa Float16

@stevengj
Copy link
Contributor

It seems like this line

ForwardDiff.jl/src/dual.jl

Lines 383 to 384 in 6b393f4

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

should just use float(V) rather than promote_type(V, Float16)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants