Skip to content

Commit

Permalink
Merge pull request #61 from Samuel3008/master
Browse files Browse the repository at this point in the history
Improve sphericalbesselj inference
  • Loading branch information
heltonmc authored Oct 24, 2022
2 parents 6c8be6f + fc0fb59 commit 5264aea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/sphericalbessel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function sphericalbesselj_recurrence(nu::Integer, x::T) where T
nu_start += 1
end
return sJ0
elseif x < nu
else
# compute sphericalbessely with forward recurrence and use continued fraction
sYnm1, sYn = sphericalbessely_forward_recurrence(nu, x)
H = besselj_ratio_jnu_jnum1(nu + T(3)/2, x)
Expand Down
40 changes: 20 additions & 20 deletions test/sphericalbessel_test.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# test very small inputs
x = 1e-15
@test Bessels.sphericalbesselj(0, x) SpecialFunctions.sphericalbesselj(0, x)
@test Bessels.sphericalbesselj(1, x) SpecialFunctions.sphericalbesselj(1, x)
@test Bessels.sphericalbesselj(5.5, x) SpecialFunctions.sphericalbesselj(5.5, x)
@test Bessels.sphericalbesselj(10, x) SpecialFunctions.sphericalbesselj(10, x)
@test Bessels.sphericalbessely(0, x) SpecialFunctions.sphericalbessely(0, x)
@test Bessels.sphericalbessely(1, x) SpecialFunctions.sphericalbessely(1, x)
@test Bessels.sphericalbessely(5.5, x) SpecialFunctions.sphericalbessely(5.5, x)
@test Bessels.sphericalbessely(10, x) SpecialFunctions.sphericalbessely(10, x)
@test Bessels.sphericalbesselk(5.5, x) SpecialFunctions.besselk(5.5 + 1/2, x) * sqrt( 2 / (x*pi))
@test Bessels.sphericalbesselk(10, x) SpecialFunctions.besselk(10 + 1/2, x) * sqrt( 2 / (x*pi))
@test @inferred(Bessels.sphericalbesselj(0, x)) SpecialFunctions.sphericalbesselj(0, x)
@test @inferred(Bessels.sphericalbesselj(1, x)) SpecialFunctions.sphericalbesselj(1, x)
@test @inferred(Bessels.sphericalbesselj(5.5, x)) SpecialFunctions.sphericalbesselj(5.5, x)
@test @inferred(Bessels.sphericalbesselj(10, x)) SpecialFunctions.sphericalbesselj(10, x)
@test @inferred(Bessels.sphericalbessely(0, x)) SpecialFunctions.sphericalbessely(0, x)
@test @inferred(Bessels.sphericalbessely(1, x)) SpecialFunctions.sphericalbessely(1, x)
@test @inferred(Bessels.sphericalbessely(5.5, x)) SpecialFunctions.sphericalbessely(5.5, x)
@test @inferred(Bessels.sphericalbessely(10, x)) SpecialFunctions.sphericalbessely(10, x)
@test @inferred(Bessels.sphericalbesselk(5.5, x)) SpecialFunctions.besselk(5.5 + 1/2, x) * sqrt( 2 / (x*pi))
@test @inferred(Bessels.sphericalbesselk(10, x)) SpecialFunctions.besselk(10 + 1/2, x) * sqrt( 2 / (x*pi))

x = 1e-20
@test Bessels.sphericalbesseli(0, x) SpecialFunctions.besseli(0 + 1/2, x) * sqrt( pi / (x*2))
@test Bessels.sphericalbesseli(1, x) SpecialFunctions.besseli(1 + 1/2, x) * sqrt( pi / (x*2))
@test Bessels.sphericalbesseli(2, x) SpecialFunctions.besseli(2 + 1/2, x) * sqrt( pi / (x*2))
@test Bessels.sphericalbesseli(3, x) SpecialFunctions.besseli(3 + 1/2, x) * sqrt( pi / (x*2))
@test Bessels.sphericalbesseli(4, x) SpecialFunctions.besseli(4 + 1/2, x) * sqrt( pi / (x*2))
@test Bessels.sphericalbesseli(6.5, x) SpecialFunctions.besseli(6.5 + 1/2, x) * sqrt( pi / (x*2))
@test @inferred(Bessels.sphericalbesseli(0, x)) SpecialFunctions.besseli(0 + 1/2, x) * sqrt( pi / (x*2))
@test @inferred(Bessels.sphericalbesseli(1, x)) SpecialFunctions.besseli(1 + 1/2, x) * sqrt( pi / (x*2))
@test @inferred(Bessels.sphericalbesseli(2, x)) SpecialFunctions.besseli(2 + 1/2, x) * sqrt( pi / (x*2))
@test @inferred(Bessels.sphericalbesseli(3, x)) SpecialFunctions.besseli(3 + 1/2, x) * sqrt( pi / (x*2))
@test @inferred(Bessels.sphericalbesseli(4, x)) SpecialFunctions.besseli(4 + 1/2, x) * sqrt( pi / (x*2))
@test @inferred(Bessels.sphericalbesseli(6.5, x)) SpecialFunctions.besseli(6.5 + 1/2, x) * sqrt( pi / (x*2))

# test zero
@test isone(Bessels.sphericalbesselj(0, 0.0))
Expand Down Expand Up @@ -78,10 +78,10 @@ x = NaN
@test isnan(Bessels.sphericalbesseli(6.4, x))

# test Float16, Float32 types
@test Bessels.sphericalbesselj(Float16(1.4), Float16(1.2)) isa Float16
@test Bessels.sphericalbessely(Float16(1.4), Float16(1.2)) isa Float16
@test Bessels.sphericalbesselj(1.4f0, 1.2f0) isa Float32
@test Bessels.sphericalbessely(1.4f0, 1.2f0) isa Float32
@test @inferred(Bessels.sphericalbesselj(Float16(1.4), Float16(1.2))) isa Float16
@test @inferred(Bessels.sphericalbessely(Float16(1.4), Float16(1.2))) isa Float16
@test @inferred(Bessels.sphericalbesselj(1.4f0, 1.2f0)) isa Float32
@test @inferred(Bessels.sphericalbessely(1.4f0, 1.2f0)) isa Float32

@test Bessels.sphericalbesselk(Float16(1.4), Float16(1.2)) isa Float16
@test Bessels.sphericalbesselk(1.0f0, 1.2f0) isa Float32
Expand Down

0 comments on commit 5264aea

Please sign in to comment.