JuliaDiff / ReverseDiff.jl

Reverse Mode Automatic Differentiation for Julia
Other
348 stars 57 forks source link

Fix `Base.isapprox` for `TrackedReal` #166

Closed delehef closed 3 years ago

delehef commented 3 years ago

The Base.isapprox function relies on Base.rtoldefault to return an acceptable margin of error for inexact comparisons. If the default implementation for types descending from AbstractFloat returns sqrt(eps(T)), the one for types descending from Real simply returns 0.

As TrackedReal descends from Real and not AbstractFloat, a custom Base.rtoldefault implementation returning sqrt(eps(T)) ensures that iscompare behaves correctly for TrackedReal approximative comparisons.

Fixes #165

codecov-io commented 3 years ago

Codecov Report

Merging #166 (87398e9) into master (c847b23) will decrease coverage by 0.96%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #166      +/-   ##
==========================================
- Coverage   82.46%   81.50%   -0.97%     
==========================================
  Files          18       18              
  Lines        1557     1465      -92     
==========================================
- Hits         1284     1194      -90     
+ Misses        273      271       -2     
Impacted Files Coverage Δ
src/tracked.jl 88.51% <0.00%> (-0.89%) :arrow_down:
src/derivatives/broadcast.jl 74.50% <0.00%> (-13.52%) :arrow_down:
src/macros.jl 90.90% <0.00%> (-1.63%) :arrow_down:
src/derivatives/scalars.jl 95.74% <0.00%> (-0.75%) :arrow_down:
src/api/hessians.jl 84.00% <0.00%> (-0.62%) :arrow_down:
src/derivatives/linalg/special.jl 97.43% <0.00%> (-0.07%) :arrow_down:
src/api/jacobians.jl 100.00% <0.00%> (ø)
src/tape.jl 55.55% <0.00%> (+0.29%) :arrow_up:
src/derivatives/elementwise.jl 77.74% <0.00%> (+0.71%) :arrow_up:
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c847b23...87398e9. Read the comment docs.

mohamed82008 commented 3 years ago

Thanks for this and sorry for the delay. Can you please add a test?