Skip to content

Commit

Permalink
Fix for derivative through sincospi gives StackOverflowError (#499)
Browse files Browse the repository at this point in the history
* fixed stackoverflow for sincospi (#497)

* add version checks since sincospi is only defined for Julia 1.6

* Update version check for sincospi to 1.6.0-DEV.292

Co-authored-by: Andreas Noack <[email protected]>

Co-authored-by: Andreas Noack <[email protected]>
  • Loading branch information
mchitre and andreasnoack authored Jan 18, 2021
1 parent 56efb9f commit 6afe377
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,16 @@ end
return (Dual{T}(sd, cd * partials(d)), Dual{T}(cd, -sd * partials(d)))
end

# sincospi #
#----------#

if VERSION >= v"1.6.0-DEV.292"
@inline function Base.sincospi(d::Dual{T}) where T
sd, cd = sincospi(value(d))
return (Dual{T}(sd, cd * π * partials(d)), Dual{T}(cd, -sd * π * partials(d)))
end
end

###################
# Pretty Printing #
###################
Expand Down
4 changes: 4 additions & 0 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ for N in (0,3), M in (0,4), V in (Int, Float32)

@test all(map(dual_isapprox, ForwardDiff.sincos(FDNUM), (sin(FDNUM), cos(FDNUM))))

if VERSION >= v"1.6.0-DEV.292"
@test all(map(dual_isapprox, sincospi(FDNUM), (sinpi(FDNUM), cospi(FDNUM))))
end

if V === Float32
@test typeof(sqrt(FDNUM)) === typeof(FDNUM)
@test typeof(sqrt(NESTED_FDNUM)) === typeof(NESTED_FDNUM)
Expand Down

0 comments on commit 6afe377

Please sign in to comment.