Skip to content

Commit

Permalink
fix allocation and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
heltonmc committed Oct 12, 2022
1 parent 02a9d7a commit 4a59336
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,7 @@ In general, this provides a fast way to generate a sequence of Bessel functions
julia> @btime besselj(0:100, 50.0)
443.328 ns (2 allocations: 1.75 KiB)
```
This function will allocate so it is recommended that you calculate the Bessel functions at the top level of your function outside any hot loop. For example,

```julia
function bessel_sequence(x, orders)
J_nu = besselj(orders, x)
out = zero(x)
for i in eachindex(J_nu)
out += sin(x*i)*J_nu[i]
end
return out
end

julia> bessel_sequence(10.2, 1:400)
0.11404996570230919
```
This function will allocate so it is recommended that you calculate the Bessel functions at the top level of your function outside any hot loop.

### Support for negative arguments

Expand Down
3 changes: 2 additions & 1 deletion src/besseli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ function _besseli(nu::AbstractRange, x::T) where T
end
if k > 1
out[k] = _besseli(nu[k], x)
out[1:k+1] = besselk_down_recurrence!(out[1:k+1], x, nu[1:k+1])
tmp = @view out[1:k+1]
out[1:k+1] = besselk_down_recurrence!(tmp, x, nu[1:k+1])
return out
else
return out
Expand Down
3 changes: 2 additions & 1 deletion src/besselj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ function _besselj(nu::AbstractRange, x::T) where T
end
if k > 1
out[k] = _besselj(nu[k], x)
out[1:k+1] = besselj_down_recurrence!(out[1:k+1], x, nu[1:k+1])
tmp = @view out[1:k+1]
besselj_down_recurrence!(tmp, x, nu[1:k+1])
return out
else
return out
Expand Down
3 changes: 2 additions & 1 deletion src/besselk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ function _besselk(nu::AbstractRange, x::T) where T
end
if k < len
out[k] = _besselk(nu[k], x)
out[k-1:end] = besselk_up_recurrence!(out[k-1:end], x, nu[k-1:end])
tmp = @view out[k-1:end]
out[k-1:end] = besselk_up_recurrence!(tmp, x, nu[k-1:end])
return out
else
return out
Expand Down

0 comments on commit 4a59336

Please sign in to comment.