OrdinaryDiffEq.jl
OrdinaryDiffEq.jl copied to clipboard
Unitful v0.17.0 breaks tests
It seems like zero(u) for u an array of heterogeneous units fails.
https://github.com/PainterQubits/Unitful.jl/pull/266 https://github.com/PainterQubits/Unitful.jl/issues/264
I think we should just do some type piracy so it works like a normal array type.
Is there a fix in sight? Or what's the work-around?
I think the work around is to type pirate zero(u) to be correct with its types?
But the fix lies with Unitful, right?
Yes, I think we need to just open issues and mention that, if Unitful is the only package that makes zero(u) return a different type than u, it's very difficult to handle generically.
Ok, I'll see whether I can file one. But it will be a few days until I get the time to look at it. The easiest work-around is probably to pin Unitful to 0.16.
Just to spell it out, for heterogeneous arrays, u might have type "Vector{Quantity{Float64, D, U} where {D, U}}". The standard overload for this would be "zero(x::AbstractArray{T, N} where N) where T" in Base. This method just fills with the zero of that type:
zero(x::AbstractArray{T}) where {T} = fill!(similar(x), zero(T))
This does nothing useful -- the actual type information is lost at this point. Instead we want it to effectively do zero.(u).
Adding an overload for this case isn't hard.
https://github.com/PainterQubits/Unitful.jl/pull/472 is a pull request that fixes this for heterogeneous arrays of Unitful quantities specifically (though using map(zero, x) rather than zero.(x)). But discussion there points out, that Julia Base itself has this issue for heterogeneous arrays.
This is recorded in this issue: https://github.com/JuliaLang/julia/issues/33099 and there's now attempts at resolving it in this pull request: https://github.com/JuliaLang/julia/pull/41705 .