Skip to content

Commit f14f023

Browse files
authored
remove global state (#17)
1 parent b1cf074 commit f14f023

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LegendrePolynomials"
22
uuid = "3db4a2ba-fc88-11e8-3e01-49c72059a882"
3-
version = "0.4.3"
3+
version = "0.4.4"
44

55
[deps]
66
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"

src/LegendrePolynomials.jl

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ export dnPl
1313
export collectdnPl
1414
export collectdnPl!
1515

16-
# cache values of logfactorial to avoid expensive calls
17-
const lfdictInt = Vector{Dict{Int, Float64}}()
18-
const lfdictBigInt = Vector{Dict{BigInt, BigFloat}}()
19-
20-
function __init__()
21-
empty!(lfdictInt)
22-
empty!(lfdictBigInt)
23-
resize!(lfdictInt, Threads.nthreads())
24-
resize!(lfdictBigInt, Threads.nthreads())
25-
for i in 1:Threads.nthreads()
26-
lfdictInt[i] = Dict{Int, Float64}()
27-
lfdictBigInt[i] = Dict{BigInt, BigFloat}()
28-
end
29-
end
30-
3116
checkdomain(x) = true
3217
function checkdomain(x::Number)
3318
f = abs(x) > 1
@@ -84,18 +69,9 @@ end
8469
convert(T, P_n_l)
8570
end
8671

87-
# Allow memoization
88-
_logfactorial(n) = logfactorial(n)
89-
_logfactorial(n::Int) = get!(lfdictInt[Threads.threadid()], n) do
90-
logfactorial(n)
91-
end
92-
_logfactorial(n::BigInt) = get!(lfdictBigInt[Threads.threadid()], n) do
93-
logfactorial(n)
94-
end
95-
9672
function logplm_norm(l, m)
9773
T = promote_type(typeof(l), typeof(m))
98-
(log(T(2)) - log(2T(l)+1) + _logfactorial(l + m) - _logfactorial(l - m))/2
74+
(log(T(2)) - log(2T(l)+1) + logfactorial(l + m) - logfactorial(l - m))/2
9975
end
10076
function _maybebigexp(t)
10177
if t < log(prevfloat(typemax(t)))
@@ -111,12 +87,12 @@ end
11187
function logabspll_prefactor(l, T = typeof(l))
11288
lT = T(l)
11389
a = (logfactorial(2lT-1) + log(2lT+1) - log(lT))/2
114-
b = l*log(T(2)) + _logfactorial(lT-1)
90+
b = l*log(T(2)) + logfactorial(lT-1)
11591
a - b
11692
end
11793
neg1pow(l) = iseven(l) ? 1 : -1
11894
function pll_prefactor(l, T = typeof(l); csphase::Bool = true)
119-
l == 0 && return sqrt(oftype(_logfactorial(T(l)), 1/2))
95+
l == 0 && return sqrt(oftype(logfactorial(T(l)), 1/2))
12096
t = logabspll_prefactor(l, T)
12197
(csphase ? neg1pow(l) : 1) * exp(t)
12298
end

0 commit comments

Comments
 (0)