You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, one returns a Dual number. It seems like it could simply return the underlying value type instead. i.e. change these lines to
Base.one(d::Dual) =one(typeof(d))
Base.oneunit(d::Dual) =oneunit(typeof(d))
Base.one(::Type{Dual{T,V,N}}) where {T,V,N} =one(V)
Base.oneunit(::Type{Dual{T,V,N}}) where {T,V,N} =Dual{T}(oneunit(V), zero(Partials{N,V}))
which is still correct since one(V) is still a multiplicative identity for Dual, and type promotion takes care of the rest. In general, one(x) in Julia need not return the same type as x — if you want the same type, you use oneunit, which is why I added a method for Dual (since they otherwise fall back to calling one).
The advantage of this is that code that is designed to "strip the units" from numbers will then work with Dual numbers as well. For example, this code in QuadGK.jl will work, and you will suddenly be able to differentiate numerical integrals:
Currently,
one
returns aDual
number. It seems like it could simply return the underlying value type instead. i.e. change these lines towhich is still correct since
one(V)
is still a multiplicative identity forDual
, and type promotion takes care of the rest. In general,one(x)
in Julia need not return the same type asx
— if you want the same type, you useoneunit
, which is why I added a method forDual
(since they otherwise fall back to callingone
).The advantage of this is that code that is designed to "strip the units" from numbers will then work with
Dual
numbers as well. For example, this code in QuadGK.jl will work, and you will suddenly be able to differentiate numerical integrals:The text was updated successfully, but these errors were encountered: