-
Notifications
You must be signed in to change notification settings - Fork 149
Make duals' operations through steprange use linrange instead #618
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this on!
I had a go at writing some tests...
Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
Some other ways to make StepRangeLen with Dual, one of which makes a TwicePrecision{Dual}: julia> (1:4) * Dual(1,2) |> typeof # UnitRange, not tested
StepRangeLen{Dual{Nothing, Int64, 1}, Dual{Nothing, Int64, 1}, Dual{Nothing, Int64, 1}, Int64}
julia> (1:2:4) * Dual(1.0,2) |> typeof
StepRangeLen{Dual{Nothing, Float64, 1}, Dual{Nothing, Float64, 1}, Dual{Nothing, Float64, 1}, Int64}
julia> (0:0.1:1) ./ Dual(1.0,2) |> typeof
StepRangeLen{Dual{Nothing, Float64, 1}, Base.TwicePrecision{Dual{Nothing, Float64, 1}}, Base.TwicePrecision{Dual{Nothing, Float64, 1}}, Int64} These don't seem to cause problems, so perhaps it's simplest to leave them alone. |
Failure on 1.6 seems to be this, arguably a bug in Base, but can it be worked around here? julia> using ForwardDiff: Dual
julia> range(1, step = Dual(1,1), length = 5)
ERROR: InexactError: Int(Int64, Dual{Nothing}(5,4))
Stacktrace:
[1] Int64
@ ~/.julia/packages/ForwardDiff/pDtsf/src/dual.jl:362 [inlined]
[2] convert
@ ./number.jl:7 [inlined]
[3] _rangestyle(#unused#::Base.Ordered, #unused#::Base.ArithmeticWraps, a::Int64, step::Dual{Nothing, Int64, 1}, len::Int64)
@ Base ./range.jl:118
...
julia> VERSION
v"1.6.0"
julia> range(1.0, step = Dual(1,1), length = 5)
ERROR: StackOverflowError:
Stacktrace:
[1] _range(a::Float64, st::Dual{Nothing, Float64, 1}, #unused#::Nothing, len::Int64) (repeats 79984 times)
@ Base ./range.jl:111 |
On 1.8, it seems the behavior is
Which operation is causing the errors? The one on the dual component? For the Int one, we could force it to convert to Float, I guess, since it seems that range on Base also does this (at least in this anecdotal example). |
I just ran into this issue. Is the PR still active? |
If there's anything that needs to be changed for the PR to merged, I don't know exactly what is. Or if it should be redone. |
@tom-plaa, I believe that the PR was not merge because of the failing tests on Julia 1.6. The CI tests are now so old that I cannot see the logs anymore. I therefore don't know which test that failed. I would suggest.
I think they will merge this PR as when all the CI checks pass :) |
@tom-plaa
|
Feel free to reuse my code. The tests were mostly written by @mcabbott, not myself. |
Trying to solve #380.
Does not fix the "show" ambiguity.
A bit naively done, please review and advise if there's anything that needs to be done differently.