Skip to content
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

Add rem2pi #19

Closed
wants to merge 1 commit into from
Closed

Add rem2pi #19

wants to merge 1 commit into from

Conversation

tkoolen
Copy link

@tkoolen tkoolen commented Sep 14, 2017

Fixes #18.

Unlike rem, I don't think it makes sense to add rem2pi to RealInterface.BINARY_MATH, because e.g. https://github.com/JuliaDiff/ForwardDiff.jl/blob/18b46471e4bb3d36633058267606767246b3e931/src/dual.jl#L420 won't do the right thing for this case. Same thing for the standard tests in RulesTests.jl.

Please advise on how to handle this: should there be a new category in RealInterface containing only this function, or should this just be special cased directly in ForwardDiff and other RealInterface dependents?

@jrevels
Copy link
Contributor

jrevels commented Sep 20, 2017

Please advise on how to handle this: should there be a new category in RealInterface containing only this function, or should this just be special cased directly in ForwardDiff and other RealInterface dependents?

I think we can fix this by just adding Any to ForwardDiff's type ambiguity list (the REAL_TYPES const). EDIT: And we'll also have to add a special test case for rem2pi in ForwardDiff, but that's not too bad.

Instead of this PR, could you open a similar PR in https://github.com/JuliaDiff/DiffRules.jl instead? Sorry for the inconvenience - my plan is to archive DiffBase and RealInterface after JuliaDiff/ForwardDiff.jl#262 is merged.

tkoolen added a commit to tkoolen/DiffRules.jl that referenced this pull request Sep 25, 2017
@tkoolen
Copy link
Author

tkoolen commented Sep 25, 2017

See JuliaDiff/DiffRules.jl#2.

@tkoolen tkoolen closed this Sep 25, 2017
jrevels pushed a commit to JuliaDiff/DiffRules.jl that referenced this pull request Dec 8, 2017
@rdeits
Copy link

rdeits commented Jan 5, 2018

Adding Any to the REAL_TYPES results in some new ambiguities in the tests:

Testing Dual...
  ...testing Dual{TestTag(),Int64,0} and Dual{TestTag(),Dual{TestTag(),Int64,0},0}
Error During Test
  Test threw an exception of type MethodError
  Expression: dual_isapprox(PRIMAL / NESTED_FDNUM, Dual{TestTag()}(PRIMAL / value(NESTED_FDNUM), (-PRIMAL / value(NESTED_FDNUM) ^ 2) * partials(NESTED_FDNUM)))
  MethodError: *(::ForwardDiff.Dual{DualTest.TestTag(),Float64,0}, ::ForwardDiff.Partials{0,ForwardDiff.Dual{DualTest.TestTag(),Int64,0}}) is ambiguous. Candidates:                                                                            
    *(x::ForwardDiff.Dual{Tx,V,N} where N where V<:Real, y) where Tx in ForwardDiff at /home/rdeits/Downloads/packages/v0.6/ForwardDiff/src/dual.jl:104                                                                                         
    *(x::Real, partials::ForwardDiff.Partials{0,V}) where V in ForwardDiff at /home/rdeits/Downloads/packages/v0.6/ForwardDiff/src/partials.jl:134                                                                                              
  Possible fix, define                                                                                                  
    *(::ForwardDiff.Dual{Tx,V,N} where N where V<:Real, ::ForwardDiff.Partials{0,V})                                    
  Stacktrace:
   [1] /(::Int64, ::ForwardDiff.Dual{DualTest.TestTag(),ForwardDiff.Dual{DualTest.TestTag(),Int64,0},0}) at /home/rdeits/Downloads/packages/v0.6/ForwardDiff/src/dual.jl:373
   [2] macro expansion at /home/rdeits/Downloads/packages/v0.6/ForwardDiff/test/DualTest.jl:373 [inlined]

@jrevels
Copy link
Contributor

jrevels commented Jan 8, 2018

Thanks for looking into this. Simplest solution then might be to add the strictest supertype necessary to resolve the ambiguity (for this case, RoundingMode).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants