ForwardDiff Allocations

I think this happens because your ternary operators are not type-stable: they return either a Float64 or a typeof(B / K) (which will be a Dual number at differentiation time). I am not at my computer but the first thing I would try is replacing 0.0 in the first branch of the ternary operator with zero(Base.promote_type(typeof(B), typeof(K)))

3 Likes