Skip to content

Commit 4a59336

Browse files
committed
fix allocation and readme
1 parent 02a9d7a commit 4a59336

File tree

4 files changed

+7
-18
lines changed

4 files changed

+7
-18
lines changed

README.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,7 @@ In general, this provides a fast way to generate a sequence of Bessel functions
145145
julia> @btime besselj(0:100, 50.0)
146146
443.328 ns (2 allocations: 1.75 KiB)
147147
```
148-
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,
149-
150-
```julia
151-
function bessel_sequence(x, orders)
152-
J_nu = besselj(orders, x)
153-
out = zero(x)
154-
for i in eachindex(J_nu)
155-
out += sin(x*i)*J_nu[i]
156-
end
157-
return out
158-
end
159-
160-
julia> bessel_sequence(10.2, 1:400)
161-
0.11404996570230919
162-
```
148+
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.
163149

164150
### Support for negative arguments
165151

src/besseli.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ function _besseli(nu::AbstractRange, x::T) where T
225225
end
226226
if k > 1
227227
out[k] = _besseli(nu[k], x)
228-
out[1:k+1] = besselk_down_recurrence!(out[1:k+1], x, nu[1:k+1])
228+
tmp = @view out[1:k+1]
229+
out[1:k+1] = besselk_down_recurrence!(tmp, x, nu[1:k+1])
229230
return out
230231
else
231232
return out

src/besselj.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ function _besselj(nu::AbstractRange, x::T) where T
279279
end
280280
if k > 1
281281
out[k] = _besselj(nu[k], x)
282-
out[1:k+1] = besselj_down_recurrence!(out[1:k+1], x, nu[1:k+1])
282+
tmp = @view out[1:k+1]
283+
besselj_down_recurrence!(tmp, x, nu[1:k+1])
283284
return out
284285
else
285286
return out

src/besselk.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ function _besselk(nu::AbstractRange, x::T) where T
235235
end
236236
if k < len
237237
out[k] = _besselk(nu[k], x)
238-
out[k-1:end] = besselk_up_recurrence!(out[k-1:end], x, nu[k-1:end])
238+
tmp = @view out[k-1:end]
239+
out[k-1:end] = besselk_up_recurrence!(tmp, x, nu[k-1:end])
239240
return out
240241
else
241242
return out

0 commit comments

Comments
 (0)