-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversion issue when combining StaticArrays
, ForwardDif
, and IntervalArithmetic
#685
Comments
Thx for reporting this issue. If one defines Your example also pointed out that using StaticArrays, ForwardDiff, IntervalArithmetic
julia> Base.convert(::Type{ForwardDiff.Dual{T,V,N}}, x::ExactReal) where {T,V,N} = ForwardDiff.Dual{T}(convert(V, x), zero(ForwardDiff.Partials{N,V})) # missing conversion!
julia> x = SVector(1.0, 2.0)
2-element SVector{2, Float64} with indices SOneTo(2):
1.0
2.0
julia> xI = SVector(interval(0.0, 1.0), interval(0.0, 1.0))
2-element SVector{2, Interval{Float64}} with indices SOneTo(2):
[0.0, 1.0]_com
[0.0, 1.0]_com
julia> @exact g = (x) -> sum(insert(x, 1, 1.0)); # wraps `1.0` into `ExactReal(1.0)`
julia> ∇g = x -> ForwardDiff.gradient(g, x);
julia> ∇g(x) # OK (relies on `Float64(::ExactReal)`)
2-element SVector{2, Float64} with indices SOneTo(2):
1.0
1.0
julia> ∇g(xI) # also OK (relies on `Interval{Float64}(::ExactReal)`)
2-element SVector{2, Interval{Float64}} with indices SOneTo(2):
[1.0, 1.0]_com
[1.0, 1.0]_com |
Thanks for looking into this. In my application I can't really use I don't know the internals of |
I think we can bring back such implicit conversions, it will just be marked with a "not guaranteed" flag. E.g. julia> insert(xI, 1, 1.0)
3-element SVector{3, Interval{Float64}} with indices SOneTo(3):
[1.0, 1.0]_com_NG
[0.0, 1.0]_com
[0.0, 1.0]_com Note that for functions expected to work for both floats and intervals, the current way is to use julia> g = (x) -> sum(insert(x, 1, ExactReal(1.0)))
julia> g(x)
4.0
julia> g(xI)
[1.0, 3.0]_com
julia> ∇g = x -> ForwardDiff.gradient(g, x);
julia> ∇g(x)
2-element SVector{2, Float64} with indices SOneTo(2):
1.0
1.0
julia> ∇g(xI)
2-element SVector{2, Interval{Float64}} with indices SOneTo(2):
[1.0, 1.0]_com
[1.0, 1.0]_com |
Thanks @OlivierHnt ! |
In trying to combine
ForwardDiff
withStaticArrays
andIntervalArithmetic
I ran into the following issue:I did not look too deep, but it seems that somewhere in the conversion pipeline
StaticArrays
calls a conversion method, which in turn calls the constructorInterval{Float64}(x)
. I saw that this constructor was intentionally commented outIntervalArithmetic.jl/src/intervals/construction.jl
Line 371 in 429ad16
Uncommenting the line above does "solve" the issue, but the
IntervalArithmetic
tests fail because it is explicitly tested thatInterval{T}(x)
should throwIntervalArithmetic.jl/test/interval_tests/construction.jl
Line 47 in 429ad16
So I see that this is intentional. I was wondering if there is a workaround?
Thanks.
The text was updated successfully, but these errors were encountered: