Skip to content

Commit 6afe377

Browse files
Fix for derivative through sincospi gives StackOverflowError (#499)
* 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 <andreas@noack.dk> Co-authored-by: Andreas Noack <andreas@noack.dk>
1 parent 56efb9f commit 6afe377

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/dual.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,16 @@ end
609609
return (Dual{T}(sd, cd * partials(d)), Dual{T}(cd, -sd * partials(d)))
610610
end
611611

612+
# sincospi #
613+
#----------#
614+
615+
if VERSION >= v"1.6.0-DEV.292"
616+
@inline function Base.sincospi(d::Dual{T}) where T
617+
sd, cd = sincospi(value(d))
618+
return (Dual{T}(sd, cd * π * partials(d)), Dual{T}(cd, -sd * π * partials(d)))
619+
end
620+
end
621+
612622
###################
613623
# Pretty Printing #
614624
###################

test/DualTest.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,10 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
449449

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

452+
if VERSION >= v"1.6.0-DEV.292"
453+
@test all(map(dual_isapprox, sincospi(FDNUM), (sinpi(FDNUM), cospi(FDNUM))))
454+
end
455+
452456
if V === Float32
453457
@test typeof(sqrt(FDNUM)) === typeof(FDNUM)
454458
@test typeof(sqrt(NESTED_FDNUM)) === typeof(NESTED_FDNUM)

0 commit comments

Comments
 (0)