JuliaDiff / DiffRules.jl

A simple shared suite of common derivative definitions
Other
75 stars 38 forks source link

Type instability in ldexp with Float32 arguments #88

Closed ptiede closed 1 year ago

ptiede commented 1 year ago

Hi,

This is a cross-post with https://github.com/JuliaDiff/ForwardDiff.jl/issues/604. The rule for ldexp(x,y) always returns a Float64 regardless of the type of the first argument x. This is because the rule is given by

@define_diffrule Base.ldexp(x, y)  = :( exp2($y) ), :NaN

and since y is an Int exp2 by default return a Float64. @mcabbott pointed out that if we change the rule to

@define_diffrule Base.ldexp(x, y)  = :(  oftype(float($x), exp2($y)  ), :NaN

then we should maintain the Float32 type throughout the computation.

ptiede commented 1 year ago

Closed because of #89