Skip to content

Commit 27d257f

Browse files
author
Chris Geoga
committed
Fix manual sinpi rule, but CI and compat to 1.9.
1 parent 1578b6f commit 27d257f

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
matrix:
2222
version:
2323
- '1'
24-
- '1.8'
24+
- '1.9'
2525
- 'nightly'
2626
os:
2727
- ubuntu-latest

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SIMDMath = "5443be0b-e40a-4f70-a07e-dcd652efc383"
77

88
[compat]
99
SIMDMath = "0.2.5"
10-
julia = "1.8"
10+
julia = "1.9"
1111

1212
[extras]
1313
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

ext/BesselsEnzymeCoreExt.jl

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
module BesselsEnzymeCoreExt
22

3-
# TODO (cg 2023/05/08 10:02): Compat of any kind.
4-
53
using Bessels, EnzymeCore
64
using EnzymeCore.EnzymeRules
75
using Bessels.Math
86

97
# A manual method that separately transforms the `val` and `dval`, because
108
# sometimes the `val` can converge while the `dval` hasn't, so just using an
119
# early return or something can give incorrect derivatives in edge cases.
12-
#
13-
# https://github.com/JuliaMath/Bessels.jl/issues/96
14-
#
15-
# and links with for discussion.
16-
#
17-
# TODO (cg 2023/05/08 10:00): I'm not entirely sure how best to "generalize"
18-
# this to cases like a return type of DuplicatedNoNeed, or something being a
19-
# `Enzyme.Const`. These shouldn't in principle affect the "point" of this
20-
# function (which is just to check for convergence before applying a
21-
# function), but on its face this approach would mean I need a lot of
22-
# hand-written extra methods. I have an open issue on the Enzyme.jl repo at
23-
#
24-
# https://github.com/EnzymeAD/Enzyme.jl/issues/786
25-
#
26-
# that gets at this problem a bit. But it's a weird request and I'm sure Billy
27-
# has a lot of asks on his time.
2810
function EnzymeRules.forward(func::Const{typeof(levin_transform)},
2911
::Type{<:Duplicated},
3012
s::Duplicated,
@@ -39,7 +21,8 @@ module BesselsEnzymeCoreExt
3921
function EnzymeRules.forward(func::Const{typeof(sinpi)},
4022
::Type{<:Duplicated},
4123
x::Duplicated)
42-
Duplicated(sinpi(x.val), pi*cospi(x.val))
24+
(sp, cp) = sincospi(x.val)
25+
Duplicated(sp, pi*cp*x.dval)
4326
end
4427

4528
function EnzymeRules.forward(func::Const{typeof(sinpi)},

src/BesselFunctions/besselk.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ function besselk_power_series(v, x::ComplexOrReal{T}) where T
513513
# use the reflection identify to calculate gamma(-v)
514514
# use relation gamma(v)*v = gamma(v+1) to avoid two gamma calls
515515
gam_v = gamma(v)
516-
gam_nv = π / (sinpi(-abs(v)) * gam_v * v)
516+
#gam_nv = π / (sin(-pi*abs(v)) * gam_v * v) # not using sinpi here to avoid Enzyme bug
517+
gam_nv = π / (sinpi(-abs(v)) * gam_v * v) # not using sinpi here to avoid Enzyme bug
517518
gam_1mv = -gam_nv * v
518519
gam_1mnv = gam_v * v
519520

0 commit comments

Comments
 (0)