JuliaDiff/ForwardDiff.jl

`construct_seeds` for types where `typeof(one(T)) !=T` is broken

longemen3000 opened this issue · 1 comments

as far as i understand, the type of one(T) is not necessarily T (JuliaPhysics/Measurements.jl#134 for example). but construct_seeds uses this:

@generated function single_seed(::Type{Partials{N,V}}, ::Val{i}) where {N,V,i}
ex = Expr(:tuple, [ifelse(i === j, :(one(V)), :(zero(V))) for j in 1:N]...)
return :(Partials($(ex)))
end

Maybe using oneunit there is more correct?

If you want to get something of the same type, you should use oneunit, that's what it's for.

(e.g. for a dimensionful type, one must be dimensionless, i.e. of a different type, as otherwise it will not be a multiplicative identity.)