-
Notifications
You must be signed in to change notification settings - Fork 146
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
Int(::Dual) and Integer(::Dual) #508
Conversation
Codecov Report
@@ Coverage Diff @@
## master #508 +/- ##
==========================================
+ Coverage 88.94% 88.96% +0.02%
==========================================
Files 10 10
Lines 841 843 +2
==========================================
+ Hits 748 750 +2
Misses 93 93
Continue to review full report at Codecov.
|
I think this should only work if the dual part is zero (cf the behavior of complex numbers). |
I think I agree: julia> Integer(nextfloat(1.0))
ERROR: InexactError: Int64(1.0000000000000002)
Stacktrace:
[1] Int64
@ ./float.jl:723 [inlined]
[2] Integer(x::Float64)
@ Core ./boot.jl:786
[3] top-level scope
@ REPL[1]:1 But in that case I should also overload julia> UnitRange(Dual(1,1), Dual(2,0)) |> collect
2-element Vector{Dual{Nothing, Int64, 1}}:
Dual{Nothing}(1,1)
Dual{Nothing}(2,1) works. |
Ha! We're in luck, because |
Bump. This looks like a useful addition to me 👍 |
Can this be merged? Just ran into it, again |
The test failure looks unrelated... |
I agree that the test failures don't look directly related to this but when I look at the CI run for earlier commits on master (https://github.com/JuliaDiff/ForwardDiff.jl/commits/master) they all seem green so it is a bit surprising why this would suddenly start happening. And it happens for all Julia versions as well. |
CI error also happens in #527. It seems to be something with the StaticArray tests so maybe it is a new version of StaticArrays that caused it? The last PR on master ran with StaticArrays v1.1.0 and this one runs with StaticArrays v1.2.4, |
I bisected and JuliaArrays/StaticArrays.jl#907 is when the ForwardDiff test failure was introduced. |
Note the values depend on the sample in julia> @test DiffResults.value(result1) == DiffResults.value(result)
Test Failed at REPL[39]:1
Expression: DiffResults.value(result1) == DiffResults.value(result)
Evaluated: 0.0 == 1.297445353195765e-6 |
I'm debugging this now. FYI I believe ForwardDiff.jl/src/apiutils.jl Line 40 in 909976d
EDIT: The StaticArrays.jl#907 Issue already has a minimum working example. |
Codecov Report
@@ Coverage Diff @@
## master #508 +/- ##
==========================================
+ Coverage 84.62% 84.83% +0.21%
==========================================
Files 9 9
Lines 826 831 +5
==========================================
+ Hits 699 705 +6
+ Misses 127 126 -1
Continue to review full report at Codecov.
|
This adds convert routines for integers. I need this to fix the following bug: