OrdinaryDiffEq.jl icon indicating copy to clipboard operation
OrdinaryDiffEq.jl copied to clipboard

Unitful v0.17.0 breaks tests

Open ChrisRackauckas opened this issue 6 years ago • 6 comments

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.

ChrisRackauckas avatar Sep 08 '19 23:09 ChrisRackauckas

Is there a fix in sight? Or what's the work-around?

mauro3 avatar Nov 15 '19 08:11 mauro3

I think the work around is to type pirate zero(u) to be correct with its types?

ChrisRackauckas avatar Nov 16 '19 15:11 ChrisRackauckas

But the fix lies with Unitful, right?

mauro3 avatar Nov 16 '19 16:11 mauro3

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.

ChrisRackauckas avatar Nov 16 '19 18:11 ChrisRackauckas

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.

mauro3 avatar Nov 16 '19 19:11 mauro3

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 .

wnoise avatar Oct 06 '21 20:10 wnoise